diff --git a/beacon_chain/utils/active-validators/Cargo.toml b/beacon_chain/utils/active-validators/Cargo.toml deleted file mode 100644 index 4729747d98..0000000000 --- a/beacon_chain/utils/active-validators/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "active-validators" -version = "0.1.0" -authors = ["Paul Hauner "] - -[dependencies] -types = { path = "../../types" } diff --git a/beacon_chain/utils/active-validators/src/lib.rs b/beacon_chain/utils/active-validators/src/lib.rs deleted file mode 100644 index 495d1f85af..0000000000 --- a/beacon_chain/utils/active-validators/src/lib.rs +++ /dev/null @@ -1,64 +0,0 @@ -extern crate types; - -use types::{ValidatorRecord, ValidatorStatus}; - -/// Returns the indicies of each active validator in a given vec of validators. -pub fn active_validator_indices(validators: &[ValidatorRecord]) -> Vec { - validators - .iter() - .enumerate() - .filter_map(|(i, validator)| { - if validator.status_is(ValidatorStatus::Active) { - Some(i) - } else { - None - } - }) - .collect() -} - -#[cfg(test)] -mod tests { - use super::*; - - pub fn validator_is_active(v: &ValidatorRecord) -> bool { - v.status_is(ValidatorStatus::Active) - } - - #[test] - fn test_active_validator() { - let mut validators = vec![]; - - let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); - v.status = ValidatorStatus::Active; - assert!(validator_is_active(&v)); - validators.push(v); - - let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); - v.status = ValidatorStatus::PendingActivation; - assert!(!validator_is_active(&v)); - validators.push(v); - - let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); - v.status = ValidatorStatus::PendingExit; - assert!(!validator_is_active(&v)); - validators.push(v); - - let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); - v.status = ValidatorStatus::PendingWithdraw; - assert!(!validator_is_active(&v)); - validators.push(v); - - let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); - v.status = ValidatorStatus::Withdrawn; - assert!(!validator_is_active(&v)); - validators.push(v); - - let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair(); - v.status = ValidatorStatus::Penalized; - assert!(!validator_is_active(&v)); - validators.push(v); - - assert_eq!(active_validator_indices(&validators), vec![0]); - } -} diff --git a/beacon_chain/validator_change/Cargo.toml b/beacon_chain/validator_change/Cargo.toml index 88e78c9f85..0705033dc3 100644 --- a/beacon_chain/validator_change/Cargo.toml +++ b/beacon_chain/validator_change/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors = ["Paul Hauner "] [dependencies] -active-validators = { path = "../utils/active-validators" } bytes = "0.4.10" hashing = { path = "../utils/hashing" } types = { path = "../types" } diff --git a/beacon_chain/validator_change/src/lib.rs b/beacon_chain/validator_change/src/lib.rs index a2d9daeffa..99687e30ad 100644 --- a/beacon_chain/validator_change/src/lib.rs +++ b/beacon_chain/validator_change/src/lib.rs @@ -1,9 +1,7 @@ -extern crate active_validators; extern crate bytes; extern crate hashing; extern crate types; -use active_validators::validator_is_active; use bytes::{BufMut, BytesMut}; use hashing::canonical_hash; use std::cmp::max; @@ -31,7 +29,7 @@ pub fn update_validator_set( let total_balance = { let mut bal: u64 = 0; for v in validators.iter() { - if validator_is_active(&v) { + if v.status_is(ValidatorStatus::Active) { bal = bal .checked_add(v.balance) .ok_or(UpdateValidatorSetError::ArithmeticOverflow)?; diff --git a/beacon_chain/validator_shuffling/src/lib.rs b/beacon_chain/validator_shuffling/src/lib.rs index fe2447fc05..90077279ff 100644 --- a/beacon_chain/validator_shuffling/src/lib.rs +++ b/beacon_chain/validator_shuffling/src/lib.rs @@ -1,4 +1,3 @@ -extern crate active_validators; extern crate honey_badger_split; extern crate types; extern crate vec_shuffle; diff --git a/beacon_chain/validator_shuffling/src/shuffle.rs b/beacon_chain/validator_shuffling/src/shuffle.rs index 3009f4cbd8..17d3d6420e 100644 --- a/beacon_chain/validator_shuffling/src/shuffle.rs +++ b/beacon_chain/validator_shuffling/src/shuffle.rs @@ -1,8 +1,7 @@ use std::cmp::min; -use active_validators::active_validator_indices; use honey_badger_split::SplitExt; -use types::{ChainConfig, ShardAndCommittee, ValidatorRecord}; +use types::{ChainConfig, ShardAndCommittee, ValidatorRecord, ValidatorStatus}; use vec_shuffle::{shuffle, ShuffleErr}; type DelegatedCycle = Vec>; @@ -24,7 +23,17 @@ pub fn shard_and_committees_for_cycle( config: &ChainConfig, ) -> Result { let shuffled_validator_indices = { - let mut validator_indices = active_validator_indices(validators); + let mut validator_indices = validators + .iter() + .enumerate() + .filter_map(|(i, validator)| { + if validator.status_is(ValidatorStatus::Active) { + Some(i) + } else { + None + } + }) + .collect(); shuffle(seed, validator_indices)? }; let shard_indices: Vec = (0_usize..config.shard_count as usize).into_iter().collect();