Strip out anitquated parts of chain crate

This commit is contained in:
Paul Hauner 2018-12-10 10:48:02 +11:00
parent 7ea701aa30
commit 3ae82c0710
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
4 changed files with 27 additions and 106 deletions

View File

@ -19,8 +19,8 @@ where
{ {
pub fn process_block( pub fn process_block(
&mut self, &mut self,
ssz: &[u8], _ssz: &[u8],
present_slot: u64, _present_slot: u64,
) -> Result<(BlockProcessingOutcome, Hash256), Error> { ) -> Result<(BlockProcessingOutcome, Hash256), Error> {
// TODO: block processing has been removed. // TODO: block processing has been removed.
// https://github.com/sigp/lighthouse/issues/98 // https://github.com/sigp/lighthouse/issues/98

View File

@ -1,22 +1,24 @@
use super::{ActiveState, BeaconChainError, ChainConfig, CrystallizedState}; use super::{ActiveState, ChainConfig, CrystallizedState};
use types::{CrosslinkRecord, Hash256, ValidatorStatus}; use types::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};
pub const INITIAL_FORK_VERSION: u32 = 0; #[derive(Debug, PartialEq)]
pub enum Error {
ValidationAssignmentError(ValidatorAssignmentError),
NotImplemented,
}
impl From<ValidatorAssignmentError> for BeaconChainError { impl From<ValidatorAssignmentError> for Error {
fn from(_: ValidatorAssignmentError) -> BeaconChainError { fn from(e: ValidatorAssignmentError) -> Error {
BeaconChainError::InvalidGenesis Error::ValidationAssignmentError(e)
} }
} }
/// 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( pub fn genesis_states(config: &ChainConfig) -> Result<(ActiveState, CrystallizedState), Error> {
config: &ChainConfig,
) -> Result<(ActiveState, CrystallizedState), ValidatorAssignmentError> {
/* /*
* Parse the ValidatorRegistrations into ValidatorRecords and induct them. * 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. * 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, &config)?;
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`
* Set all the crosslink records to reference zero hashes. // https://github.com/sigp/lighthouse/issues/99
*/
let crosslinks = {
let mut c = vec![];
for _ in 0..config.shard_count {
c.push(CrosslinkRecord {
recently_changed: false,
slot: 0,
hash: Hash256::zero(),
});
}
c
};
/* Err(Error::NotImplemented)
* 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))
} }
#[cfg(test)] #[cfg(test)]
@ -99,6 +55,10 @@ mod tests {
extern crate bls; extern crate bls;
extern crate validator_induction; 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 self::bls::{create_proof_of_possession, Keypair};
use super::*; use super::*;
use types::{Address, Hash256, ValidatorRegistration}; use types::{Address, Hash256, ValidatorRegistration};
@ -190,4 +150,5 @@ mod tests {
); );
assert_eq!(cry.validators.len(), good_validator_count); assert_eq!(cry.validators.len(), good_validator_count);
} }
*/
} }

View File

@ -14,7 +14,7 @@ mod stores;
mod transition; mod transition;
use db::ClientDB; use db::ClientDB;
use genesis::genesis_states; use genesis::{genesis_states, Error as GenesisError};
use maps::{generate_attester_and_proposer_maps, AttesterAndProposerMapError}; use maps::{generate_attester_and_proposer_maps, AttesterAndProposerMapError};
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
@ -26,6 +26,7 @@ pub enum BeaconChainError {
InvalidGenesis, InvalidGenesis,
InsufficientValidators, InsufficientValidators,
UnableToGenerateMaps(AttesterAndProposerMapError), UnableToGenerateMaps(AttesterAndProposerMapError),
GenesisError(GenesisError),
DBError(String), DBError(String),
} }
@ -101,42 +102,8 @@ impl From<AttesterAndProposerMapError> for BeaconChainError {
} }
} }
#[cfg(test)] impl From<GenesisError> for BeaconChainError {
mod tests { fn from(e: GenesisError) -> BeaconChainError {
use super::*; BeaconChainError::GenesisError(e)
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);
} }
} }

View File

@ -1,7 +0,0 @@
extern crate chain;
#[cfg(test)]
mod tests {
use chain::{BeaconChain, BeaconChainError};
}