From 725741307a1d87f4ce64a90febbbd1d3d9773285 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 19 Oct 2018 23:17:27 +1100 Subject: [PATCH] Update validator record to new spec --- beacon_chain/types/src/lib.rs | 4 +- beacon_chain/types/src/validator_record.rs | 44 +++++++++++----------- 2 files changed, 25 insertions(+), 23 deletions(-) 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); } }