From 430bc224a406063651a012642fed4c9d09ebb15b Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 3 Dec 2018 14:29:05 +1100 Subject: [PATCH] Update `BeaconState` object Also adds the following structs: - AttestationData - ForkData - PendingAttestationRecord The `AttestationRecord` object has _not_ been updated. --- beacon_chain/types/src/attestation_data.rs | 13 +++++ beacon_chain/types/src/beacon_state.rs | 34 ++++++++++++ beacon_chain/types/src/fork_data.rs | 6 +++ beacon_chain/types/src/lib.rs | 9 +++- .../types/src/pending_attestation_record.rs | 9 ++++ beacon_chain/types/src/state.rs | 54 ------------------- 6 files changed, 70 insertions(+), 55 deletions(-) create mode 100644 beacon_chain/types/src/attestation_data.rs create mode 100644 beacon_chain/types/src/beacon_state.rs create mode 100644 beacon_chain/types/src/fork_data.rs create mode 100644 beacon_chain/types/src/pending_attestation_record.rs delete mode 100644 beacon_chain/types/src/state.rs diff --git a/beacon_chain/types/src/attestation_data.rs b/beacon_chain/types/src/attestation_data.rs new file mode 100644 index 000000000..9088ce058 --- /dev/null +++ b/beacon_chain/types/src/attestation_data.rs @@ -0,0 +1,13 @@ +use super::Hash256; + +#[derive(Debug, Clone, PartialEq)] +pub struct AttestationData { + pub slot: u64, + pub shard: u64, + pub beacon_block_hash: Hash256, + pub epoch_boundary_hash: Hash256, + pub shard_block_hash: Hash256, + pub latest_crosslink_hash: Hash256, + pub justified_slot: u64, + pub justified_block_hash: Hash256, +} diff --git a/beacon_chain/types/src/beacon_state.rs b/beacon_chain/types/src/beacon_state.rs new file mode 100644 index 000000000..1ab3a58de --- /dev/null +++ b/beacon_chain/types/src/beacon_state.rs @@ -0,0 +1,34 @@ +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_and_committee::ShardAndCommittee; +use super::shard_reassignment_record::ShardReassignmentRecord; +use super::validator_record::ValidatorRecord; +use super::Hash256; + +#[derive(Debug, PartialEq)] +pub struct BeaconState { + validator_registry: Vec, + validator_registry_latest_change_slot: u64, + validator_registry_exit_count: u64, + validator_registry_delta_chain_tip: Hash256, + randao_mix: Hash256, + next_seed: Hash256, + shard_and_committee_for_slots: Vec>, + persistent_committees: Vec>, + persistent_committee_reassignments: Vec, + previous_justified_slot: u64, + justified_slot: u64, + justified_slot_bitfield: u64, + finalized_slot: u64, + latest_crosslinks: Vec, + latest_state_recalculation_slot: u64, + latest_block_hashes: Vec, + latest_penalized_exit_balances: Vec, + latest_attestations: Vec, + processed_pow_receipt_root: Hash256, + candidate_pow_receipt_roots: Vec, + genesis_time: u64, + fork_data: ForkData, +} diff --git a/beacon_chain/types/src/fork_data.rs b/beacon_chain/types/src/fork_data.rs new file mode 100644 index 000000000..4c3541c3f --- /dev/null +++ b/beacon_chain/types/src/fork_data.rs @@ -0,0 +1,6 @@ +#[derive(Debug, Clone, PartialEq)] +pub struct ForkData { + pub pre_fork_version: u64, + pub post_fork_version: u64, + pub fork_slot: u64, +} diff --git a/beacon_chain/types/src/lib.rs b/beacon_chain/types/src/lib.rs index 0cb9b8de0..6ef752e04 100644 --- a/beacon_chain/types/src/lib.rs +++ b/beacon_chain/types/src/lib.rs @@ -4,16 +4,19 @@ extern crate ethereum_types; extern crate ssz; pub mod active_state; +pub mod attestation_data; pub mod attestation_record; pub mod beacon_block; +pub mod beacon_state; pub mod candidate_pow_receipt_root_record; pub mod chain_config; pub mod crosslink_record; pub mod crystallized_state; +pub mod fork_data; +pub mod pending_attestation_record; pub mod shard_and_committee; pub mod shard_reassignment_record; pub mod special_record; -pub mod state; pub mod validator_record; pub mod validator_registration; @@ -21,11 +24,15 @@ use self::ethereum_types::{H160, H256, U256}; use std::collections::HashMap; pub use active_state::ActiveState; +pub use attestation_data::AttestationData; pub use attestation_record::AttestationRecord; pub use beacon_block::BeaconBlock; +pub use beacon_state::BeaconState; pub use chain_config::ChainConfig; pub use crosslink_record::CrosslinkRecord; pub use crystallized_state::CrystallizedState; +pub use fork_data::ForkData; +pub use pending_attestation_record::PendingAttestationRecord; pub use shard_and_committee::ShardAndCommittee; pub use special_record::{SpecialRecord, SpecialRecordKind}; pub use validator_record::{ValidatorRecord, ValidatorStatus}; diff --git a/beacon_chain/types/src/pending_attestation_record.rs b/beacon_chain/types/src/pending_attestation_record.rs new file mode 100644 index 000000000..16f77c90c --- /dev/null +++ b/beacon_chain/types/src/pending_attestation_record.rs @@ -0,0 +1,9 @@ +use super::{AttestationData, Bitfield}; + +#[derive(Debug, Clone, PartialEq)] +pub struct PendingAttestationRecord { + pub data: AttestationData, + pub participation_bitfield: Bitfield, + pub custody_bitfield: Bitfield, + pub slot_included: u64, +} diff --git a/beacon_chain/types/src/state.rs b/beacon_chain/types/src/state.rs deleted file mode 100644 index 1d65c3dae..000000000 --- a/beacon_chain/types/src/state.rs +++ /dev/null @@ -1,54 +0,0 @@ -use super::attestation_record::AttestationRecord; -use super::candidate_pow_receipt_root_record::CandidatePoWReceiptRootRecord; -use super::crosslink_record::CrosslinkRecord; -use super::shard_and_committee::ShardAndCommittee; -use super::shard_reassignment_record::ShardReassignmentRecord; -use super::validator_record::ValidatorRecord; -use super::Hash256; - -#[derive(Debug, PartialEq)] -pub struct BeaconState { - // Slot of last validator set change - validator_set_change_slot: u64, - // List of validators - validators: Vec, - // Most recent crosslink for each shard - crosslinks: Vec, - // Last cycle-boundary state recalculation - last_state_recalculation_slot: u64, - // Last finalized slot - last_finalized_slot: u64, - // Last justified slot - last_justified_slot: u64, - // Number of consecutive justified slots - justified_streak: u64, - // Committee members and their assigned shard, per slot - shard_and_committee_for_slots: Vec>, - // Persistent shard committees - persistent_committees: Vec>, - persistent_committee_reassignments: Vec, - // Randao seed used for next shuffling - next_shuffling_seed: Hash256, - // Total deposits penalized in the given withdrawal period - deposits_penalized_in_period: Vec, - // Hash chain of validator set changes (for light clients to easily track deltas) - validator_set_delta_hash_chain: Hash256, - // Current sequence number for withdrawals - current_exit_seq: u64, - // Genesis time - genesis_time: u64, - // PoW receipt root - processed_pow_receipt_root: Hash256, - candidate_pow_receipt_roots: Vec, - // Parameters relevant to hard forks / versioning. - // Should be updated only by hard forks. - pre_fork_version: u64, - post_fork_version: u64, - fork_slot_number: u64, - // Attestations not yet processed - pending_attestations: Vec, - // recent beacon block hashes needed to process attestations, older to newer - recent_block_hashes: Vec, - // RANDAO state - randao_mix: Hash256, -}