drop initiate validator ordering optimization

This commit is contained in:
realbigsean
2024-05-11 09:58:14 -04:00
parent a75257fb6e
commit f4907ef971

View File

@@ -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)?;
@@ -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)?;