From 3ae82c0710729645acce28cd1c3090b5ed12f1dd Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 10 Dec 2018 10:48:02 +1100 Subject: [PATCH] Strip out anitquated parts of chain crate --- beacon_chain/chain/src/block_processing.rs | 4 +- beacon_chain/chain/src/genesis.rs | 79 ++++++---------------- beacon_chain/chain/src/lib.rs | 43 ++---------- beacon_chain/chain/tests/main.rs | 7 -- 4 files changed, 27 insertions(+), 106 deletions(-) delete mode 100644 beacon_chain/chain/tests/main.rs diff --git a/beacon_chain/chain/src/block_processing.rs b/beacon_chain/chain/src/block_processing.rs index 8954e48d8..b576bdbce 100644 --- a/beacon_chain/chain/src/block_processing.rs +++ b/beacon_chain/chain/src/block_processing.rs @@ -19,8 +19,8 @@ where { pub fn process_block( &mut self, - ssz: &[u8], - present_slot: u64, + _ssz: &[u8], + _present_slot: u64, ) -> Result<(BlockProcessingOutcome, Hash256), Error> { // TODO: block processing has been removed. // https://github.com/sigp/lighthouse/issues/98 diff --git a/beacon_chain/chain/src/genesis.rs b/beacon_chain/chain/src/genesis.rs index fb0bc58f8..d9b634062 100644 --- a/beacon_chain/chain/src/genesis.rs +++ b/beacon_chain/chain/src/genesis.rs @@ -1,22 +1,24 @@ -use super::{ActiveState, BeaconChainError, ChainConfig, CrystallizedState}; -use types::{CrosslinkRecord, Hash256, ValidatorStatus}; +use super::{ActiveState, ChainConfig, CrystallizedState}; +use types::ValidatorStatus; use validator_induction::ValidatorInductor; use validator_shuffling::{shard_and_committees_for_cycle, ValidatorAssignmentError}; -pub const INITIAL_FORK_VERSION: u32 = 0; +#[derive(Debug, PartialEq)] +pub enum Error { + ValidationAssignmentError(ValidatorAssignmentError), + NotImplemented, +} -impl From for BeaconChainError { - fn from(_: ValidatorAssignmentError) -> BeaconChainError { - BeaconChainError::InvalidGenesis +impl From for Error { + fn from(e: ValidatorAssignmentError) -> Error { + Error::ValidationAssignmentError(e) } } /// Initialize a new ChainHead with genesis parameters. /// /// Used when syncing a chain from scratch. -pub fn genesis_states( - config: &ChainConfig, -) -> Result<(ActiveState, CrystallizedState), ValidatorAssignmentError> { +pub fn genesis_states(config: &ChainConfig) -> Result<(ActiveState, CrystallizedState), Error> { /* * Parse the ValidatorRegistrations into ValidatorRecords and induct them. * @@ -35,63 +37,17 @@ pub fn genesis_states( * * 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 b = a.clone(); a.append(&mut b); a }; - /* - * Set all the crosslink records to reference zero hashes. - */ - let crosslinks = { - let mut c = vec![]; - for _ in 0..config.shard_count { - c.push(CrosslinkRecord { - recently_changed: false, - slot: 0, - hash: Hash256::zero(), - }); - } - c - }; + // TODO: implement genesis for `BeaconState` + // https://github.com/sigp/lighthouse/issues/99 - /* - * Initialize a genesis `Crystallizedstate` - */ - let crystallized_state = CrystallizedState { - validator_set_change_slot: 0, - validators: validators.to_vec(), - crosslinks, - last_state_recalculation_slot: 0, - last_finalized_slot: 0, - last_justified_slot: 0, - justified_streak: 0, - shard_and_committee_for_slots, - deposits_penalized_in_period: vec![], - validator_set_delta_hash_chain: Hash256::zero(), - pre_fork_version: INITIAL_FORK_VERSION, - post_fork_version: INITIAL_FORK_VERSION, - fork_slot_number: 0, - }; - - /* - * Set all recent block hashes to zero. - */ - let recent_block_hashes = vec![Hash256::zero(); config.cycle_length as usize]; - - /* - * Create an active state. - */ - let active_state = ActiveState { - pending_attestations: vec![], - pending_specials: vec![], - recent_block_hashes, - randao_mix: Hash256::zero(), - }; - - Ok((active_state, crystallized_state)) + Err(Error::NotImplemented) } #[cfg(test)] @@ -99,6 +55,10 @@ mod tests { extern crate bls; extern crate validator_induction; + // TODO: implement genesis for `BeaconState` + // https://github.com/sigp/lighthouse/issues/99 + // + /* use self::bls::{create_proof_of_possession, Keypair}; use super::*; use types::{Address, Hash256, ValidatorRegistration}; @@ -190,4 +150,5 @@ mod tests { ); assert_eq!(cry.validators.len(), good_validator_count); } + */ } diff --git a/beacon_chain/chain/src/lib.rs b/beacon_chain/chain/src/lib.rs index 17cda320f..0837f3baf 100644 --- a/beacon_chain/chain/src/lib.rs +++ b/beacon_chain/chain/src/lib.rs @@ -14,7 +14,7 @@ mod stores; mod transition; use db::ClientDB; -use genesis::genesis_states; +use genesis::{genesis_states, Error as GenesisError}; use maps::{generate_attester_and_proposer_maps, AttesterAndProposerMapError}; use std::collections::HashMap; use std::sync::Arc; @@ -26,6 +26,7 @@ pub enum BeaconChainError { InvalidGenesis, InsufficientValidators, UnableToGenerateMaps(AttesterAndProposerMapError), + GenesisError(GenesisError), DBError(String), } @@ -101,42 +102,8 @@ impl From for BeaconChainError { } } -#[cfg(test)] -mod tests { - use super::*; - use db::stores::*; - use db::MemoryDB; - use std::sync::Arc; - use types::ValidatorRegistration; - - #[test] - fn test_new_chain() { - let mut config = ChainConfig::standard(); - config.cycle_length = 4; - config.shard_count = 4; - let db = Arc::new(MemoryDB::open()); - let store = BeaconChainStore { - block: Arc::new(BeaconBlockStore::new(db.clone())), - pow_chain: Arc::new(PoWChainStore::new(db.clone())), - validator: Arc::new(ValidatorStore::new(db.clone())), - }; - - for _ in 0..config.cycle_length * 2 { - config - .initial_validators - .push(ValidatorRegistration::random()) - } - - let chain = BeaconChain::new(store, config.clone()).unwrap(); - let (act, cry) = genesis_states(&config).unwrap(); - - assert_eq!(chain.last_finalized_slot, 0); - assert_eq!(chain.canonical_block_hash(), Hash256::zero()); - - let stored_act = chain.active_states.get(&Hash256::zero()).unwrap(); - assert_eq!(act, *stored_act); - - let stored_cry = chain.crystallized_states.get(&Hash256::zero()).unwrap(); - assert_eq!(cry, *stored_cry); +impl From for BeaconChainError { + fn from(e: GenesisError) -> BeaconChainError { + BeaconChainError::GenesisError(e) } } diff --git a/beacon_chain/chain/tests/main.rs b/beacon_chain/chain/tests/main.rs deleted file mode 100644 index 8b926693e..000000000 --- a/beacon_chain/chain/tests/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -extern crate chain; - -#[cfg(test)] -mod tests { - use chain::{BeaconChain, BeaconChainError}; - -}