Skip to content

Commit

Permalink
Fix findEarliestExitEpoch calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassaldanha committed Dec 4, 2024
1 parent 9e80efa commit 14ce636
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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<Validator> validators = state.getValidators();

Expand Down Expand Up @@ -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();
}
}

0 comments on commit 14ce636

Please sign in to comment.