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:
Justin 2020-05-26 01:10:52 +01:00 committed by GitHub
parent f8cac1b822
commit e889c2eb22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
use super::super::common::initiate_validator_exit; use super::super::common::initiate_validator_exit;
use super::Error; use super::Error;
use itertools::{Either, Itertools}; use itertools::Itertools;
use types::*; use types::*;
/// Performs a validator registry update, if required. /// 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`. // 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. // Rest assured exiting validators will still be exited in the same order as in the spec.
let current_epoch = state.current_epoch(); let current_epoch = state.current_epoch();
let is_exiting_validator = |validator: &Validator| { let is_ejectable = |validator: &Validator| {
validator.is_active_at(current_epoch) validator.is_active_at(current_epoch)
&& validator.effective_balance <= spec.ejection_balance && validator.effective_balance <= spec.ejection_balance
}; };
let (eligible_validators, exiting_validators): (Vec<_>, Vec<_>) = state let indices_to_update: Vec<_> = state
.validators .validators
.iter() .iter()
.enumerate() .enumerate()
.filter(|(_, validator)| { .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)| { .map(|(idx, _)| idx)
if validator.is_eligible_for_activation_queue(spec) { .collect();
Either::Left(index)
} else { for index in indices_to_update {
Either::Right(index) if state.validators[index].is_eligible_for_activation_queue(spec) {
} state.validators[index].activation_eligibility_epoch = current_epoch + 1;
}); }
for index in eligible_validators { if is_ejectable(&state.validators[index]) {
state.validators[index].activation_eligibility_epoch = current_epoch + 1; initiate_validator_exit(state, index, spec)?;
} }
for index in exiting_validators {
initiate_validator_exit(state, index, spec)?;
} }
// Queue validators eligible for activation and not dequeued for activation prior to finalized epoch // Queue validators eligible for activation and not dequeued for activation prior to finalized epoch