Remove dupe info between ChainSpec and EthSpec

This commit is contained in:
Paul Hauner
2019-06-08 07:57:25 -04:00
parent f69d9093a3
commit e74d49fc8a
57 changed files with 299 additions and 252 deletions

View File

@@ -10,7 +10,8 @@ use slot_clock::SlotClock;
use std::sync::Arc;
use tree_hash::TreeHash;
use types::{
test_utils::TestingBeaconStateBuilder, BeaconBlock, EthSpec, Hash256, LighthouseTestnetEthSpec,
test_utils::TestingBeaconStateBuilder, BeaconBlock, ChainSpec, EthSpec, Hash256,
LighthouseTestnetEthSpec,
};
/// The number initial validators when starting the `LighthouseTestnet`.
@@ -18,8 +19,12 @@ const TESTNET_VALIDATOR_COUNT: usize = 16;
/// Provides a new, initialized `BeaconChain`
pub trait InitialiseBeaconChain<T: BeaconChainTypes> {
fn initialise_beacon_chain(store: Arc<T::Store>, log: Logger) -> BeaconChain<T> {
maybe_load_from_store_for_testnet::<_, T::Store, T::EthSpec>(store, log)
fn initialise_beacon_chain(
store: Arc<T::Store>,
spec: ChainSpec,
log: Logger,
) -> BeaconChain<T> {
maybe_load_from_store_for_testnet::<_, T::Store, T::EthSpec>(store, spec, log)
}
}
@@ -48,13 +53,14 @@ impl<T: BeaconChainTypes> InitialiseBeaconChain<T> for TestnetDiskBeaconChainTyp
/// Loads a `BeaconChain` from `store`, if it exists. Otherwise, create a new chain from genesis.
fn maybe_load_from_store_for_testnet<T, U: Store, V: EthSpec>(
store: Arc<U>,
spec: ChainSpec,
log: Logger,
) -> BeaconChain<T>
where
T: BeaconChainTypes<Store = U>,
T::ForkChoice: ForkChoice<U>,
{
if let Ok(Some(beacon_chain)) = BeaconChain::from_store(store.clone()) {
if let Ok(Some(beacon_chain)) = BeaconChain::from_store(store.clone(), spec.clone()) {
info!(
log,
"Loaded BeaconChain from store";
@@ -65,8 +71,6 @@ where
beacon_chain
} else {
info!(log, "Initializing new BeaconChain from genesis");
let spec = T::EthSpec::spec();
let state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(
TESTNET_VALIDATOR_COUNT,
&spec,
@@ -92,7 +96,7 @@ where
slot_clock,
genesis_state,
genesis_block,
spec.clone(),
spec,
fork_choice,
)
.expect("Terminate if beacon chain generation fails")

View File

@@ -4,24 +4,26 @@ use network::NetworkConfig;
use serde_derive::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use types::ChainSpec;
/// The core configuration of a Lighthouse beacon node.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClientConfig {
pub data_dir: String,
pub spec: String,
pub spec_constants: String,
pub db_type: String,
db_name: String,
pub network: network::NetworkConfig,
pub rpc: rpc::RPCConfig,
pub http: HttpServerConfig, //pub ipc_conf:
pub spec: ChainSpec,
}
impl Default for ClientConfig {
fn default() -> Self {
Self {
data_dir: ".lighthouse".to_string(),
spec: "testnet".to_string(),
spec_constants: "testnet".to_string(),
db_type: "disk".to_string(),
db_name: "chain_db".to_string(),
// Note: there are no default bootnodes specified.
@@ -29,6 +31,7 @@ impl Default for ClientConfig {
network: NetworkConfig::new(vec![]),
rpc: rpc::RPCConfig::default(),
http: HttpServerConfig::default(),
spec: ChainSpec::lighthouse_testnet(8),
}
}
}

View File

@@ -17,7 +17,6 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::runtime::TaskExecutor;
use tokio::timer::Interval;
use types::EthSpec;
pub use beacon_chain::BeaconChainTypes;
pub use beacon_chain_types::InitialiseBeaconChain;
@@ -58,10 +57,14 @@ where
) -> error::Result<Self> {
let metrics_registry = Registry::new();
let store = Arc::new(store);
let spec = T::EthSpec::spec();
let seconds_per_slot = config.spec.seconds_per_slot;
// Load a `BeaconChain` from the store, or create a new one if it does not exist.
let beacon_chain = Arc::new(T::initialise_beacon_chain(store, log.clone()));
let beacon_chain = Arc::new(T::initialise_beacon_chain(
store,
config.spec.clone(),
log.clone(),
));
// Registry all beacon chain metrics with the global registry.
beacon_chain
.metrics
@@ -143,7 +146,7 @@ where
// set up the validator work interval - start at next slot and proceed every slot
let interval = {
// Set the interval to start at the next slot, and every slot after
let slot_duration = Duration::from_secs(spec.seconds_per_slot);
let slot_duration = Duration::from_secs(seconds_per_slot);
//TODO: Handle checked add correctly
Interval::new(Instant::now() + duration_to_next_slot, slot_duration)
};