diff --git a/beacon_chain/transition/src/delegation/validator.rs b/beacon_chain/transition/src/delegation/validator.rs index 4c33d0081..ab7c06b64 100644 --- a/beacon_chain/transition/src/delegation/validator.rs +++ b/beacon_chain/transition/src/delegation/validator.rs @@ -1,27 +1,26 @@ use super::honey_badger_split::SplitExt; -use super::types::{ShardAndCommittee, ValidatorRecord, ChainConfig}; +use super::types::{ + ShardAndCommittee, + ValidatorRecord, + ValidatorStatus, + ChainConfig, +}; use super::TransitionError; use super::shuffle; use std::cmp::min; type DelegatedCycle = Vec>; -/// Produce a vector of validators indicies where those validators start and end -/// dynasties are within the supplied `dynasty`. -fn active_validator_indicies( - dynasty: u64, - validators: &[ValidatorRecord]) +/// Returns the indicies of each active validator in a given vec of validators. +fn active_validator_indicies(validators: &[ValidatorRecord]) -> Vec { validators.iter() .enumerate() .filter_map(|(i, validator)| { - if (validator.start_dynasty >= dynasty) & - (validator.end_dynasty < dynasty) - { - Some(i) - } else { - None + match validator.status { + x if x == ValidatorStatus::Active as u8 => Some(i), + _ => None } }) .collect() @@ -35,13 +34,12 @@ fn active_validator_indicies( pub fn delegate_validators( seed: &[u8], validators: &[ValidatorRecord], - dynasty: u64, crosslinking_shard_start: u16, config: &ChainConfig) -> Result { let shuffled_validator_indices = { - let mut validator_indices = active_validator_indicies(dynasty, validators); + let mut validator_indices = active_validator_indicies(validators); match shuffle(seed, validator_indices) { Ok(shuffled) => shuffled, _ => return Err(TransitionError::InvalidInput( diff --git a/beacon_chain/types/src/lib.rs b/beacon_chain/types/src/lib.rs index 14dfa792a..a00e904e9 100644 --- a/beacon_chain/types/src/lib.rs +++ b/beacon_chain/types/src/lib.rs @@ -16,7 +16,7 @@ pub mod validator_record; use self::ethereum_types::{ H256, H160, - U256 + U256, }; use self::boolean_bitfield::BooleanBitfield; use std::collections::HashMap; @@ -29,7 +29,7 @@ pub use beacon_block::BeaconBlock; pub use crosslink_record::CrosslinkRecord; pub use shard_and_committee::ShardAndCommittee; pub use special_record::{ SpecialRecord, SpecialRecordKind }; -pub use validator_record::ValidatorRecord; +pub use validator_record::{ ValidatorRecord, ValidatorStatus }; pub type Hash256 = H256; pub type Address = H160; diff --git a/beacon_chain/types/src/validator_record.rs b/beacon_chain/types/src/validator_record.rs index 4949e13f4..19c848a76 100644 --- a/beacon_chain/types/src/validator_record.rs +++ b/beacon_chain/types/src/validator_record.rs @@ -1,21 +1,32 @@ use super::{ Hash256, Address, - EthBalance, }; use super::bls::{ PublicKey, Keypair }; +#[derive(Debug, PartialEq, Clone, Copy)] +pub enum ValidatorStatus { + PendingActivation = 0, + Active = 1, + PendingExit = 2, + PendingWithdraw = 3, + Withdrawn = 5, + Penalized = 127, +} + +#[derive(Debug, Clone, PartialEq)] pub struct ValidatorRecord { pub pubkey: PublicKey, pub withdrawal_shard: u16, pub withdrawal_address: Address, pub randao_commitment: Hash256, - pub balance: EthBalance, - pub start_dynasty: u64, - pub end_dynasty: u64, + pub randao_last_change: u64, + pub balance: u64, + pub status: u8, + pub exit_slot: u64, } impl ValidatorRecord { @@ -30,24 +41,15 @@ impl ValidatorRecord { withdrawal_shard: 0, withdrawal_address: Address::zero(), randao_commitment: Hash256::zero(), - balance: EthBalance::zero(), - start_dynasty: 0, - end_dynasty: 0, + randao_last_change: 0, + balance: 0, + status: 0, + exit_slot: 0, }; (s, keypair) } } -impl Clone for ValidatorRecord { - fn clone(&self) -> ValidatorRecord { - ValidatorRecord { - pubkey: self.pubkey.clone(), - ..*self - - } - } -} - #[cfg(test)] mod tests { @@ -56,12 +58,12 @@ mod tests { #[test] fn test_validator_record_zero_rand_keypair() { let (v, _kp) = ValidatorRecord::zero_with_thread_rand_keypair(); - // TODO: check keys assert_eq!(v.withdrawal_shard, 0); assert!(v.withdrawal_address.is_zero()); assert!(v.randao_commitment.is_zero()); - assert!(v.balance.is_zero()); - assert_eq!(v.start_dynasty, 0); - assert_eq!(v.end_dynasty, 0); + assert_eq!(v.randao_last_change, 0); + assert_eq!(v.balance, 0); + assert_eq!(v.status, 0); + assert_eq!(v.exit_slot, 0); } }