Update validator record to new spec

This commit is contained in:
Paul Hauner 2018-10-19 23:17:27 +11:00
parent 1acfb87e77
commit 725741307a
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 25 additions and 23 deletions

View File

@ -16,7 +16,7 @@ pub mod validator_record;
use self::ethereum_types::{ use self::ethereum_types::{
H256, H256,
H160, H160,
U256 U256,
}; };
use self::boolean_bitfield::BooleanBitfield; use self::boolean_bitfield::BooleanBitfield;
use std::collections::HashMap; use std::collections::HashMap;
@ -29,7 +29,7 @@ pub use beacon_block::BeaconBlock;
pub use crosslink_record::CrosslinkRecord; pub use crosslink_record::CrosslinkRecord;
pub use shard_and_committee::ShardAndCommittee; pub use shard_and_committee::ShardAndCommittee;
pub use special_record::{ SpecialRecord, SpecialRecordKind }; pub use special_record::{ SpecialRecord, SpecialRecordKind };
pub use validator_record::ValidatorRecord; pub use validator_record::{ ValidatorRecord, ValidatorStatus };
pub type Hash256 = H256; pub type Hash256 = H256;
pub type Address = H160; pub type Address = H160;

View File

@ -1,21 +1,32 @@
use super::{ use super::{
Hash256, Hash256,
Address, Address,
EthBalance,
}; };
use super::bls::{ use super::bls::{
PublicKey, PublicKey,
Keypair 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 struct ValidatorRecord {
pub pubkey: PublicKey, pub pubkey: PublicKey,
pub withdrawal_shard: u16, pub withdrawal_shard: u16,
pub withdrawal_address: Address, pub withdrawal_address: Address,
pub randao_commitment: Hash256, pub randao_commitment: Hash256,
pub balance: EthBalance, pub randao_last_change: u64,
pub start_dynasty: u64, pub balance: u64,
pub end_dynasty: u64, pub status: u8,
pub exit_slot: u64,
} }
impl ValidatorRecord { impl ValidatorRecord {
@ -30,24 +41,15 @@ impl ValidatorRecord {
withdrawal_shard: 0, withdrawal_shard: 0,
withdrawal_address: Address::zero(), withdrawal_address: Address::zero(),
randao_commitment: Hash256::zero(), randao_commitment: Hash256::zero(),
balance: EthBalance::zero(), randao_last_change: 0,
start_dynasty: 0, balance: 0,
end_dynasty: 0, status: 0,
exit_slot: 0,
}; };
(s, keypair) (s, keypair)
} }
} }
impl Clone for ValidatorRecord {
fn clone(&self) -> ValidatorRecord {
ValidatorRecord {
pubkey: self.pubkey.clone(),
..*self
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -56,12 +58,12 @@ mod tests {
#[test] #[test]
fn test_validator_record_zero_rand_keypair() { fn test_validator_record_zero_rand_keypair() {
let (v, _kp) = ValidatorRecord::zero_with_thread_rand_keypair(); let (v, _kp) = ValidatorRecord::zero_with_thread_rand_keypair();
// TODO: check keys
assert_eq!(v.withdrawal_shard, 0); assert_eq!(v.withdrawal_shard, 0);
assert!(v.withdrawal_address.is_zero()); assert!(v.withdrawal_address.is_zero());
assert!(v.randao_commitment.is_zero()); assert!(v.randao_commitment.is_zero());
assert!(v.balance.is_zero()); assert_eq!(v.randao_last_change, 0);
assert_eq!(v.start_dynasty, 0); assert_eq!(v.balance, 0);
assert_eq!(v.end_dynasty, 0); assert_eq!(v.status, 0);
assert_eq!(v.exit_slot, 0);
} }
} }