Skip to content

Commit 40beb6c

Browse files
hangleangpovi
authored andcommitted
Update initial earliest_exit_epoch calculation
format code resolved conflict
1 parent 299b099 commit 40beb6c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

helper_functions/src/fork.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -549,19 +549,17 @@ pub fn upgrade_to_electra<P: Preset>(
549549
epoch,
550550
};
551551

552-
let mut earliest_exit_epoch = misc::compute_activation_exit_epoch::<P>(epoch);
552+
// initial value of `earliest_exit_epoch`
553+
let earliest_activation_epoch = misc::compute_activation_exit_epoch::<P>(epoch);
553554

554-
for exit_epoch in validators
555+
let earliest_exit_epoch = validators
555556
.into_iter()
556557
.map(|validator| validator.exit_epoch)
557558
.filter(|exit_epoch| *exit_epoch != FAR_FUTURE_EPOCH)
558-
{
559-
if exit_epoch > earliest_exit_epoch {
560-
earliest_exit_epoch = exit_epoch;
561-
}
562-
}
563-
564-
earliest_exit_epoch += 1;
559+
.fold(earliest_activation_epoch, |earliest, exit_epoch| {
560+
earliest.max(exit_epoch)
561+
})
562+
+ 1;
565563

566564
let mut post = ElectraBeaconState {
567565
// > Versioning
@@ -610,7 +608,7 @@ pub fn upgrade_to_electra<P: Preset>(
610608
exit_balance_to_consume: 0,
611609
earliest_exit_epoch,
612610
consolidation_balance_to_consume: 0,
613-
earliest_consolidation_epoch: misc::compute_activation_exit_epoch::<P>(epoch),
611+
earliest_consolidation_epoch: earliest_activation_epoch,
614612
pending_deposits: PersistentList::default(),
615613
pending_partial_withdrawals: PersistentList::default(),
616614
pending_consolidations: PersistentList::default(),

0 commit comments

Comments
 (0)