Move state trans fns into state_processing

This commit is contained in:
Paul Hauner
2019-03-18 21:34:42 +11:00
parent 7503f31ddc
commit 1028acf3f1
17 changed files with 741 additions and 669 deletions

View File

@@ -0,0 +1,28 @@
use crate::common::exit_validator;
use types::{BeaconStateError as Error, *};
/// Iterate through the validator registry and eject active validators with balance below
/// ``EJECTION_BALANCE``.
///
/// Spec v0.5.0
pub fn process_ejections(state: &mut BeaconState, spec: &ChainSpec) -> Result<(), Error> {
// 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)?
.iter()
.filter_map(|&i| {
if state.validator_balances[i as usize] < spec.ejection_balance {
Some(i)
} else {
None
}
})
.collect();
for validator_index in exitable {
exit_validator(state, validator_index, spec)?
}
Ok(())
}