From 4c0c93f0c97cfee7cdeddb5f306611fc5bbec056 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 9 May 2019 09:40:32 +1000 Subject: [PATCH] Update `beacon_node` to work w/ `BeaconStateTypes` --- beacon_node/client/src/client_config.rs | 4 ++-- beacon_node/client/src/client_types.rs | 14 +++++++++----- beacon_node/client/src/lib.rs | 8 +++++--- .../src/beacon_state/beacon_state_types.rs | 18 ++++++++++++++++++ eth2/utils/fixed_len_vec/src/lib.rs | 1 - 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/beacon_node/client/src/client_config.rs b/beacon_node/client/src/client_config.rs index 407171ff5..74ef5f2e5 100644 --- a/beacon_node/client/src/client_config.rs +++ b/beacon_node/client/src/client_config.rs @@ -9,8 +9,8 @@ use std::net::{IpAddr, Ipv4Addr}; use std::path::PathBuf; use types::multiaddr::Protocol; use types::multiaddr::ToMultiaddr; -use types::ChainSpec; use types::Multiaddr; +use types::{BeaconStateTypes, ChainSpec, LighthouseTestnetStateTypes}; /// Stores the client configuration for this Lighthouse instance. #[derive(Debug, Clone)] @@ -35,7 +35,7 @@ impl Default for ClientConfig { fs::create_dir_all(&data_dir) .unwrap_or_else(|_| panic!("Unable to create {:?}", &data_dir)); - let default_spec = ChainSpec::lighthouse_testnet(); + let default_spec = LighthouseTestnetStateTypes::spec(); let default_net_conf = NetworkConfig::new(default_spec.boot_nodes.clone()); Self { diff --git a/beacon_node/client/src/client_types.rs b/beacon_node/client/src/client_types.rs index f5abc77ce..b934b508e 100644 --- a/beacon_node/client/src/client_types.rs +++ b/beacon_node/client/src/client_types.rs @@ -7,6 +7,7 @@ use beacon_chain::{ BeaconChain, }; use fork_choice::ForkChoice; +use types::{BeaconStateTypes, FewValidatorsStateTypes, FoundationStateTypes}; use std::sync::Arc; @@ -14,10 +15,11 @@ pub trait ClientTypes { type DB: ClientDB + 'static; type SlotClock: SlotClock + 'static; type ForkChoice: ForkChoice + 'static; + type BeaconStateTypes: BeaconStateTypes + 'static; fn initialise_beacon_chain( config: &ClientConfig, - ) -> Arc>; + ) -> Arc>; } pub struct StandardClientType; @@ -25,11 +27,12 @@ pub struct StandardClientType; impl ClientTypes for StandardClientType { type DB = DiskDB; type SlotClock = SystemTimeSlotClock; - type ForkChoice = BitwiseLMDGhost; + type ForkChoice = BitwiseLMDGhost; + type BeaconStateTypes = FoundationStateTypes; fn initialise_beacon_chain( config: &ClientConfig, - ) -> Arc> { + ) -> Arc> { initialise::initialise_beacon_chain(&config.spec, Some(&config.db_name)) } } @@ -39,11 +42,12 @@ pub struct TestingClientType; impl ClientTypes for TestingClientType { type DB = MemoryDB; type SlotClock = SystemTimeSlotClock; - type ForkChoice = BitwiseLMDGhost; + type ForkChoice = BitwiseLMDGhost; + type BeaconStateTypes = FewValidatorsStateTypes; fn initialise_beacon_chain( config: &ClientConfig, - ) -> Arc> { + ) -> Arc> { initialise::initialise_test_beacon_chain(&config.spec, None) } } diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index 6a21493b1..466256735 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -20,6 +20,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use tokio::runtime::TaskExecutor; use tokio::timer::Interval; +use types::BeaconStateTypes; /// Main beacon node client service. This provides the connection and initialisation of the clients /// sub-services in multiple threads. @@ -27,9 +28,9 @@ pub struct Client { /// Configuration for the lighthouse client. _config: ClientConfig, /// The beacon chain for the running client. - _beacon_chain: Arc>, + _beacon_chain: Arc>, /// Reference to the network service. - pub network: Arc, + pub network: Arc>, /// Signal to terminate the RPC server. pub rpc_exit_signal: Option, /// Signal to terminate the slot timer. @@ -141,11 +142,12 @@ impl Client { } } -fn do_state_catchup(chain: &Arc>, log: &slog::Logger) +fn do_state_catchup(chain: &Arc>, log: &slog::Logger) where T: ClientDB, U: SlotClock, F: ForkChoice, + B: BeaconStateTypes, { if let Some(genesis_height) = chain.slots_since_genesis() { let result = chain.catchup_state(); diff --git a/eth2/types/src/beacon_state/beacon_state_types.rs b/eth2/types/src/beacon_state/beacon_state_types.rs index 1a45088d1..f66591669 100644 --- a/eth2/types/src/beacon_state/beacon_state_types.rs +++ b/eth2/types/src/beacon_state/beacon_state_types.rs @@ -12,6 +12,7 @@ pub trait BeaconStateTypes: 'static + Default + Sync + Send + Clone + Debug + Pa fn spec() -> ChainSpec; } +/// Ethereum Foundation specifications. #[derive(Clone, PartialEq, Debug, Default)] pub struct FoundationStateTypes; @@ -45,3 +46,20 @@ impl BeaconStateTypes for FewValidatorsStateTypes { } pub type FewValidatorsBeaconState = BeaconState; + +#[derive(Clone, PartialEq, Debug, Default)] +pub struct LighthouseTestnetStateTypes; + +impl BeaconStateTypes for LighthouseTestnetStateTypes { + type ShardCount = U8; + type SlotsPerHistoricalRoot = U8192; + type LatestRandaoMixesLength = U8192; + type LatestActiveIndexRootsLength = U8192; + type LatestSlashedExitLength = U8192; + + fn spec() -> ChainSpec { + ChainSpec::lighthouse_testnet() + } +} + +pub type LighthouseTestnetBeaconState = BeaconState; diff --git a/eth2/utils/fixed_len_vec/src/lib.rs b/eth2/utils/fixed_len_vec/src/lib.rs index d2d4ec57c..0d811566b 100644 --- a/eth2/utils/fixed_len_vec/src/lib.rs +++ b/eth2/utils/fixed_len_vec/src/lib.rs @@ -29,7 +29,6 @@ impl FixedLenVec { impl From> for FixedLenVec { fn from(mut vec: Vec) -> Self { - dbg!(Self::capacity()); vec.resize_with(Self::capacity(), Default::default); Self {