Modify BeaconState and BeaconBlockBody to reflect changes in the specs. Also add new variable LATEST_RANDAO_MIXES_LENGTH to foundation
This commit is contained in:
parent
7df6481349
commit
7979ec1635
@ -16,6 +16,9 @@ pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBloc
|
||||
proposer_slashings: vec![],
|
||||
casper_slashings: vec![],
|
||||
attestations: vec![],
|
||||
custody_reseeds: vec![],
|
||||
custody_challenges: vec![],
|
||||
custody_responses: vec![],
|
||||
deposits: vec![],
|
||||
exits: vec![],
|
||||
},
|
||||
|
@ -47,11 +47,13 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
||||
/*
|
||||
* Randomness and committees
|
||||
*/
|
||||
randao_mix: spec.zero_hash,
|
||||
next_seed: spec.zero_hash,
|
||||
latest_randao_mixes: vec![spec.zero_hash; spec.latest_randao_mixes_length as usize],
|
||||
latest_vdf_outputs: vec![spec.zero_hash; (spec.latest_randao_mixes_length / spec.epoch_length) as usize],
|
||||
shard_committees_at_slots: vec![],
|
||||
persistent_committees: vec![],
|
||||
persistent_committee_reassignments: vec![],
|
||||
/*
|
||||
* Custody challenges
|
||||
*/
|
||||
custody_challenges: vec![],
|
||||
/*
|
||||
* Finality
|
||||
*/
|
||||
@ -66,6 +68,7 @@ pub fn genesis_beacon_state(spec: &ChainSpec) -> Result<BeaconState, Error> {
|
||||
latest_block_roots: vec![spec.zero_hash; spec.epoch_length as usize],
|
||||
latest_penalized_exit_balances: vec![],
|
||||
latest_attestations: vec![],
|
||||
batched_block_roots: vec![],
|
||||
/*
|
||||
* PoW receipt root
|
||||
*/
|
||||
|
@ -24,6 +24,7 @@ impl ChainSpec {
|
||||
beacon_chain_shard_number: u64::max_value(),
|
||||
bls_withdrawal_prefix_byte: 0x00,
|
||||
max_casper_votes: 1_024,
|
||||
latest_randao_mixes_length: 8_192,
|
||||
/*
|
||||
* Deposit contract
|
||||
*/
|
||||
|
@ -18,6 +18,7 @@ pub struct ChainSpec {
|
||||
pub beacon_chain_shard_number: u64,
|
||||
pub bls_withdrawal_prefix_byte: u8,
|
||||
pub max_casper_votes: u64,
|
||||
pub latest_randao_mixes_length: u64,
|
||||
/*
|
||||
* Deposit contract
|
||||
*/
|
||||
|
@ -3,11 +3,20 @@ use super::{Attestation, CasperSlashing, Deposit, Exit, ProposerSlashing};
|
||||
use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
|
||||
// The following types are just dummy classes as they will not be defined until
|
||||
// Phase 1 (Sharding phase)
|
||||
type CustodyReseed = usize;
|
||||
type CustodyChallenge = usize;
|
||||
type CustodyResponse = usize;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Default)]
|
||||
pub struct BeaconBlockBody {
|
||||
pub proposer_slashings: Vec<ProposerSlashing>,
|
||||
pub casper_slashings: Vec<CasperSlashing>,
|
||||
pub attestations: Vec<Attestation>,
|
||||
pub custody_reseeds: Vec<CustodyReseed>,
|
||||
pub custody_challenges: Vec<CustodyChallenge>,
|
||||
pub custody_responses: Vec<CustodyResponse>,
|
||||
pub deposits: Vec<Deposit>,
|
||||
pub exits: Vec<Exit>,
|
||||
}
|
||||
@ -17,6 +26,9 @@ impl Encodable for BeaconBlockBody {
|
||||
s.append_vec(&self.proposer_slashings);
|
||||
s.append_vec(&self.casper_slashings);
|
||||
s.append_vec(&self.attestations);
|
||||
s.append_vec(&self.custody_reseeds);
|
||||
s.append_vec(&self.custody_challenges);
|
||||
s.append_vec(&self.custody_responses);
|
||||
s.append_vec(&self.deposits);
|
||||
s.append_vec(&self.exits);
|
||||
}
|
||||
@ -27,6 +39,9 @@ impl Decodable for BeaconBlockBody {
|
||||
let (proposer_slashings, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (casper_slashings, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (attestations, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (custody_reseeds, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (custody_challenges, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (custody_responses, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (deposits, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (exits, i) = <_>::ssz_decode(bytes, i)?;
|
||||
|
||||
@ -35,6 +50,9 @@ impl Decodable for BeaconBlockBody {
|
||||
proposer_slashings,
|
||||
casper_slashings,
|
||||
attestations,
|
||||
custody_reseeds,
|
||||
custody_challenges,
|
||||
custody_responses,
|
||||
deposits,
|
||||
exits,
|
||||
},
|
||||
@ -49,6 +67,9 @@ impl<T: RngCore> TestRandom<T> for BeaconBlockBody {
|
||||
proposer_slashings: <_>::random_for_test(rng),
|
||||
casper_slashings: <_>::random_for_test(rng),
|
||||
attestations: <_>::random_for_test(rng),
|
||||
custody_reseeds: <_>::random_for_test(rng),
|
||||
custody_challenges: <_>::random_for_test(rng),
|
||||
custody_responses: <_>::random_for_test(rng),
|
||||
deposits: <_>::random_for_test(rng),
|
||||
exits: <_>::random_for_test(rng),
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ use super::crosslink_record::CrosslinkRecord;
|
||||
use super::fork_data::ForkData;
|
||||
use super::pending_attestation_record::PendingAttestationRecord;
|
||||
use super::shard_committee::ShardCommittee;
|
||||
use super::shard_reassignment_record::ShardReassignmentRecord;
|
||||
use super::validator_record::ValidatorRecord;
|
||||
use super::Hash256;
|
||||
use crate::test_utils::TestRandom;
|
||||
@ -11,6 +10,9 @@ use hashing::canonical_hash;
|
||||
use rand::RngCore;
|
||||
use ssz::{ssz_encode, Decodable, DecodeError, Encodable, SszStream};
|
||||
|
||||
// Custody will not be added to the specs until Phase 1 (Sharding Phase) so dummay class used.
|
||||
type CustodyChallenge = usize;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Default)]
|
||||
pub struct BeaconState {
|
||||
// Misc
|
||||
@ -26,11 +28,12 @@ pub struct BeaconState {
|
||||
pub validator_registry_delta_chain_tip: Hash256,
|
||||
|
||||
// Randomness and committees
|
||||
pub randao_mix: Hash256,
|
||||
pub next_seed: Hash256,
|
||||
pub latest_randao_mixes: Vec<Hash256>,
|
||||
pub latest_vdf_outputs: Vec<Hash256>,
|
||||
pub shard_committees_at_slots: Vec<Vec<ShardCommittee>>,
|
||||
pub persistent_committees: Vec<Vec<u32>>,
|
||||
pub persistent_committee_reassignments: Vec<ShardReassignmentRecord>,
|
||||
|
||||
// Custody challenges
|
||||
pub custody_challenges: Vec<CustodyChallenge>,
|
||||
|
||||
// Finality
|
||||
pub previous_justified_slot: u64,
|
||||
@ -43,8 +46,9 @@ pub struct BeaconState {
|
||||
pub latest_block_roots: Vec<Hash256>,
|
||||
pub latest_penalized_exit_balances: Vec<u64>,
|
||||
pub latest_attestations: Vec<PendingAttestationRecord>,
|
||||
pub batched_block_roots: Vec<Hash256>,
|
||||
|
||||
// PoW receipt root
|
||||
// PoW receipt root (a.k.a. deposit root)
|
||||
pub processed_pow_receipt_root: Hash256,
|
||||
pub candidate_pow_receipt_roots: Vec<CandidatePoWReceiptRootRecord>,
|
||||
}
|
||||
@ -67,11 +71,10 @@ impl Encodable for BeaconState {
|
||||
s.append(&self.validator_registry_latest_change_slot);
|
||||
s.append(&self.validator_registry_exit_count);
|
||||
s.append(&self.validator_registry_delta_chain_tip);
|
||||
s.append(&self.randao_mix);
|
||||
s.append(&self.next_seed);
|
||||
s.append(&self.latest_randao_mixes);
|
||||
s.append(&self.latest_vdf_outputs);
|
||||
s.append(&self.shard_committees_at_slots);
|
||||
s.append(&self.persistent_committees);
|
||||
s.append(&self.persistent_committee_reassignments);
|
||||
s.append(&self.custody_challenges);
|
||||
s.append(&self.previous_justified_slot);
|
||||
s.append(&self.justified_slot);
|
||||
s.append(&self.justification_bitfield);
|
||||
@ -80,6 +83,7 @@ impl Encodable for BeaconState {
|
||||
s.append(&self.latest_block_roots);
|
||||
s.append(&self.latest_penalized_exit_balances);
|
||||
s.append(&self.latest_attestations);
|
||||
s.append(&self.batched_block_roots);
|
||||
s.append(&self.processed_pow_receipt_root);
|
||||
s.append(&self.candidate_pow_receipt_roots);
|
||||
}
|
||||
@ -95,11 +99,10 @@ impl Decodable for BeaconState {
|
||||
let (validator_registry_latest_change_slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (validator_registry_exit_count, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (validator_registry_delta_chain_tip, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (randao_mix, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (next_seed, 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 (persistent_committees, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (persistent_committee_reassignments, 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)?;
|
||||
let (justification_bitfield, i) = <_>::ssz_decode(bytes, i)?;
|
||||
@ -108,6 +111,7 @@ impl Decodable for BeaconState {
|
||||
let (latest_block_roots, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (latest_penalized_exit_balances, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (latest_attestations, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (batched_block_roots, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (processed_pow_receipt_root, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (candidate_pow_receipt_roots, i) = <_>::ssz_decode(bytes, i)?;
|
||||
|
||||
@ -121,11 +125,10 @@ impl Decodable for BeaconState {
|
||||
validator_registry_latest_change_slot,
|
||||
validator_registry_exit_count,
|
||||
validator_registry_delta_chain_tip,
|
||||
randao_mix,
|
||||
next_seed,
|
||||
latest_randao_mixes,
|
||||
latest_vdf_outputs,
|
||||
shard_committees_at_slots,
|
||||
persistent_committees,
|
||||
persistent_committee_reassignments,
|
||||
custody_challenges,
|
||||
previous_justified_slot,
|
||||
justified_slot,
|
||||
justification_bitfield,
|
||||
@ -134,6 +137,7 @@ impl Decodable for BeaconState {
|
||||
latest_block_roots,
|
||||
latest_penalized_exit_balances,
|
||||
latest_attestations,
|
||||
batched_block_roots,
|
||||
processed_pow_receipt_root,
|
||||
candidate_pow_receipt_roots,
|
||||
},
|
||||
@ -153,11 +157,10 @@ impl<T: RngCore> TestRandom<T> for BeaconState {
|
||||
validator_registry_latest_change_slot: <_>::random_for_test(rng),
|
||||
validator_registry_exit_count: <_>::random_for_test(rng),
|
||||
validator_registry_delta_chain_tip: <_>::random_for_test(rng),
|
||||
randao_mix: <_>::random_for_test(rng),
|
||||
next_seed: <_>::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),
|
||||
persistent_committees: <_>::random_for_test(rng),
|
||||
persistent_committee_reassignments: <_>::random_for_test(rng),
|
||||
custody_challenges: <_>::random_for_test(rng),
|
||||
previous_justified_slot: <_>::random_for_test(rng),
|
||||
justified_slot: <_>::random_for_test(rng),
|
||||
justification_bitfield: <_>::random_for_test(rng),
|
||||
@ -166,6 +169,7 @@ impl<T: RngCore> TestRandom<T> for BeaconState {
|
||||
latest_block_roots: <_>::random_for_test(rng),
|
||||
latest_penalized_exit_balances: <_>::random_for_test(rng),
|
||||
latest_attestations: <_>::random_for_test(rng),
|
||||
batched_block_roots: <_>::random_for_test(rng),
|
||||
processed_pow_receipt_root: <_>::random_for_test(rng),
|
||||
candidate_pow_receipt_roots: <_>::random_for_test(rng),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user