drop initiate validator ordering optimization

This commit is contained in:
realbigsean
2024-05-11 09:58:14 -04:00
parent 4041cb99af
commit 740494f22f

View File

@@ -8,12 +8,12 @@ pub fn initiate_validator_exit<E: EthSpec>(
index: usize, index: usize,
spec: &ChainSpec, spec: &ChainSpec,
) -> Result<(), Error> { ) -> Result<(), Error> {
// We do things in a slightly different order to the spec here. Instead of immediately checking let validator = state.get_validator_cow(index)?;
// 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 // Return if the validator already initiated exit
// validator tree (expensive), make the check and mutate as appropriate. Compared to the spec if validator.exit_epoch != spec.far_future_epoch {
// ordering, this saves us from looking up the validator in the validator registry multiple return Ok(());
// times. }
// Ensure the exit cache is built. // Ensure the exit cache is built.
state.build_exit_cache(spec)?; state.build_exit_cache(spec)?;
@@ -36,14 +36,7 @@ pub fn initiate_validator_exit<E: EthSpec>(
exit_queue_epoch exit_queue_epoch
}; };
let validator = state.get_validator_cow(index)?; let validator = state.get_validator_mut(index)?;
// Return if the validator already initiated exit
if validator.exit_epoch != spec.far_future_epoch {
return Ok(());
}
let validator = validator.into_mut()?;
validator.exit_epoch = exit_queue_epoch; validator.exit_epoch = exit_queue_epoch;
validator.withdrawable_epoch = validator.withdrawable_epoch =
exit_queue_epoch.safe_add(spec.min_validator_withdrawability_delay)?; exit_queue_epoch.safe_add(spec.min_validator_withdrawability_delay)?;