Introduce un-tested BeaconState genesis code.
This commit is contained in:
parent
56dc73fbd1
commit
bf49c881d5
@ -7,6 +7,7 @@ authors = ["Paul Hauner <paul@paulhauner.com>"]
|
|||||||
bls = { path = "../utils/bls" }
|
bls = { path = "../utils/bls" }
|
||||||
db = { path = "../../lighthouse/db" }
|
db = { path = "../../lighthouse/db" }
|
||||||
naive_fork_choice = { path = "../naive_fork_choice" }
|
naive_fork_choice = { path = "../naive_fork_choice" }
|
||||||
|
spec = { path = "../spec" }
|
||||||
ssz = { path = "../utils/ssz" }
|
ssz = { path = "../utils/ssz" }
|
||||||
ssz_helpers = { path = "../utils/ssz_helpers" }
|
ssz_helpers = { path = "../utils/ssz_helpers" }
|
||||||
state-transition = { path = "../state-transition" }
|
state-transition = { path = "../state-transition" }
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use super::{ActiveState, ChainConfig, CrystallizedState};
|
use spec::ChainSpec;
|
||||||
use types::ValidatorStatus;
|
use types::{
|
||||||
|
BeaconState, CrosslinkRecord, ForkData, Hash256, ValidatorRegistration, ValidatorStatus,
|
||||||
|
};
|
||||||
use validator_induction::ValidatorInductor;
|
use validator_induction::ValidatorInductor;
|
||||||
use validator_shuffling::{shard_and_committees_for_cycle, ValidatorAssignmentError};
|
use validator_shuffling::{shard_and_committees_for_cycle, ValidatorAssignmentError};
|
||||||
|
|
||||||
@ -18,15 +20,20 @@ impl From<ValidatorAssignmentError> for Error {
|
|||||||
/// Initialize a new ChainHead with genesis parameters.
|
/// Initialize a new ChainHead with genesis parameters.
|
||||||
///
|
///
|
||||||
/// Used when syncing a chain from scratch.
|
/// Used when syncing a chain from scratch.
|
||||||
pub fn genesis_states(config: &ChainConfig) -> Result<(ActiveState, CrystallizedState), Error> {
|
pub fn genesis_states(
|
||||||
|
spec: &ChainSpec,
|
||||||
|
initial_validators: Vec<ValidatorRegistration>,
|
||||||
|
genesis_time: u64,
|
||||||
|
processed_pow_receipt_root: Hash256,
|
||||||
|
) -> Result<BeaconState, Error> {
|
||||||
/*
|
/*
|
||||||
* Parse the ValidatorRegistrations into ValidatorRecords and induct them.
|
* Parse the ValidatorRegistrations into ValidatorRecords and induct them.
|
||||||
*
|
*
|
||||||
* Ignore any records which fail proof-of-possession or are invalid.
|
* Ignore any records which fail proof-of-possession or are invalid.
|
||||||
*/
|
*/
|
||||||
let validators = {
|
let validators = {
|
||||||
let mut inductor = ValidatorInductor::new(0, config.shard_count, vec![]);
|
let mut inductor = ValidatorInductor::new(0, spec.shard_count, vec![]);
|
||||||
for registration in &config.initial_validators {
|
for registration in &initial_validators {
|
||||||
let _ = inductor.induct(®istration, ValidatorStatus::Active);
|
let _ = inductor.induct(®istration, ValidatorStatus::Active);
|
||||||
}
|
}
|
||||||
inductor.to_vec()
|
inductor.to_vec()
|
||||||
@ -38,16 +45,63 @@ pub fn genesis_states(config: &ChainConfig) -> Result<(ActiveState, Crystallized
|
|||||||
* Crystallizedstate stores two cycles, so we simply repeat the same assignment twice.
|
* Crystallizedstate stores two cycles, so we simply repeat the same assignment twice.
|
||||||
*/
|
*/
|
||||||
let _shard_and_committee_for_slots = {
|
let _shard_and_committee_for_slots = {
|
||||||
let mut a = shard_and_committees_for_cycle(&vec![0; 32], &validators, 0, &config)?;
|
let mut a = shard_and_committees_for_cycle(&vec![0; 32], &validators, 0, &spec)?;
|
||||||
let mut b = a.clone();
|
let mut b = a.clone();
|
||||||
a.append(&mut b);
|
a.append(&mut b);
|
||||||
a
|
a
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: implement genesis for `BeaconState`
|
let initial_crosslink = CrosslinkRecord {
|
||||||
// https://github.com/sigp/lighthouse/issues/99
|
slot: spec.initial_slot_number,
|
||||||
|
shard_block_root: spec.zero_hash,
|
||||||
|
};
|
||||||
|
|
||||||
Err(Error::NotImplemented)
|
Ok(BeaconState {
|
||||||
|
/*
|
||||||
|
* Misc
|
||||||
|
*/
|
||||||
|
slot: spec.initial_slot_number,
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
/*
|
||||||
|
* Validator registry
|
||||||
|
*/
|
||||||
|
validator_registry: validators,
|
||||||
|
validator_registry_latest_change_slot: spec.initial_slot_number,
|
||||||
|
validator_registry_exit_count: 0,
|
||||||
|
validator_registry_delta_chain_tip: spec.zero_hash,
|
||||||
|
/*
|
||||||
|
* Randomness and committees
|
||||||
|
*/
|
||||||
|
randao_mix: spec.zero_hash,
|
||||||
|
next_seed: spec.zero_hash,
|
||||||
|
shard_committees_at_slot: vec![],
|
||||||
|
persistent_committees: vec![],
|
||||||
|
persisten_committee_reassignments: vec![],
|
||||||
|
/*
|
||||||
|
* Finality
|
||||||
|
*/
|
||||||
|
previous_justified_slot: spec.initial_slot_number,
|
||||||
|
justified_slot: spec.initial_slot_number,
|
||||||
|
justified_bitfield: 0,
|
||||||
|
finalized_slot: spec.initial_slot_number,
|
||||||
|
/*
|
||||||
|
* Recent state
|
||||||
|
*/
|
||||||
|
latest_crosslinks: vec![initial_crosslink; spec.shard_count as usize],
|
||||||
|
latest_block_roots: vec![spec.zero_hash; spec.epoch_length as usize],
|
||||||
|
latest_penalized_exit_balances: vec![],
|
||||||
|
latest_attestations: vec![],
|
||||||
|
/*
|
||||||
|
* PoW receipt root
|
||||||
|
*/
|
||||||
|
processed_pow_receipt_root,
|
||||||
|
candidate_pow_receipt_roots: vec![],
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
extern crate db;
|
extern crate db;
|
||||||
extern crate naive_fork_choice;
|
extern crate naive_fork_choice;
|
||||||
|
extern crate spec;
|
||||||
extern crate ssz;
|
extern crate ssz;
|
||||||
extern crate ssz_helpers;
|
extern crate ssz_helpers;
|
||||||
extern crate state_transition;
|
extern crate state_transition;
|
||||||
@ -37,10 +38,8 @@ pub struct BeaconChain<T: ClientDB + Sized> {
|
|||||||
pub head_block_hashes: Vec<Hash256>,
|
pub head_block_hashes: Vec<Hash256>,
|
||||||
/// The index of the canonical block in `head_block_hashes`.
|
/// The index of the canonical block in `head_block_hashes`.
|
||||||
pub canonical_head_block_hash: usize,
|
pub canonical_head_block_hash: usize,
|
||||||
/// A map where the value is an active state the the key is its hash.
|
/// An in-memory map of root hash to beacon state.
|
||||||
pub active_states: HashMap<Hash256, ActiveState>,
|
pub beacon_states: HashMap<Hash256, ActiveState>,
|
||||||
/// A map where the value is crystallized state the the key is its hash.
|
|
||||||
pub crystallized_states: HashMap<Hash256, CrystallizedState>,
|
|
||||||
/// A map of crystallized state to a proposer and attester map.
|
/// A map of crystallized state to a proposer and attester map.
|
||||||
pub attester_proposer_maps: HashMap<Hash256, (Arc<AttesterMap>, Arc<ProposerMap>)>,
|
pub attester_proposer_maps: HashMap<Hash256, (Arc<AttesterMap>, Arc<ProposerMap>)>,
|
||||||
/// A collection of database stores used by the chain.
|
/// A collection of database stores used by the chain.
|
||||||
|
Loading…
Reference in New Issue
Block a user