From 65917a696a85407e1c69e40ff45388f48f8f6a3f Mon Sep 17 00:00:00 2001 From: Grant Wuerker Date: Wed, 26 Dec 2018 14:43:09 -0600 Subject: [PATCH] beacon_state, deposit_input, and validator_record updated again beacon_state, deposit_input, and validator_record updated again --- beacon_chain/chain/src/genesis.rs | 5 ++++- beacon_chain/types/src/beacon_state.rs | 8 +++++--- beacon_chain/types/src/deposit_input.rs | 5 +++++ beacon_chain/types/src/validator_record.rs | 14 +++++++++++--- beacon_chain/validator_induction/src/inductor.rs | 6 +++++- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/beacon_chain/chain/src/genesis.rs b/beacon_chain/chain/src/genesis.rs index d9b634062..e1b39cd23 100644 --- a/beacon_chain/chain/src/genesis.rs +++ b/beacon_chain/chain/src/genesis.rs @@ -1,6 +1,5 @@ use super::{ActiveState, ChainConfig, CrystallizedState}; use types::ValidatorStatus; -use validator_induction::ValidatorInductor; use validator_shuffling::{shard_and_committees_for_cycle, ValidatorAssignmentError}; #[derive(Debug, PartialEq)] @@ -24,6 +23,8 @@ pub fn genesis_states(config: &ChainConfig) -> Result<(ActiveState, Crystallized * * Ignore any records which fail proof-of-possession or are invalid. */ + /* + TODO: refactor this let validators = { let mut inductor = ValidatorInductor::new(0, config.shard_count, vec![]); for registration in &config.initial_validators { @@ -31,6 +32,8 @@ pub fn genesis_states(config: &ChainConfig) -> Result<(ActiveState, Crystallized } inductor.to_vec() }; + */ + let validators = vec![]; /* * Assign the validators to shards, using all zeros as the seed. diff --git a/beacon_chain/types/src/beacon_state.rs b/beacon_chain/types/src/beacon_state.rs index 76c23ac85..c90595da3 100644 --- a/beacon_chain/types/src/beacon_state.rs +++ b/beacon_chain/types/src/beacon_state.rs @@ -17,9 +17,9 @@ pub struct BeaconState { pub validator_registry_latest_change_slot: u64, pub validator_registry_exit_count: u64, pub validator_registry_delta_chain_tip: Hash256, - pub randao_mix: Hash256, - pub next_seed: Hash256, - pub shard_and_committee_for_slots: Vec>, + pub latest_randao_mixes: Vec, + pub latest_vdf_outputs: Vec, + pub shard_committees_at_slots: Vec>, pub persistent_committees: Vec>, pub persistent_committee_reassignments: Vec, pub previous_justified_slot: u64, @@ -27,6 +27,8 @@ pub struct BeaconState { pub justification_bitfield: u64, pub finalized_slot: u64, pub latest_crosslinks: Vec, + // TODO: remove this, it's no longer in the spec + pub latest_state_recalculation_slot: u64, pub latest_block_roots: Vec, pub latest_penalized_exit_balances: Vec, pub latest_attestations: Vec, diff --git a/beacon_chain/types/src/deposit_input.rs b/beacon_chain/types/src/deposit_input.rs index 41b579cda..d280fa7ea 100644 --- a/beacon_chain/types/src/deposit_input.rs +++ b/beacon_chain/types/src/deposit_input.rs @@ -9,6 +9,7 @@ pub struct DepositInput { pub pubkey: PublicKey, pub withdrawal_credentials: Hash256, pub randao_commitment: Hash256, + pub poc_commitment: Hash256, pub proof_of_possession: Signature, } @@ -17,6 +18,7 @@ impl Encodable for DepositInput { s.append_vec(&self.pubkey.as_bytes()); s.append(&self.withdrawal_credentials); s.append(&self.randao_commitment); + s.append(&self.poc_commitment); s.append(&self.proof_of_possession); } } @@ -27,6 +29,7 @@ impl Decodable for DepositInput { let pubkey = PublicKey::from_bytes(&pubkey_bytes).map_err(|_| DecodeError::TooShort)?; let (withdrawal_credentials, i) = <_>::ssz_decode(bytes, i)?; let (randao_commitment, i) = <_>::ssz_decode(bytes, i)?; + let (poc_commitment, i) = <_>::ssz_decode(bytes, i)?; let (proof_of_possession, i) = <_>::ssz_decode(bytes, i)?; Ok(( @@ -34,6 +37,7 @@ impl Decodable for DepositInput { pubkey, withdrawal_credentials, randao_commitment, + poc_commitment, proof_of_possession, }, i, @@ -47,6 +51,7 @@ impl TestRandom for DepositInput { pubkey: <_>::random_for_test(rng), withdrawal_credentials: <_>::random_for_test(rng), randao_commitment: <_>::random_for_test(rng), + poc_commitment: <_>::random_for_test(rng), proof_of_possession: <_>::random_for_test(rng), } } diff --git a/beacon_chain/types/src/validator_record.rs b/beacon_chain/types/src/validator_record.rs index af0e75d39..42dc45811 100644 --- a/beacon_chain/types/src/validator_record.rs +++ b/beacon_chain/types/src/validator_record.rs @@ -34,7 +34,10 @@ pub struct ValidatorRecord { pub randao_layers: u64, pub status: ValidatorStatus, pub latest_status_change_slot: u64, - pub exit_count: u64 + pub exit_count: u64, + pub poc_commitment: Hash256, + pub last_poc_change_slot: u64, + pub second_last_poc_slot: u64 } impl ValidatorRecord { @@ -51,7 +54,10 @@ impl ValidatorRecord { randao_layers: 0, status: From::from(0), latest_status_change_slot: 0, - exit_count: 0 + exit_count: 0, + poc_commitment: Hash256::zero(), + last_poc_change_slot: 0, + second_last_poc_slot: 0 }; (s, keypair) } @@ -71,9 +77,11 @@ mod tests { assert!(v.withdrawal_credentials.is_zero()); assert!(v.randao_commitment.is_zero()); assert_eq!(v.randao_layers, 0); - assert_eq!(v.balance, 0); assert_eq!(v.status, From::from(0)); assert_eq!(v.latest_status_change_slot, 0); assert_eq!(v.exit_count, 0); + assert!(v.poc_commitment.is_zero()); + assert_eq!(v.last_poc_change_slot, 0); + assert_eq!(v.second_last_poc_slot, 0); } } diff --git a/beacon_chain/validator_induction/src/inductor.rs b/beacon_chain/validator_induction/src/inductor.rs index 4b370dcfc..ab40bd8cd 100644 --- a/beacon_chain/validator_induction/src/inductor.rs +++ b/beacon_chain/validator_induction/src/inductor.rs @@ -44,7 +44,10 @@ pub fn process_deposit( randao_layers: 0, status: ValidatorStatus::PendingActivation, latest_status_change_slot: state.validator_registry_latest_change_slot, - exit_count: 0 + exit_count: 0, + poc_commitment: deposit_input.poc_commitment, + last_poc_change_slot: 0, + second_last_poc_slot: 0 }; match min_empty_validator_index(state, spec) { @@ -91,6 +94,7 @@ mod tests { pubkey: kp.pk.clone(), withdrawal_credentials: Hash256::zero(), randao_commitment: Hash256::zero(), + poc_commitment: Hash256::zero(), proof_of_possession: create_proof_of_possession(&kp) }; let deposit_data = DepositData {