Skip to content

Commit

Permalink
drop initiate validator ordering optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
realbigsean committed May 11, 2024
1 parent a75257f commit f4907ef
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions consensus/state_processing/src/common/initiate_validator_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ pub fn initiate_validator_exit<E: EthSpec>(
index: usize,
spec: &ChainSpec,
) -> Result<(), Error> {
// We do things in a slightly different order to the spec here. Instead of immediately checking
// whether the validator has already exited, we instead prepare the exit cache and compute the
// cheap-to-calculate values from that. *Then* we look up the validator a single time in the
// validator tree (expensive), make the check and mutate as appropriate. Compared to the spec
// ordering, this saves us from looking up the validator in the validator registry multiple
// times.
let validator = state.get_validator_cow(index)?;

// Return if the validator already initiated exit
if validator.exit_epoch != spec.far_future_epoch {
return Ok(());
}

// Ensure the exit cache is built.
state.build_exit_cache(spec)?;
Expand All @@ -36,14 +36,7 @@ pub fn initiate_validator_exit<E: EthSpec>(
exit_queue_epoch
};

let validator = state.get_validator_cow(index)?;

// Return if the validator already initiated exit
if validator.exit_epoch != spec.far_future_epoch {
return Ok(());
}

let validator = validator.into_mut()?;
let validator = state.get_validator_mut(index)?;
validator.exit_epoch = exit_queue_epoch;
validator.withdrawable_epoch =
exit_queue_epoch.safe_add(spec.min_validator_withdrawability_delay)?;
Expand Down

0 comments on commit f4907ef

Please sign in to comment.