From 14ce63661cdd4591a74cdfba4c07391e2886a2ce Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Wed, 4 Dec 2024 13:25:43 +1300 Subject: [PATCH] Fix findEarliestExitEpoch calculation --- .../forktransition/ElectraStateUpgrade.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgrade.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgrade.java index a5c71a7af76..f2e8251b733 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgrade.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/forktransition/ElectraStateUpgrade.java @@ -58,6 +58,7 @@ public BeaconStateElectra upgrade(final BeaconState preState) { final PredicatesElectra predicatesElectra = new PredicatesElectra(specConfig); final MiscHelpersElectra miscHelpersElectra = new MiscHelpersElectra(specConfig, predicatesElectra, schemaDefinitions); + final UInt64 activationExitEpoch = miscHelpersElectra.computeActivationExitEpoch(epoch); return BeaconStateElectra.required(schemaDefinitions.getBeaconStateSchema().createEmpty()) .updatedElectra( state -> { @@ -86,11 +87,10 @@ public BeaconStateElectra upgrade(final BeaconState preState) { state.setDepositBalanceToConsume(UInt64.ZERO); state.setExitBalanceToConsume( beaconStateAccessors.getActivationExitChurnLimit(state)); - state.setEarliestExitEpoch(findEarliestExitEpoch(state, epoch)); + state.setEarliestExitEpoch(findEarliestExitEpoch(state, activationExitEpoch)); state.setConsolidationBalanceToConsume( beaconStateAccessors.getConsolidationChurnLimit(state)); - state.setEarliestConsolidationEpoch( - miscHelpersElectra.computeActivationExitEpoch(epoch)); + state.setEarliestConsolidationEpoch(activationExitEpoch); final SszMutableList validators = state.getValidators(); @@ -120,12 +120,13 @@ public BeaconStateElectra upgrade(final BeaconState preState) { }); } - private UInt64 findEarliestExitEpoch(final BeaconState state, final UInt64 currentEpoch) { - return state.getValidators().stream() - .map(Validator::getExitEpoch) - .filter(exitEpoch -> !exitEpoch.equals(FAR_FUTURE_EPOCH)) - .max(UInt64::compareTo) - .orElse(currentEpoch) - .increment(); + private UInt64 findEarliestExitEpoch(final BeaconState state, final UInt64 activationExitEpoch) { + final UInt64 maxExitEpochFromValidatorSet = + state.getValidators().stream() + .map(Validator::getExitEpoch) + .filter(exitEpoch -> !exitEpoch.equals(FAR_FUTURE_EPOCH)) + .max(UInt64::compareTo) + .orElse(UInt64.ZERO); + return maxExitEpochFromValidatorSet.max(activationExitEpoch).increment(); } }