From e889c2eb2228b6380ece20b655b7f74840974d3d Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 26 May 2020 01:10:52 +0100 Subject: [PATCH] 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 --- .../per_epoch_processing/registry_updates.rs | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/consensus/state_processing/src/per_epoch_processing/registry_updates.rs b/consensus/state_processing/src/per_epoch_processing/registry_updates.rs index d77b1e654..3579419e1 100644 --- a/consensus/state_processing/src/per_epoch_processing/registry_updates.rs +++ b/consensus/state_processing/src/per_epoch_processing/registry_updates.rs @@ -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( // 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