Merge branch 'timing-report' of github.com:sigp/lighthouse into timing-report

Signed-off-by: Kirk Baird <baird.k@outlook.com>
This commit is contained in:
Kirk Baird 2019-03-11 11:55:32 +11:00
commit 9c225936b6
5 changed files with 26 additions and 48 deletions

View File

@ -15,7 +15,7 @@
//! let validator_count = 8; //! let validator_count = 8;
//! let spec = ChainSpec::few_validators(); //! let spec = ChainSpec::few_validators();
//! //!
//! let mut harness = BeaconChainHarness::new(spec, validator_count); //! let mut harness = BeaconChainHarness::new(spec, validator_count, None, true);
//! //!
//! harness.advance_chain_with_block(); //! harness.advance_chain_with_block();
//! //!

View File

@ -10,7 +10,7 @@ fn it_can_build_on_genesis_block() {
let spec = ChainSpec::few_validators(); let spec = ChainSpec::few_validators();
let validator_count = 8; let validator_count = 8;
let mut harness = BeaconChainHarness::new(spec, validator_count as usize); let mut harness = BeaconChainHarness::new(spec, validator_count as usize, None, true);
harness.advance_chain_with_block(); harness.advance_chain_with_block();
} }
@ -25,7 +25,7 @@ fn it_can_produce_past_first_epoch_boundary() {
debug!("Starting harness build..."); debug!("Starting harness build...");
let mut harness = BeaconChainHarness::new(spec, validator_count); let mut harness = BeaconChainHarness::new(spec, validator_count, None, true);
debug!("Harness built, tests starting.."); debug!("Harness built, tests starting..");

View File

@ -17,8 +17,12 @@ use db::{
use fork_choice::BitwiseLMDGhost; use fork_choice::BitwiseLMDGhost;
use slog::{error, info, o, Drain}; use slog::{error, info, o, Drain};
use slot_clock::SystemTimeSlotClock; use slot_clock::SystemTimeSlotClock;
use ssz::TreeHash;
use std::sync::Arc; use std::sync::Arc;
use types::{ChainSpec, Deposit, DepositData, DepositInput, Eth1Data, Hash256, Keypair}; use types::{
beacon_state::BeaconStateBuilder, BeaconBlock, ChainSpec, Deposit, DepositData, DepositInput,
Eth1Data, Hash256, Keypair,
};
fn main() { fn main() {
let decorator = slog_term::TermDecorator::new().build(); let decorator = slog_term::TermDecorator::new().build();
@ -97,7 +101,8 @@ fn main() {
.iter() .iter()
.map(|_| Keypair::random()) .map(|_| Keypair::random())
.collect(); .collect();
let initial_validator_deposits = keypairs
let initial_validator_deposits: Vec<Deposit> = keypairs
.iter() .iter()
.map(|keypair| Deposit { .map(|keypair| Deposit {
branch: vec![], // branch verification is not specified. branch: vec![], // branch verification is not specified.
@ -114,14 +119,19 @@ fn main() {
}) })
.collect(); .collect();
let mut state_builder = BeaconStateBuilder::new(genesis_time, latest_eth1_data, &spec);
state_builder.process_initial_deposits(&initial_validator_deposits, &spec);
let genesis_state = state_builder.build(&spec).unwrap();
let state_root = Hash256::from_slice(&genesis_state.hash_tree_root());
let genesis_block = BeaconBlock::genesis(state_root, &spec);
// Genesis chain // Genesis chain
let _chain_result = BeaconChain::genesis( let _chain_result = BeaconChain::from_genesis(
state_store.clone(), state_store.clone(),
block_store.clone(), block_store.clone(),
slot_clock, slot_clock,
genesis_time, genesis_state,
latest_eth1_data, genesis_block,
initial_validator_deposits,
spec, spec,
fork_choice, fork_choice,
); );

View File

@ -12,7 +12,7 @@ extern crate types;
extern crate yaml_rust; extern crate yaml_rust;
pub use beacon_chain::BeaconChain; pub use beacon_chain::BeaconChain;
use bls::{PublicKey, Signature}; use bls::Signature;
use db::stores::{BeaconBlockStore, BeaconStateStore}; use db::stores::{BeaconBlockStore, BeaconStateStore};
use db::MemoryDB; use db::MemoryDB;
//use env_logger::{Builder, Env}; //use env_logger::{Builder, Env};
@ -21,9 +21,8 @@ use ssz::ssz_encode;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use std::{fs::File, io::prelude::*, path::PathBuf}; use std::{fs::File, io::prelude::*, path::PathBuf};
use types::{ use types::test_utils::TestingBeaconStateBuilder;
BeaconBlock, BeaconBlockBody, BeaconState, ChainSpec, Epoch, Eth1Data, Hash256, Slot, Validator, use types::{BeaconBlock, BeaconBlockBody, ChainSpec, Eth1Data, Hash256, Slot};
};
use yaml_rust::yaml; use yaml_rust::yaml;
// Note: We Assume the block Id's are hex-encoded. // Note: We Assume the block Id's are hex-encoded.
@ -207,8 +206,6 @@ fn setup_inital_state(
fork_choice_algo: &ForkChoiceAlgorithm, fork_choice_algo: &ForkChoiceAlgorithm,
no_validators: usize, no_validators: usize,
) -> (Box<ForkChoice>, Arc<BeaconBlockStore<MemoryDB>>, Hash256) { ) -> (Box<ForkChoice>, Arc<BeaconBlockStore<MemoryDB>>, Hash256) {
let zero_hash = Hash256::zero();
let db = Arc::new(MemoryDB::open()); let db = Arc::new(MemoryDB::open());
let block_store = Arc::new(BeaconBlockStore::new(db.clone())); let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
let state_store = Arc::new(BeaconStateStore::new(db.clone())); let state_store = Arc::new(BeaconStateStore::new(db.clone()));
@ -225,40 +222,10 @@ fn setup_inital_state(
ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(block_store.clone())), ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(block_store.clone())),
}; };
// misc vars for setting up the state
let genesis_time = 1_550_381_159;
let latest_eth1_data = Eth1Data {
deposit_root: zero_hash.clone(),
block_hash: zero_hash.clone(),
};
let initial_validator_deposits = vec![];
let spec = ChainSpec::foundation(); let spec = ChainSpec::foundation();
// create the state let state_builder = TestingBeaconStateBuilder::new(no_validators, &spec);
let mut state = BeaconState::genesis( let (state, _keypairs) = state_builder.build();
genesis_time,
initial_validator_deposits,
latest_eth1_data,
&spec,
)
.unwrap();
let default_validator = Validator {
pubkey: PublicKey::default(),
withdrawal_credentials: zero_hash,
activation_epoch: Epoch::from(0u64),
exit_epoch: spec.far_future_epoch,
withdrawable_epoch: spec.far_future_epoch,
initiated_exit: false,
slashed: false,
};
// activate the validators
for _ in 0..no_validators {
state.validator_registry.push(default_validator.clone());
state.validator_balances.push(32_000_000_000);
}
let state_root = state.canonical_root(); let state_root = state.canonical_root();
state_store state_store

View File

@ -53,7 +53,8 @@ impl BeaconStateBuilder {
/// Instantiate the validator registry from a YAML file. /// Instantiate the validator registry from a YAML file.
/// ///
/// This skips a lot of signing and verification, useful for fast test setups. /// This skips a lot of signing and verification, useful if signing and verification has been
/// completed previously.
/// ///
/// Spec v0.4.0 /// Spec v0.4.0
pub fn import_existing_validators( pub fn import_existing_validators(