diff --git a/beacon_node/client/src/client_config.rs b/beacon_node/client/src/client_config.rs index 942a907e08..4309b8a64a 100644 --- a/beacon_node/client/src/client_config.rs +++ b/beacon_node/client/src/client_config.rs @@ -1,5 +1,4 @@ use clap::ArgMatches; -use db::DBType; use fork_choice::ForkChoiceAlgorithm; use network::NetworkConfig; use slog::error; @@ -12,6 +11,12 @@ use types::multiaddr::ToMultiaddr; use types::Multiaddr; use types::{ChainSpec, EthSpec, LighthouseTestnetEthSpec}; +#[derive(Debug, Clone)] +pub enum DBType { + Memory, + Disk, +} + /// Stores the client configuration for this Lighthouse instance. #[derive(Debug, Clone)] pub struct ClientConfig { @@ -132,7 +137,7 @@ impl ClientConfig { } match args.value_of("db") { - Some("rocks") => config.db_type = DBType::RocksDB, + Some("disk") => config.db_type = DBType::Disk, Some("memory") => config.db_type = DBType::Memory, _ => unreachable!(), // clap prevents this. }; diff --git a/beacon_node/client/src/client_types.rs b/beacon_node/client/src/client_types.rs index fdca11caaa..c54028d28b 100644 --- a/beacon_node/client/src/client_types.rs +++ b/beacon_node/client/src/client_types.rs @@ -1,6 +1,6 @@ use crate::{ArcBeaconChain, ClientConfig}; use beacon_chain::{ - db::{ClientDB, DiskDB, MemoryDB}, + db::{DiskDB, MemoryDB, Store}, fork_choice::BitwiseLMDGhost, initialise, slot_clock::{SlotClock, SystemTimeSlotClock}, @@ -9,7 +9,7 @@ use fork_choice::ForkChoice; use types::{EthSpec, FewValidatorsEthSpec, FoundationEthSpec}; pub trait ClientTypes { - type DB: ClientDB + 'static; + type DB: Store + 'static; type SlotClock: SlotClock + 'static; type ForkChoice: ForkChoice + 'static; type EthSpec: EthSpec + 'static; @@ -24,7 +24,7 @@ pub struct StandardClientType; impl ClientTypes for StandardClientType { type DB = DiskDB; type SlotClock = SystemTimeSlotClock; - type ForkChoice = BitwiseLMDGhost; + type ForkChoice = BitwiseLMDGhost; type EthSpec = FoundationEthSpec; fn initialise_beacon_chain( @@ -39,12 +39,27 @@ pub struct MemoryDBTestingClientType; impl ClientTypes for MemoryDBTestingClientType { type DB = MemoryDB; type SlotClock = SystemTimeSlotClock; - type ForkChoice = BitwiseLMDGhost; + type ForkChoice = BitwiseLMDGhost; type EthSpec = FewValidatorsEthSpec; fn initialise_beacon_chain( config: &ClientConfig, ) -> ArcBeaconChain { - initialise::initialise_test_beacon_chain(&config.spec, None) + initialise::initialise_test_beacon_chain_with_memory_db(&config.spec, None) + } +} + +pub struct DiskDBTestingClientType; + +impl ClientTypes for DiskDBTestingClientType { + type DB = DiskDB; + type SlotClock = SystemTimeSlotClock; + type ForkChoice = BitwiseLMDGhost; + type EthSpec = FewValidatorsEthSpec; + + fn initialise_beacon_chain( + config: &ClientConfig, + ) -> ArcBeaconChain { + initialise::initialise_test_beacon_chain_with_disk_db(&config.spec, Some(&config.db_name)) } } diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index 5d7c221ef5..00478b4758 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -6,9 +6,9 @@ pub mod error; pub mod notifier; use beacon_chain::BeaconChain; -pub use client_config::ClientConfig; +pub use client_config::{ClientConfig, DBType}; pub use client_types::ClientTypes; -use db::ClientDB; +use db::Store; use exit_future::Signal; use fork_choice::ForkChoice; use futures::{future::Future, Stream}; @@ -146,7 +146,7 @@ impl Client { fn do_state_catchup(chain: &Arc>, log: &slog::Logger) where - T: ClientDB, + T: Store, U: SlotClock, F: ForkChoice, E: EthSpec, diff --git a/beacon_node/network/src/beacon_chain.rs b/beacon_node/network/src/beacon_chain.rs index a98aa73deb..f123e45406 100644 --- a/beacon_node/network/src/beacon_chain.rs +++ b/beacon_node/network/src/beacon_chain.rs @@ -1,6 +1,6 @@ use beacon_chain::BeaconChain as RawBeaconChain; use beacon_chain::{ - db::ClientDB, + db::Store, fork_choice::ForkChoice, parking_lot::RwLockReadGuard, slot_clock::SlotClock, @@ -66,7 +66,7 @@ pub trait BeaconChain: Send + Sync { impl BeaconChain for RawBeaconChain where - T: ClientDB + Sized, + T: Store, U: SlotClock, F: ForkChoice, E: EthSpec, diff --git a/beacon_node/rpc/src/beacon_chain.rs b/beacon_node/rpc/src/beacon_chain.rs index 7e75b32ced..9b6b05e9d0 100644 --- a/beacon_node/rpc/src/beacon_chain.rs +++ b/beacon_node/rpc/src/beacon_chain.rs @@ -1,6 +1,6 @@ use beacon_chain::BeaconChain as RawBeaconChain; use beacon_chain::{ - db::ClientDB, + db::Store, fork_choice::ForkChoice, parking_lot::{RwLockReadGuard, RwLockWriteGuard}, slot_clock::SlotClock, @@ -36,7 +36,7 @@ pub trait BeaconChain: Send + Sync { impl BeaconChain for RawBeaconChain where - T: ClientDB + Sized, + T: Store, U: SlotClock, F: ForkChoice, E: EthSpec, diff --git a/beacon_node/src/main.rs b/beacon_node/src/main.rs index a1df0b63be..ef21218827 100644 --- a/beacon_node/src/main.rs +++ b/beacon_node/src/main.rs @@ -74,7 +74,7 @@ fn main() { .value_name("DB") .help("Type of database to use.") .takes_value(true) - .possible_values(&["rocks", "memory"]) + .possible_values(&["disk", "memory"]) .default_value("memory"), ) .get_matches(); diff --git a/beacon_node/src/run.rs b/beacon_node/src/run.rs index 52dc3973b1..ec421fc6ed 100644 --- a/beacon_node/src/run.rs +++ b/beacon_node/src/run.rs @@ -1,7 +1,6 @@ use client::client_types::{DiskDBTestingClientType, MemoryDBTestingClientType}; -use client::error; +use client::{error, DBType}; use client::{notifier, Client, ClientConfig, ClientTypes}; -use db::DBType; use futures::sync::oneshot; use futures::Future; use slog::info; @@ -26,7 +25,7 @@ pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Resul let executor = runtime.executor(); match config.db_type { - DBType::RocksDB => { + DBType::Disk => { info!( log, "BeaconNode starting"; diff --git a/eth2/fork_choice/tests/tests.rs b/eth2/fork_choice/tests/tests.rs index 067d39da42..b4f4ede2ca 100644 --- a/eth2/fork_choice/tests/tests.rs +++ b/eth2/fork_choice/tests/tests.rs @@ -14,8 +14,8 @@ extern crate yaml_rust; pub use beacon_chain::BeaconChain; use bls::Signature; -use db::stores::{BeaconBlockStore, BeaconStateStore}; use db::MemoryDB; +use db::Store; // use env_logger::{Builder, Env}; use fork_choice::{ BitwiseLMDGhost, ForkChoice, ForkChoiceAlgorithm, LongestChain, OptimizedLMDGhost, SlowLMDGhost, @@ -106,7 +106,7 @@ fn test_yaml_vectors( // process the tests for test_case in test_cases { // setup a fresh test - let (mut fork_choice, block_store, state_root) = + let (mut fork_choice, store, state_root) = setup_inital_state(&fork_choice_algo, emulated_validators); // keep a hashmap of block_id's to block_hashes (random hashes to abstract block_id) @@ -149,9 +149,7 @@ fn test_yaml_vectors( }; // Store the block. - block_store - .put(&block_hash, &ssz_encode(&beacon_block)[..]) - .unwrap(); + store.put(&block_hash, &beacon_block).unwrap(); // run add block for fork choice if not genesis if parent_id != block_id { @@ -222,29 +220,26 @@ fn load_test_cases_from_yaml(file_path: &str) -> Vec { fn setup_inital_state( fork_choice_algo: &ForkChoiceAlgorithm, num_validators: usize, -) -> (Box, Arc>, Hash256) { - let db = Arc::new(MemoryDB::open()); - let block_store = Arc::new(BeaconBlockStore::new(db.clone())); - let state_store = Arc::new(BeaconStateStore::new(db.clone())); +) -> (Box, Arc, Hash256) { + let store = Arc::new(MemoryDB::open()); // the fork choice instantiation let fork_choice: Box = match fork_choice_algo { ForkChoiceAlgorithm::OptimizedLMDGhost => { let f: OptimizedLMDGhost = - OptimizedLMDGhost::new(block_store.clone(), state_store.clone()); + OptimizedLMDGhost::new(store.clone()); Box::new(f) } ForkChoiceAlgorithm::BitwiseLMDGhost => { let f: BitwiseLMDGhost = - BitwiseLMDGhost::new(block_store.clone(), state_store.clone()); + BitwiseLMDGhost::new(store.clone()); Box::new(f) } ForkChoiceAlgorithm::SlowLMDGhost => { - let f: SlowLMDGhost = - SlowLMDGhost::new(block_store.clone(), state_store.clone()); + let f: SlowLMDGhost = SlowLMDGhost::new(store.clone()); Box::new(f) } - ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(block_store.clone())), + ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(store.clone())), }; let spec = FoundationEthSpec::spec(); @@ -255,12 +250,10 @@ fn setup_inital_state( let (state, _keypairs) = state_builder.build(); let state_root = state.canonical_root(); - state_store - .put(&state_root, &ssz_encode(&state)[..]) - .unwrap(); + store.put(&state_root, &state).unwrap(); // return initialised vars - (fork_choice, block_store, state_root) + (fork_choice, store, state_root) } // convert a block_id into a Hash256 -- assume input is hex encoded;