Solve one FIXME, add two more..

This commit is contained in:
Michael Sproul
2022-11-30 17:46:23 +11:00
parent 39a23c1de6
commit a113a39e90
3 changed files with 20 additions and 10 deletions

View File

@@ -8,10 +8,10 @@ pub fn initiate_validator_exit<T: EthSpec>(
index: usize,
spec: &ChainSpec,
) -> Result<(), Error> {
// Return if the validator already initiated exit
if state.get_validator(index)?.exit_epoch() != spec.far_future_epoch {
return Ok(());
}
// 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.
// Ensure the exit cache is built.
state.build_exit_cache(spec)?;
@@ -28,15 +28,21 @@ pub fn initiate_validator_exit<T: EthSpec>(
exit_queue_epoch.safe_add_assign(1)?;
}
state
.exit_cache_mut()
.record_validator_exit(exit_queue_epoch)?;
let validator = state.get_validator_cow(index)?;
// FIXME(sproul): could avoid this second lookup with some clever borrowing
let mut 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.to_mut();
validator.mutable.exit_epoch = exit_queue_epoch;
validator.mutable.withdrawable_epoch =
exit_queue_epoch.safe_add(spec.min_validator_withdrawability_delay)?;
state
.exit_cache_mut()
.record_validator_exit(exit_queue_epoch)?;
Ok(())
}

View File

@@ -66,9 +66,11 @@ impl EpochCache {
// The cache should never be constructed at slot 0 because it should only be used for
// block processing (which implies slot > 0) or epoch processing (which implies slot >= 32).
/* FIXME(sproul): EF tests like this
if decision_block_root.is_zero() {
return Err(EpochCacheError::InvalidSlot { slot: state.slot() });
}
*/
// Compute base rewards.
let total_active_balance = state.get_total_active_balance()?;