mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 03:12:41 +00:00
* Update to spec v0.9.0 * Update to v0.9.1 * Bump spec tags for v0.9.1 * Formatting, fix CI failures * Resolve accidental KeyPair merge conflict * Document new BeaconState functions * Fix incorrect cache drops in `advance_caches` * Update fork choice for v0.9.1 * Clean up some FIXMEs * Fix a few docs/logs
40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
use std::cmp::max;
|
|
use types::{BeaconStateError as Error, *};
|
|
|
|
/// Initiate the exit of the validator of the given `index`.
|
|
///
|
|
/// Spec v0.9.1
|
|
pub fn initiate_validator_exit<T: EthSpec>(
|
|
state: &mut BeaconState<T>,
|
|
index: usize,
|
|
spec: &ChainSpec,
|
|
) -> Result<(), Error> {
|
|
if index >= state.validators.len() {
|
|
return Err(Error::UnknownValidator);
|
|
}
|
|
|
|
// Return if the validator already initiated exit
|
|
if state.validators[index].exit_epoch != spec.far_future_epoch {
|
|
return Ok(());
|
|
}
|
|
|
|
// Compute exit queue epoch
|
|
let delayed_epoch = state.compute_activation_exit_epoch(state.current_epoch(), spec);
|
|
let mut exit_queue_epoch = state
|
|
.exit_cache
|
|
.max_epoch()
|
|
.map_or(delayed_epoch, |epoch| max(epoch, delayed_epoch));
|
|
let exit_queue_churn = state.exit_cache.get_churn_at(exit_queue_epoch);
|
|
|
|
if exit_queue_churn >= state.get_churn_limit(spec)? {
|
|
exit_queue_epoch += 1;
|
|
}
|
|
|
|
state.exit_cache.record_validator_exit(exit_queue_epoch);
|
|
state.validators[index].exit_epoch = exit_queue_epoch;
|
|
state.validators[index].withdrawable_epoch =
|
|
exit_queue_epoch + spec.min_validator_withdrawability_delay;
|
|
|
|
Ok(())
|
|
}
|