From 8dec3c1dc7b90701cef6438e52cc0fe11b80aa31 Mon Sep 17 00:00:00 2001 From: Kirk Baird Date: Wed, 16 Jan 2019 10:39:02 +1100 Subject: [PATCH 1/4] Added/modified types and constants according to specs --- beacon_chain/genesis/src/beacon_block.rs | 17 ++----- beacon_chain/genesis/src/beacon_state.rs | 25 ++++++---- beacon_chain/spec/src/foundation.rs | 48 ++++++++++++++----- beacon_chain/spec/src/lib.rs | 39 +++++++++++---- beacon_chain/types/src/beacon_state.rs | 36 +++++++++++--- .../src/candidate_pow_receipt_root_record.rs | 1 + beacon_chain/types/src/validator_record.rs | 20 ++++++++ beacon_chain/utils/bls/src/signature.rs | 18 +++++++ .../validator_induction/src/inductor.rs | 4 ++ 9 files changed, 160 insertions(+), 48 deletions(-) diff --git a/beacon_chain/genesis/src/beacon_block.rs b/beacon_chain/genesis/src/beacon_block.rs index 6caa0c80c..3d0b8f512 100644 --- a/beacon_chain/genesis/src/beacon_block.rs +++ b/beacon_chain/genesis/src/beacon_block.rs @@ -1,17 +1,15 @@ -use bls::{Signature, BLS_AGG_SIG_BYTE_SIZE}; use spec::ChainSpec; -use ssz::{encode::encode_length, Decodable, LENGTH_BYTES}; use types::{BeaconBlock, BeaconBlockBody, Hash256}; /// Generate a genesis BeaconBlock. pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBlock { BeaconBlock { - slot: spec.initial_slot_number, + slot: spec.genesis_slot_number, parent_root: spec.zero_hash, state_root, randao_reveal: spec.zero_hash, candidate_pow_receipt_root: spec.zero_hash, - signature: genesis_signature(), + signature: spec.empty_signature.clone(), body: BeaconBlockBody { proposer_slashings: vec![], casper_slashings: vec![], @@ -25,19 +23,11 @@ pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBloc } } -fn genesis_signature() -> Signature { - let mut bytes = encode_length(BLS_AGG_SIG_BYTE_SIZE, LENGTH_BYTES); - bytes.append(&mut vec![0; BLS_AGG_SIG_BYTE_SIZE]); - let (signature, _) = match Signature::ssz_decode(&bytes, 0) { - Ok(sig) => sig, - Err(_) => unreachable!(), - }; - signature -} #[cfg(test)] mod tests { use super::*; + use bls::{Signature}; #[test] fn test_genesis() { @@ -101,5 +91,6 @@ mod tests { for item in raw_sig_bytes.iter() { assert!(*item == 0); } + assert_eq!(genesis_block.signature, Signature::empty_sig()); } } diff --git a/beacon_chain/genesis/src/beacon_state.rs b/beacon_chain/genesis/src/beacon_state.rs index 7326bbf1d..09404275d 100644 --- a/beacon_chain/genesis/src/beacon_state.rs +++ b/beacon_chain/genesis/src/beacon_state.rs @@ -21,7 +21,7 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result { }; let initial_crosslink = CrosslinkRecord { - slot: spec.initial_slot_number, + slot: spec.genesis_slot_number, shard_block_root: spec.zero_hash, }; @@ -29,19 +29,19 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result { /* * Misc */ - slot: spec.initial_slot_number, + slot: spec.genesis_slot_number, genesis_time: spec.genesis_time, fork_data: ForkData { - pre_fork_version: spec.initial_fork_version, - post_fork_version: spec.initial_fork_version, - fork_slot: spec.initial_slot_number, + pre_fork_version: spec.genesis_fork_version, + post_fork_version: spec.genesis_fork_version, + fork_slot: spec.genesis_slot_number, }, /* * Validator registry */ validator_registry: spec.initial_validators.clone(), validator_balances: spec.initial_balances.clone(), - validator_registry_latest_change_slot: spec.initial_slot_number, + validator_registry_latest_change_slot: spec.genesis_slot_number, validator_registry_exit_count: 0, validator_registry_delta_chain_tip: spec.zero_hash, /* @@ -52,7 +52,12 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result { spec.zero_hash; (spec.latest_randao_mixes_length / spec.epoch_length) as usize ], - shard_committees_at_slots: vec![], + previous_epoch_start_shard: spec.genesis_start_shard, + current_epoch_start_shard: spec.genesis_start_shard, + previous_epoch_calculation_slot: spec.genesis_slot_number, + current_epoch_calculation_slot: spec.genesis_slot_number, + previous_epoch_randao_mix: spec.zero_hash, + current_epoch_randao_mix: spec.zero_hash, /* * Custody challenges */ @@ -60,10 +65,10 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result { /* * Finality */ - previous_justified_slot: spec.initial_slot_number, - justified_slot: spec.initial_slot_number, + previous_justified_slot: spec.genesis_slot_number, + justified_slot: spec.genesis_slot_number, justification_bitfield: 0, - finalized_slot: spec.initial_slot_number, + finalized_slot: spec.genesis_slot_number, /* * Recent state */ diff --git a/beacon_chain/spec/src/foundation.rs b/beacon_chain/spec/src/foundation.rs index 8e3146ed2..c622bd4a0 100644 --- a/beacon_chain/spec/src/foundation.rs +++ b/beacon_chain/spec/src/foundation.rs @@ -1,5 +1,5 @@ use super::ChainSpec; -use bls::{Keypair, PublicKey, SecretKey}; +use bls::{Keypair, PublicKey, SecretKey, Signature}; use types::{Address, Hash256, ValidatorRecord}; @@ -17,12 +17,11 @@ impl ChainSpec { * Misc */ shard_count: 1_024, - target_committee_size: 256, + target_committee_size: 128, ejection_balance: 16, max_balance_churn_quotient: 32, gwei_per_eth: u64::pow(10, 9), beacon_chain_shard_number: u64::max_value(), - bls_withdrawal_prefix_byte: 0x00, max_casper_votes: 1_024, latest_block_roots_length: 8_192, latest_randao_mixes_length: 8_192, @@ -38,35 +37,58 @@ impl ChainSpec { /* * Initial Values */ - initial_fork_version: 0, - initial_slot_number: 0, + genesis_fork_version: 0, + genesis_slot_number: 0, + genesis_start_shard: 0, + far_future_slot: u64::max_value(), zero_hash: Hash256::zero(), + empty_signature: Signature::empty_sig(), + bls_withdrawal_prefix_byte: 0x00, /* * Time parameters */ slot_duration: 6, min_attestation_inclusion_delay: 4, epoch_length: 64, + seed_lookahead: 64, min_validator_registry_change_interval: 256, pow_receipt_root_voting_period: 1_024, - shard_persistent_committee_change_period: u64::pow(2, 17), - collective_penalty_calculation_period: u64::pow(2, 20), - zero_balance_validator_ttl: u64::pow(2, 22), + min_validator_withdrawal_time: u64::pow(2, 14), + shard_persistent_committee_change_period: u64::pow(2, 17), // old + collective_penalty_calculation_period: u64::pow(2, 20), // old + zero_balance_validator_ttl: u64::pow(2, 22), // old /* * Reward and penalty quotients */ - base_reward_quotient: 2_048, + base_reward_quotient: 1_024, whistleblower_reward_quotient: 512, includer_reward_quotient: 8, - inactivity_penalty_quotient: u64::pow(2, 34), + inactivity_penalty_quotient: u64::pow(2, 24), + /* + * Status flags + */ + initiated_exit: 1, + withdrawable: 2, /* * Max operations per block */ max_proposer_slashings: 16, - max_casper_slashings: 15, + max_casper_slashings: 16, max_attestations: 128, max_deposits: 16, max_exits: 16, + /* + * Validator registry delta flags + */ + activation: 0, + exit: 1, + /* + * Signature domains + */ + domain_deposit: 0, + domain_attestation: 1, + domain_proposal: 2, + domain_exit: 3, /* * Intialization parameters */ @@ -107,6 +129,10 @@ fn initial_validators_for_testing() -> Vec { withdrawal_credentials: Hash256::zero(), randao_commitment: Hash256::zero(), randao_layers: 0, + activation_slot: u64::max_value(), + exit_slot: u64::max_value(), + withdrawal_slot: u64::max_value(), + penalized_slot: u64::max_value(), status: From::from(0), latest_status_change_slot: 0, exit_count: 0, diff --git a/beacon_chain/spec/src/lib.rs b/beacon_chain/spec/src/lib.rs index 5b7bdfae3..cc4ce7380 100644 --- a/beacon_chain/spec/src/lib.rs +++ b/beacon_chain/spec/src/lib.rs @@ -3,6 +3,7 @@ extern crate types; mod foundation; +use bls::Signature; use types::{Address, Hash256, ValidatorRecord}; #[derive(PartialEq, Debug)] @@ -16,7 +17,6 @@ pub struct ChainSpec { pub max_balance_churn_quotient: u64, pub gwei_per_eth: u64, pub beacon_chain_shard_number: u64, - pub bls_withdrawal_prefix_byte: u8, pub max_casper_votes: u64, pub latest_block_roots_length: u64, pub latest_randao_mixes_length: u64, @@ -32,20 +32,26 @@ pub struct ChainSpec { /* * Initial Values */ - pub initial_fork_version: u64, - pub initial_slot_number: u64, + pub genesis_fork_version: u64, + pub genesis_slot_number: u64, + pub genesis_start_shard: u64, + pub far_future_slot: u64, pub zero_hash: Hash256, + pub empty_signature: Signature, + pub bls_withdrawal_prefix_byte: u8, /* * Time parameters */ pub slot_duration: u64, pub min_attestation_inclusion_delay: u64, pub epoch_length: u64, - pub min_validator_registry_change_interval: u64, - pub pow_receipt_root_voting_period: u64, - pub shard_persistent_committee_change_period: u64, - pub collective_penalty_calculation_period: u64, - pub zero_balance_validator_ttl: u64, + pub seed_lookahead: u64, + pub min_validator_registry_change_interval: u64, // a.k.a. entry_exit_delay + pub pow_receipt_root_voting_period: u64, // a.k. deposit_root_voting_period + pub min_validator_withdrawal_time: u64, + pub shard_persistent_committee_change_period: u64, //old + pub collective_penalty_calculation_period: u64, // old + pub zero_balance_validator_ttl: u64, // old /* * Reward and penalty quotients */ @@ -53,6 +59,11 @@ pub struct ChainSpec { pub whistleblower_reward_quotient: u64, pub includer_reward_quotient: u64, pub inactivity_penalty_quotient: u64, + /* + * Status flags + */ + pub initiated_exit: u64, + pub withdrawable: u64, /* * Max operations per block */ @@ -61,6 +72,18 @@ pub struct ChainSpec { pub max_attestations: u64, pub max_deposits: u64, pub max_exits: u64, + /* + * Validator registry delta flags + */ + pub activation: u64, + pub exit: u64, + /* + * Signature domains + */ + pub domain_deposit: u64, + pub domain_attestation: u64, + pub domain_proposal: u64, + pub domain_exit: u64, /* * Intialization parameters */ diff --git a/beacon_chain/types/src/beacon_state.rs b/beacon_chain/types/src/beacon_state.rs index b9994bddd..10d367f19 100644 --- a/beacon_chain/types/src/beacon_state.rs +++ b/beacon_chain/types/src/beacon_state.rs @@ -2,7 +2,6 @@ use super::candidate_pow_receipt_root_record::CandidatePoWReceiptRootRecord; use super::crosslink_record::CrosslinkRecord; use super::fork_data::ForkData; use super::pending_attestation_record::PendingAttestationRecord; -use super::shard_committee::ShardCommittee; use super::validator_record::ValidatorRecord; use super::Hash256; use crate::test_utils::TestRandom; @@ -30,7 +29,12 @@ pub struct BeaconState { // Randomness and committees pub latest_randao_mixes: Vec, pub latest_vdf_outputs: Vec, - pub shard_committees_at_slots: Vec>, + pub previous_epoch_start_shard: u64, + pub current_epoch_start_shard: u64, + pub previous_epoch_calculation_slot: u64, + pub current_epoch_calculation_slot: u64, + pub previous_epoch_randao_mix: Hash256, + pub current_epoch_randao_mix: Hash256, // Custody challenges pub custody_challenges: Vec, @@ -73,7 +77,12 @@ impl Encodable for BeaconState { s.append(&self.validator_registry_delta_chain_tip); s.append(&self.latest_randao_mixes); s.append(&self.latest_vdf_outputs); - s.append(&self.shard_committees_at_slots); + s.append(&self.previous_epoch_start_shard); + s.append(&self.current_epoch_start_shard); + s.append(&self.previous_epoch_calculation_slot); + s.append(&self.current_epoch_calculation_slot); + s.append(&self.previous_epoch_randao_mix); + s.append(&self.current_epoch_randao_mix); s.append(&self.custody_challenges); s.append(&self.previous_justified_slot); s.append(&self.justified_slot); @@ -101,7 +110,12 @@ impl Decodable for BeaconState { let (validator_registry_delta_chain_tip, i) = <_>::ssz_decode(bytes, i)?; let (latest_randao_mixes, i) = <_>::ssz_decode(bytes, i)?; let (latest_vdf_outputs, i) = <_>::ssz_decode(bytes, i)?; - let (shard_committees_at_slots, i) = <_>::ssz_decode(bytes, i)?; + let (previous_epoch_start_shard, i) = <_>::ssz_decode(bytes, i)?; + let (current_epoch_start_shard, i) = <_>::ssz_decode(bytes, i)?; + let (previous_epoch_calculation_slot, i) = <_>::ssz_decode(bytes, i)?; + let (current_epoch_calculation_slot, i) = <_>::ssz_decode(bytes, i)?; + let (previous_epoch_randao_mix, i) = <_>::ssz_decode(bytes, i)?; + let (current_epoch_randao_mix, i) = <_>::ssz_decode(bytes, i)?; let (custody_challenges, i) = <_>::ssz_decode(bytes, i)?; let (previous_justified_slot, i) = <_>::ssz_decode(bytes, i)?; let (justified_slot, i) = <_>::ssz_decode(bytes, i)?; @@ -127,7 +141,12 @@ impl Decodable for BeaconState { validator_registry_delta_chain_tip, latest_randao_mixes, latest_vdf_outputs, - shard_committees_at_slots, + previous_epoch_start_shard, + current_epoch_start_shard, + previous_epoch_calculation_slot, + current_epoch_calculation_slot, + previous_epoch_randao_mix, + current_epoch_randao_mix, custody_challenges, previous_justified_slot, justified_slot, @@ -159,7 +178,12 @@ impl TestRandom for BeaconState { validator_registry_delta_chain_tip: <_>::random_for_test(rng), latest_randao_mixes: <_>::random_for_test(rng), latest_vdf_outputs: <_>::random_for_test(rng), - shard_committees_at_slots: <_>::random_for_test(rng), + previous_epoch_start_shard: <_>::random_for_test(rng), + current_epoch_start_shard: <_>::random_for_test(rng), + previous_epoch_calculation_slot: <_>::random_for_test(rng), + current_epoch_calculation_slot: <_>::random_for_test(rng), + previous_epoch_randao_mix: <_>::random_for_test(rng), + current_epoch_randao_mix: <_>::random_for_test(rng), custody_challenges: <_>::random_for_test(rng), previous_justified_slot: <_>::random_for_test(rng), justified_slot: <_>::random_for_test(rng), diff --git a/beacon_chain/types/src/candidate_pow_receipt_root_record.rs b/beacon_chain/types/src/candidate_pow_receipt_root_record.rs index 5f260c423..9648763f3 100644 --- a/beacon_chain/types/src/candidate_pow_receipt_root_record.rs +++ b/beacon_chain/types/src/candidate_pow_receipt_root_record.rs @@ -3,6 +3,7 @@ use super::Hash256; use crate::test_utils::TestRandom; use rand::RngCore; +// Note: this is refer to as DepositRootVote in specs #[derive(Debug, PartialEq, Clone)] pub struct CandidatePoWReceiptRootRecord { pub candidate_pow_receipt_root: Hash256, diff --git a/beacon_chain/types/src/validator_record.rs b/beacon_chain/types/src/validator_record.rs index 3f4a43261..00e29df64 100644 --- a/beacon_chain/types/src/validator_record.rs +++ b/beacon_chain/types/src/validator_record.rs @@ -35,6 +35,10 @@ pub struct ValidatorRecord { pub withdrawal_credentials: Hash256, pub randao_commitment: Hash256, pub randao_layers: u64, + pub activation_slot: u64, + pub exit_slot: u64, + pub withdrawal_slot: u64, + pub penalized_slot: u64, pub status: ValidatorStatus, pub latest_status_change_slot: u64, pub exit_count: u64, @@ -99,6 +103,10 @@ impl Encodable for ValidatorRecord { s.append(&self.withdrawal_credentials); s.append(&self.randao_commitment); s.append(&self.randao_layers); + s.append(&self.activation_slot); + s.append(&self.exit_slot); + s.append(&self.withdrawal_slot); + s.append(&self.penalized_slot); s.append(&self.status); s.append(&self.latest_status_change_slot); s.append(&self.exit_count); @@ -114,6 +122,10 @@ impl Decodable for ValidatorRecord { let (withdrawal_credentials, i) = <_>::ssz_decode(bytes, i)?; let (randao_commitment, i) = <_>::ssz_decode(bytes, i)?; let (randao_layers, i) = <_>::ssz_decode(bytes, i)?; + let (activation_slot, i) = <_>::ssz_decode(bytes, i)?; + let (exit_slot, i) = <_>::ssz_decode(bytes, i)?; + let (withdrawal_slot, i) = <_>::ssz_decode(bytes, i)?; + let (penalized_slot, i) = <_>::ssz_decode(bytes, i)?; let (status, i) = <_>::ssz_decode(bytes, i)?; let (latest_status_change_slot, i) = <_>::ssz_decode(bytes, i)?; let (exit_count, i) = <_>::ssz_decode(bytes, i)?; @@ -127,6 +139,10 @@ impl Decodable for ValidatorRecord { withdrawal_credentials, randao_commitment, randao_layers, + activation_slot, + exit_slot, + withdrawal_slot, + penalized_slot, status, latest_status_change_slot, exit_count, @@ -146,6 +162,10 @@ impl TestRandom for ValidatorRecord { withdrawal_credentials: <_>::random_for_test(rng), randao_commitment: <_>::random_for_test(rng), randao_layers: <_>::random_for_test(rng), + activation_slot: <_>::random_for_test(rng), + exit_slot: <_>::random_for_test(rng), + withdrawal_slot: <_>::random_for_test(rng), + penalized_slot: <_>::random_for_test(rng), status: <_>::random_for_test(rng), latest_status_change_slot: <_>::random_for_test(rng), exit_count: <_>::random_for_test(rng), diff --git a/beacon_chain/utils/bls/src/signature.rs b/beacon_chain/utils/bls/src/signature.rs index 242908e21..bd363e34a 100644 --- a/beacon_chain/utils/bls/src/signature.rs +++ b/beacon_chain/utils/bls/src/signature.rs @@ -35,6 +35,12 @@ impl Signature { pub fn as_raw(&self) -> &RawSignature { &self.0 } + + /// Returns a new empty signature. + pub fn empty_sig() -> Self { + let empty: Vec = vec![0; 97]; + Signature(RawSignature::from_bytes(&empty).unwrap()) + } } impl Encodable for Signature { @@ -68,4 +74,16 @@ mod tests { assert_eq!(original, decoded); } + + #[test] + pub fn test_empty_sig() { + let sig = Signature::empty_sig(); + + let sig_as_bytes: Vec = sig.as_raw().as_bytes(); + + assert_eq!(sig_as_bytes.len(), 97); + for one_byte in sig_as_bytes.iter() { + assert_eq!(*one_byte, 0); + } + } } diff --git a/beacon_chain/validator_induction/src/inductor.rs b/beacon_chain/validator_induction/src/inductor.rs index f00c9ec55..fd8768cd2 100644 --- a/beacon_chain/validator_induction/src/inductor.rs +++ b/beacon_chain/validator_induction/src/inductor.rs @@ -44,6 +44,10 @@ pub fn process_deposit( withdrawal_credentials: deposit_input.withdrawal_credentials, randao_commitment: deposit_input.randao_commitment, randao_layers: 0, + activation_slot: spec.far_future_slot, + exit_slot: spec.far_future_slot, + withdrawal_slot: spec.far_future_slot, + penalized_slot: spec.far_future_slot, status: ValidatorStatus::PendingActivation, latest_status_change_slot: state.validator_registry_latest_change_slot, exit_count: 0, From b39f7ac6c2bddb15d9b884ce5a1f36f686c6d8de Mon Sep 17 00:00:00 2001 From: Kirk Baird Date: Wed, 16 Jan 2019 11:11:41 +1100 Subject: [PATCH 2/4] Formating previous commit --- beacon_chain/genesis/src/beacon_block.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/beacon_chain/genesis/src/beacon_block.rs b/beacon_chain/genesis/src/beacon_block.rs index 3d0b8f512..b57ffd510 100644 --- a/beacon_chain/genesis/src/beacon_block.rs +++ b/beacon_chain/genesis/src/beacon_block.rs @@ -23,11 +23,10 @@ pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBloc } } - #[cfg(test)] mod tests { use super::*; - use bls::{Signature}; + use bls::Signature; #[test] fn test_genesis() { From fe107616ce6ab18fbc8b674b95eff98cee10b7f0 Mon Sep 17 00:00:00 2001 From: Kirk Baird Date: Wed, 16 Jan 2019 13:32:03 +1100 Subject: [PATCH 3/4] Finailized updating structs / types to match specs as at 16.1.19 --- beacon_chain/spec/src/foundation.rs | 25 +------ beacon_chain/spec/src/lib.rs | 24 +------ beacon_chain/types/src/validator_record.rs | 15 ++-- .../validator_induction/src/inductor.rs | 68 +++---------------- 4 files changed, 19 insertions(+), 113 deletions(-) diff --git a/beacon_chain/spec/src/foundation.rs b/beacon_chain/spec/src/foundation.rs index c622bd4a0..5583957b2 100644 --- a/beacon_chain/spec/src/foundation.rs +++ b/beacon_chain/spec/src/foundation.rs @@ -51,12 +51,9 @@ impl ChainSpec { min_attestation_inclusion_delay: 4, epoch_length: 64, seed_lookahead: 64, - min_validator_registry_change_interval: 256, + entry_exit_delay: 256, pow_receipt_root_voting_period: 1_024, min_validator_withdrawal_time: u64::pow(2, 14), - shard_persistent_committee_change_period: u64::pow(2, 17), // old - collective_penalty_calculation_period: u64::pow(2, 20), // old - zero_balance_validator_ttl: u64::pow(2, 22), // old /* * Reward and penalty quotients */ @@ -64,11 +61,6 @@ impl ChainSpec { whistleblower_reward_quotient: 512, includer_reward_quotient: 8, inactivity_penalty_quotient: u64::pow(2, 24), - /* - * Status flags - */ - initiated_exit: 1, - withdrawable: 2, /* * Max operations per block */ @@ -77,18 +69,6 @@ impl ChainSpec { max_attestations: 128, max_deposits: 16, max_exits: 16, - /* - * Validator registry delta flags - */ - activation: 0, - exit: 1, - /* - * Signature domains - */ - domain_deposit: 0, - domain_attestation: 1, - domain_proposal: 2, - domain_exit: 3, /* * Intialization parameters */ @@ -133,9 +113,8 @@ fn initial_validators_for_testing() -> Vec { exit_slot: u64::max_value(), withdrawal_slot: u64::max_value(), penalized_slot: u64::max_value(), - status: From::from(0), - latest_status_change_slot: 0, exit_count: 0, + status: From::from(0), custody_commitment: Hash256::zero(), latest_custody_reseed_slot: 0, penultimate_custody_reseed_slot: 0, diff --git a/beacon_chain/spec/src/lib.rs b/beacon_chain/spec/src/lib.rs index cc4ce7380..fbe82794d 100644 --- a/beacon_chain/spec/src/lib.rs +++ b/beacon_chain/spec/src/lib.rs @@ -46,12 +46,9 @@ pub struct ChainSpec { pub min_attestation_inclusion_delay: u64, pub epoch_length: u64, pub seed_lookahead: u64, - pub min_validator_registry_change_interval: u64, // a.k.a. entry_exit_delay - pub pow_receipt_root_voting_period: u64, // a.k. deposit_root_voting_period + pub entry_exit_delay: u64, + pub pow_receipt_root_voting_period: u64, // a.k.a. deposit_root_voting_period pub min_validator_withdrawal_time: u64, - pub shard_persistent_committee_change_period: u64, //old - pub collective_penalty_calculation_period: u64, // old - pub zero_balance_validator_ttl: u64, // old /* * Reward and penalty quotients */ @@ -59,11 +56,6 @@ pub struct ChainSpec { pub whistleblower_reward_quotient: u64, pub includer_reward_quotient: u64, pub inactivity_penalty_quotient: u64, - /* - * Status flags - */ - pub initiated_exit: u64, - pub withdrawable: u64, /* * Max operations per block */ @@ -72,18 +64,6 @@ pub struct ChainSpec { pub max_attestations: u64, pub max_deposits: u64, pub max_exits: u64, - /* - * Validator registry delta flags - */ - pub activation: u64, - pub exit: u64, - /* - * Signature domains - */ - pub domain_deposit: u64, - pub domain_attestation: u64, - pub domain_proposal: u64, - pub domain_exit: u64, /* * Intialization parameters */ diff --git a/beacon_chain/types/src/validator_record.rs b/beacon_chain/types/src/validator_record.rs index 00e29df64..7622946f7 100644 --- a/beacon_chain/types/src/validator_record.rs +++ b/beacon_chain/types/src/validator_record.rs @@ -39,9 +39,8 @@ pub struct ValidatorRecord { pub exit_slot: u64, pub withdrawal_slot: u64, pub penalized_slot: u64, - pub status: ValidatorStatus, - pub latest_status_change_slot: u64, pub exit_count: u64, + pub status: ValidatorStatus, pub custody_commitment: Hash256, pub latest_custody_reseed_slot: u64, pub penultimate_custody_reseed_slot: u64, @@ -107,9 +106,8 @@ impl Encodable for ValidatorRecord { s.append(&self.exit_slot); s.append(&self.withdrawal_slot); s.append(&self.penalized_slot); - s.append(&self.status); - s.append(&self.latest_status_change_slot); s.append(&self.exit_count); + s.append(&self.status); s.append(&self.custody_commitment); s.append(&self.latest_custody_reseed_slot); s.append(&self.penultimate_custody_reseed_slot); @@ -126,9 +124,8 @@ impl Decodable for ValidatorRecord { let (exit_slot, i) = <_>::ssz_decode(bytes, i)?; let (withdrawal_slot, i) = <_>::ssz_decode(bytes, i)?; let (penalized_slot, i) = <_>::ssz_decode(bytes, i)?; - let (status, i) = <_>::ssz_decode(bytes, i)?; - let (latest_status_change_slot, i) = <_>::ssz_decode(bytes, i)?; let (exit_count, i) = <_>::ssz_decode(bytes, i)?; + let (status, i) = <_>::ssz_decode(bytes, i)?; let (custody_commitment, i) = <_>::ssz_decode(bytes, i)?; let (latest_custody_reseed_slot, i) = <_>::ssz_decode(bytes, i)?; let (penultimate_custody_reseed_slot, i) = <_>::ssz_decode(bytes, i)?; @@ -143,9 +140,8 @@ impl Decodable for ValidatorRecord { exit_slot, withdrawal_slot, penalized_slot, - status, - latest_status_change_slot, exit_count, + status, custody_commitment, latest_custody_reseed_slot, penultimate_custody_reseed_slot, @@ -166,9 +162,8 @@ impl TestRandom for ValidatorRecord { exit_slot: <_>::random_for_test(rng), withdrawal_slot: <_>::random_for_test(rng), penalized_slot: <_>::random_for_test(rng), - status: <_>::random_for_test(rng), - latest_status_change_slot: <_>::random_for_test(rng), exit_count: <_>::random_for_test(rng), + status: <_>::random_for_test(rng), custody_commitment: <_>::random_for_test(rng), latest_custody_reseed_slot: <_>::random_for_test(rng), penultimate_custody_reseed_slot: <_>::random_for_test(rng), diff --git a/beacon_chain/validator_induction/src/inductor.rs b/beacon_chain/validator_induction/src/inductor.rs index fd8768cd2..871217ffe 100644 --- a/beacon_chain/validator_induction/src/inductor.rs +++ b/beacon_chain/validator_induction/src/inductor.rs @@ -13,7 +13,7 @@ pub fn process_deposit( state: &mut BeaconState, deposit: &Deposit, spec: &ChainSpec, -) -> Result { +) -> Result<(), ValidatorInductionError> { let deposit_input = &deposit.deposit_data.deposit_input; let deposit_data = &deposit.deposit_data; @@ -33,7 +33,7 @@ pub fn process_deposit( == deposit_input.withdrawal_credentials { state.validator_balances[i] += deposit_data.value; - return Ok(i); + return Ok(()); } Err(ValidatorInductionError::InvalidWithdrawalCredentials) @@ -48,43 +48,21 @@ pub fn process_deposit( exit_slot: spec.far_future_slot, withdrawal_slot: spec.far_future_slot, penalized_slot: spec.far_future_slot, - status: ValidatorStatus::PendingActivation, - latest_status_change_slot: state.validator_registry_latest_change_slot, exit_count: 0, + status: ValidatorStatus::PendingActivation, custody_commitment: deposit_input.custody_commitment, latest_custody_reseed_slot: 0, penultimate_custody_reseed_slot: 0, }; - match min_empty_validator_index(state, spec) { - Some(i) => { - state.validator_registry[i] = validator; - state.validator_balances[i] = deposit_data.value; - Ok(i) - } - None => { - state.validator_registry.push(validator); - state.validator_balances.push(deposit_data.value); - Ok(state.validator_registry.len() - 1) - } - } + let _index = state.validator_registry.len(); + state.validator_registry.push(validator); + state.validator_balances.push(deposit_data.value); + Ok(()) } } } -fn min_empty_validator_index(state: &BeaconState, spec: &ChainSpec) -> Option { - for i in 0..state.validator_registry.len() { - if state.validator_balances[i] == 0 - && state.validator_registry[i].latest_status_change_slot - + spec.zero_balance_validator_ttl - <= state.slot - { - return Some(i); - } - } - None -} - #[cfg(test)] mod tests { use super::*; @@ -129,7 +107,7 @@ mod tests { let result = process_deposit(&mut state, &deposit, &spec); - assert_eq!(result.unwrap(), 0); + assert_eq!(result.unwrap(), ()); assert!(deposit_equals_record( &deposit, &state.validator_registry[0] @@ -147,7 +125,7 @@ mod tests { let mut deposit = get_deposit(); let result = process_deposit(&mut state, &deposit, &spec); deposit.deposit_data.value = DEPOSIT_GWEI; - assert_eq!(result.unwrap(), i); + assert_eq!(result.unwrap(), ()); assert!(deposit_equals_record( &deposit, &state.validator_registry[i] @@ -176,7 +154,7 @@ mod tests { let result = process_deposit(&mut state, &deposit, &spec); - assert_eq!(result.unwrap(), 0); + assert_eq!(result.unwrap(), ()); assert!(deposit_equals_record( &deposit, &state.validator_registry[0] @@ -186,32 +164,6 @@ mod tests { assert_eq!(state.validator_balances.len(), 1); } - #[test] - fn test_process_deposit_replace_validator() { - let mut state = BeaconState::default(); - let spec = ChainSpec::foundation(); - - let mut validator = get_validator(); - validator.latest_status_change_slot = 0; - state.validator_registry.push(validator); - state.validator_balances.push(0); - - let mut deposit = get_deposit(); - deposit.deposit_data.value = DEPOSIT_GWEI; - state.slot = spec.zero_balance_validator_ttl; - - let result = process_deposit(&mut state, &deposit, &spec); - - assert_eq!(result.unwrap(), 0); - assert!(deposit_equals_record( - &deposit, - &state.validator_registry[0] - )); - assert_eq!(state.validator_balances[0], DEPOSIT_GWEI); - assert_eq!(state.validator_registry.len(), 1); - assert_eq!(state.validator_balances.len(), 1); - } - #[test] fn test_process_deposit_invalid_proof_of_possession() { let mut state = BeaconState::default(); From a0e7f8830336b7c0391e675a419fce918d4fef16 Mon Sep 17 00:00:00 2001 From: Kirk Baird Date: Fri, 18 Jan 2019 09:59:07 +1100 Subject: [PATCH 4/4] Merge changes from genesis_test and minor formatting --- beacon_chain/genesis/src/beacon_block.rs | 2 +- beacon_chain/spec/src/foundation.rs | 2 +- beacon_chain/utils/bls/src/signature.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/beacon_chain/genesis/src/beacon_block.rs b/beacon_chain/genesis/src/beacon_block.rs index 5c2124ccc..3fefff6a0 100644 --- a/beacon_chain/genesis/src/beacon_block.rs +++ b/beacon_chain/genesis/src/beacon_block.rs @@ -84,6 +84,6 @@ mod tests { for item in raw_sig_bytes.iter() { assert!(*item == 0); } - assert_eq!(genesis_block.signature, Signature::empty_sig()); + assert_eq!(genesis_block.signature, Signature::empty_signature()); } } diff --git a/beacon_chain/spec/src/foundation.rs b/beacon_chain/spec/src/foundation.rs index 5583957b2..2e3f92df6 100644 --- a/beacon_chain/spec/src/foundation.rs +++ b/beacon_chain/spec/src/foundation.rs @@ -42,7 +42,7 @@ impl ChainSpec { genesis_start_shard: 0, far_future_slot: u64::max_value(), zero_hash: Hash256::zero(), - empty_signature: Signature::empty_sig(), + empty_signature: Signature::empty_signature(), bls_withdrawal_prefix_byte: 0x00, /* * Time parameters diff --git a/beacon_chain/utils/bls/src/signature.rs b/beacon_chain/utils/bls/src/signature.rs index bd363e34a..07fc2baff 100644 --- a/beacon_chain/utils/bls/src/signature.rs +++ b/beacon_chain/utils/bls/src/signature.rs @@ -37,7 +37,7 @@ impl Signature { } /// Returns a new empty signature. - pub fn empty_sig() -> Self { + pub fn empty_signature() -> Self { let empty: Vec = vec![0; 97]; Signature(RawSignature::from_bytes(&empty).unwrap()) } @@ -76,8 +76,8 @@ mod tests { } #[test] - pub fn test_empty_sig() { - let sig = Signature::empty_sig(); + pub fn test_empty_signature() { + let sig = Signature::empty_signature(); let sig_as_bytes: Vec = sig.as_raw().as_bytes();