mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 20:22:02 +00:00
Move get_active_validator_indices to state
This commit is contained in:
@@ -9,7 +9,7 @@ pub fn process_ejections(state: &mut BeaconState, spec: &ChainSpec) -> Result<()
|
||||
// There is an awkward double (triple?) loop here because we can't loop across the borrowed
|
||||
// active validator indices and mutate state in the one loop.
|
||||
let exitable: Vec<usize> = state
|
||||
.get_active_validator_indices(state.current_epoch(spec), spec)?
|
||||
.get_cached_active_validator_indices(RelativeEpoch::Current, spec)?
|
||||
.iter()
|
||||
.filter_map(|&i| {
|
||||
if state.validator_balances[i as usize] < spec.ejection_balance {
|
||||
|
||||
@@ -7,7 +7,8 @@ use types::{BeaconStateError as Error, *};
|
||||
/// Spec v0.4.0
|
||||
pub fn process_slashings(state: &mut BeaconState, spec: &ChainSpec) -> Result<(), Error> {
|
||||
let current_epoch = state.current_epoch(spec);
|
||||
let active_validator_indices = state.get_active_validator_indices(current_epoch, spec)?;
|
||||
let active_validator_indices =
|
||||
state.get_cached_active_validator_indices(RelativeEpoch::Current, spec)?;
|
||||
let total_balance = state.get_total_balance(&active_validator_indices[..], spec)?;
|
||||
|
||||
for (index, validator) in state.validator_registry.iter().enumerate() {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn process_validator_registry(state: &mut BeaconState, spec: &ChainSpec) ->
|
||||
state.current_shuffling_start_shard = (state.current_shuffling_start_shard
|
||||
+ spec.get_epoch_committee_count(
|
||||
state
|
||||
.get_active_validator_indices(current_epoch, spec)?
|
||||
.get_cached_active_validator_indices(RelativeEpoch::Current, spec)?
|
||||
.len(),
|
||||
) as u64)
|
||||
% spec.shard_count;
|
||||
@@ -53,7 +53,7 @@ pub fn should_update_validator_registry(
|
||||
}
|
||||
|
||||
let num_active_validators = state
|
||||
.get_active_validator_indices(state.current_epoch(spec), spec)?
|
||||
.get_cached_active_validator_indices(RelativeEpoch::Current, spec)?
|
||||
.len();
|
||||
let current_epoch_committee_count = spec.get_epoch_committee_count(num_active_validators);
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ use types::{BeaconStateError as Error, *};
|
||||
/// Spec v0.4.0
|
||||
pub fn update_validator_registry(state: &mut BeaconState, spec: &ChainSpec) -> Result<(), Error> {
|
||||
let current_epoch = state.current_epoch(spec);
|
||||
let active_validator_indices = state.get_active_validator_indices(current_epoch, spec)?;
|
||||
let active_validator_indices =
|
||||
state.get_cached_active_validator_indices(RelativeEpoch::Current, spec)?;
|
||||
let total_balance = state.get_total_balance(&active_validator_indices[..], spec)?;
|
||||
|
||||
let max_balance_churn = std::cmp::max(
|
||||
|
||||
Reference in New Issue
Block a user