Finish implementing genesis (without tests)
This commit is contained in:
parent
f17d6db5e9
commit
5d85c62f6e
@ -8,7 +8,6 @@ use types::{
|
|||||||
CrosslinkRecord,
|
CrosslinkRecord,
|
||||||
CrystallizedState,
|
CrystallizedState,
|
||||||
Hash256,
|
Hash256,
|
||||||
ValidatorRecord,
|
|
||||||
};
|
};
|
||||||
use validator_induction::{
|
use validator_induction::{
|
||||||
ValidatorInductor,
|
ValidatorInductor,
|
||||||
@ -21,13 +20,24 @@ use validator_shuffling::{
|
|||||||
|
|
||||||
pub const INITIAL_FORK_VERSION: u32 = 0;
|
pub const INITIAL_FORK_VERSION: u32 = 0;
|
||||||
|
|
||||||
|
/// A ChainHead structure represents the "head" or "tip" of a beacon chain blockchain.
|
||||||
|
///
|
||||||
|
/// Initially, a "gensis" chainhead will be created and then new blocks will be built upon it.
|
||||||
pub struct ChainHead {
|
pub struct ChainHead {
|
||||||
active_state: ActiveState,
|
/// The hash of the block that is the head of the chain.
|
||||||
crystallized_state: CrystallizedState,
|
pub head_hash: Hash256,
|
||||||
config: ChainConfig,
|
/// The active state at this head block.
|
||||||
|
pub active_state: ActiveState,
|
||||||
|
/// The crystallized state at this head block.
|
||||||
|
pub crystallized_state: CrystallizedState,
|
||||||
|
/// The configuration of the underlying chain.
|
||||||
|
pub config: ChainConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChainHead {
|
impl ChainHead {
|
||||||
|
/// Initialize a new ChainHead with genesis parameters.
|
||||||
|
///
|
||||||
|
/// Used when syncing a chain from scratch.
|
||||||
pub fn genesis(
|
pub fn genesis(
|
||||||
initial_validator_entries: &[ValidatorRegistration],
|
initial_validator_entries: &[ValidatorRegistration],
|
||||||
config: ChainConfig)
|
config: ChainConfig)
|
||||||
@ -39,17 +49,11 @@ impl ChainHead {
|
|||||||
* 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 validators = vec![];
|
let mut inductor = ValidatorInductor::new(0, config.shard_count, vec![]);
|
||||||
let inductor = ValidatorInductor {
|
|
||||||
current_slot: 0,
|
|
||||||
shard_count: config.shard_count,
|
|
||||||
validators: &mut validators,
|
|
||||||
empty_validator_start: 0,
|
|
||||||
};
|
|
||||||
for registration in initial_validator_entries {
|
for registration in initial_validator_entries {
|
||||||
let _ = inductor.induct(®istration);
|
let _ = inductor.induct(®istration);
|
||||||
};
|
};
|
||||||
validators
|
inductor.to_vec()
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -58,9 +62,10 @@ impl ChainHead {
|
|||||||
* 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 x = shard_and_committees_for_cycle(&vec![0; 32], &validators, 0, &config)?;
|
let mut a = shard_and_committees_for_cycle(&vec![0; 32], &validators, 0, &config)?;
|
||||||
x.append(&mut x.clone());
|
let mut b = a.clone();
|
||||||
x
|
a.append(&mut b);
|
||||||
|
a
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -83,7 +88,7 @@ impl ChainHead {
|
|||||||
*/
|
*/
|
||||||
let crystallized_state = CrystallizedState {
|
let crystallized_state = CrystallizedState {
|
||||||
validator_set_change_slot: 0,
|
validator_set_change_slot: 0,
|
||||||
validators,
|
validators: validators.to_vec(),
|
||||||
crosslinks,
|
crosslinks,
|
||||||
last_state_recalculation_slot: 0,
|
last_state_recalculation_slot: 0,
|
||||||
last_finalized_slot: 0,
|
last_finalized_slot: 0,
|
||||||
@ -97,6 +102,9 @@ impl ChainHead {
|
|||||||
fork_slot_number: 0,
|
fork_slot_number: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set all recent block hashes to zero.
|
||||||
|
*/
|
||||||
let recent_block_hashes = {
|
let recent_block_hashes = {
|
||||||
let mut x = vec![];
|
let mut x = vec![];
|
||||||
for _ in 0..config.cycle_length {
|
for _ in 0..config.cycle_length {
|
||||||
@ -105,6 +113,9 @@ impl ChainHead {
|
|||||||
x
|
x
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create an active state.
|
||||||
|
*/
|
||||||
let active_state = ActiveState {
|
let active_state = ActiveState {
|
||||||
pending_attestations: vec![],
|
pending_attestations: vec![],
|
||||||
pending_specials: vec![],
|
pending_specials: vec![],
|
||||||
@ -114,6 +125,7 @@ impl ChainHead {
|
|||||||
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
head_hash: Hash256::zero(),
|
||||||
active_state,
|
active_state,
|
||||||
crystallized_state,
|
crystallized_state,
|
||||||
config,
|
config,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#[derive(Clone,Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ShardAndCommittee {
|
pub struct ShardAndCommittee {
|
||||||
pub shard_id: u16,
|
pub shard_id: u16,
|
||||||
pub committee: Vec<usize>
|
pub committee: Vec<usize>
|
||||||
|
Loading…
Reference in New Issue
Block a user