Implement activation queue cache

This commit is contained in:
Michael Sproul
2023-07-03 12:03:14 +10:00
parent f631b515f6
commit b414c323f8
6 changed files with 95 additions and 17 deletions

View File

@@ -1,5 +1,4 @@
use crate::{common::initiate_validator_exit, per_epoch_processing::Error};
use itertools::Itertools;
use safe_arith::SafeArith;
use types::{BeaconState, ChainSpec, EthSpec, Validator};
@@ -40,19 +39,16 @@ pub fn process_registry_updates<T: EthSpec>(
}
// Queue validators eligible for activation and not dequeued for activation prior to finalized epoch
let activation_queue = state
.validators()
.iter()
.enumerate()
.filter(|(_, validator)| validator.is_eligible_for_activation(state, spec))
.sorted_by_key(|(index, validator)| (validator.activation_eligibility_epoch(), *index))
.map(|(index, _)| index)
.collect_vec();
// Dequeue validators for activation up to churn limit
let churn_limit = state.get_churn_limit(spec)? as usize;
let epoch_cache = state.epoch_cache().clone();
let activation_queue = epoch_cache
.activation_queue()?
.get_validators_eligible_for_activation(state.finalized_checkpoint().epoch, churn_limit);
let delayed_activation_epoch = state.compute_activation_exit_epoch(current_epoch, spec)?;
for index in activation_queue.into_iter().take(churn_limit) {
for index in activation_queue {
state.get_validator_mut(index)?.mutable.activation_epoch = delayed_activation_epoch;
}