beacon_state, deposit_input, and validator_record updated again

beacon_state, deposit_input, and validator_record updated again
This commit is contained in:
Grant Wuerker 2018-12-26 14:43:09 -06:00
parent da508fd826
commit 65917a696a
5 changed files with 30 additions and 8 deletions

View File

@ -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.

View File

@ -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<Vec<ShardAndCommittee>>,
pub latest_randao_mixes: Vec<Hash256>,
pub latest_vdf_outputs: Vec<Hash256>,
pub shard_committees_at_slots: Vec<Vec<ShardAndCommittee>>,
pub persistent_committees: Vec<Vec<u32>>,
pub persistent_committee_reassignments: Vec<ShardReassignmentRecord>,
pub previous_justified_slot: u64,
@ -27,6 +27,8 @@ pub struct BeaconState {
pub justification_bitfield: u64,
pub finalized_slot: u64,
pub latest_crosslinks: Vec<CrosslinkRecord>,
// TODO: remove this, it's no longer in the spec
pub latest_state_recalculation_slot: u64,
pub latest_block_roots: Vec<Hash256>,
pub latest_penalized_exit_balances: Vec<u64>,
pub latest_attestations: Vec<PendingAttestationRecord>,

View File

@ -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<T: RngCore> TestRandom<T> 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),
}
}

View File

@ -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);
}
}

View File

@ -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 {