Avoid implicit validator status assumption (#1188)
* Avoid implicit validator status assumption Replacement for #1092 * Update registry_updates.rs * Fix compilation errors Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
parent
f8cac1b822
commit
e889c2eb22
@ -1,6 +1,6 @@
|
||||
use super::super::common::initiate_validator_exit;
|
||||
use super::Error;
|
||||
use itertools::{Either, Itertools};
|
||||
use itertools::Itertools;
|
||||
use types::*;
|
||||
|
||||
/// Performs a validator registry update, if required.
|
||||
@ -15,29 +15,27 @@ pub fn process_registry_updates<T: EthSpec>(
|
||||
// We assume it's safe to re-order the change in eligibility and `initiate_validator_exit`.
|
||||
// Rest assured exiting validators will still be exited in the same order as in the spec.
|
||||
let current_epoch = state.current_epoch();
|
||||
let is_exiting_validator = |validator: &Validator| {
|
||||
let is_ejectable = |validator: &Validator| {
|
||||
validator.is_active_at(current_epoch)
|
||||
&& validator.effective_balance <= spec.ejection_balance
|
||||
};
|
||||
let (eligible_validators, exiting_validators): (Vec<_>, Vec<_>) = state
|
||||
let indices_to_update: Vec<_> = state
|
||||
.validators
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, validator)| {
|
||||
validator.is_eligible_for_activation_queue(spec) || is_exiting_validator(validator)
|
||||
validator.is_eligible_for_activation_queue(spec) || is_ejectable(validator)
|
||||
})
|
||||
.partition_map(|(index, validator)| {
|
||||
if validator.is_eligible_for_activation_queue(spec) {
|
||||
Either::Left(index)
|
||||
} else {
|
||||
Either::Right(index)
|
||||
}
|
||||
});
|
||||
for index in eligible_validators {
|
||||
state.validators[index].activation_eligibility_epoch = current_epoch + 1;
|
||||
}
|
||||
for index in exiting_validators {
|
||||
initiate_validator_exit(state, index, spec)?;
|
||||
.map(|(idx, _)| idx)
|
||||
.collect();
|
||||
|
||||
for index in indices_to_update {
|
||||
if state.validators[index].is_eligible_for_activation_queue(spec) {
|
||||
state.validators[index].activation_eligibility_epoch = current_epoch + 1;
|
||||
}
|
||||
if is_ejectable(&state.validators[index]) {
|
||||
initiate_validator_exit(state, index, spec)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Queue validators eligible for activation and not dequeued for activation prior to finalized epoch
|
||||
|
Loading…
Reference in New Issue
Block a user