More project-wide fixes for new DB

This commit is contained in:
Paul Hauner
2019-05-21 17:45:35 +10:00
parent 058829b64d
commit b62f4477e1
8 changed files with 48 additions and 36 deletions

View File

@@ -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.
};

View File

@@ -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<DiskDB, Self::EthSpec>;
type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>;
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<MemoryDB, Self::EthSpec>;
type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>;
type EthSpec = FewValidatorsEthSpec;
fn initialise_beacon_chain(
config: &ClientConfig,
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::EthSpec> {
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<Self::DB, Self::EthSpec>;
type EthSpec = FewValidatorsEthSpec;
fn initialise_beacon_chain(
config: &ClientConfig,
) -> ArcBeaconChain<Self::DB, Self::SlotClock, Self::ForkChoice, Self::EthSpec> {
initialise::initialise_test_beacon_chain_with_disk_db(&config.spec, Some(&config.db_name))
}
}

View File

@@ -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<TClientType: ClientTypes> Client<TClientType> {
fn do_state_catchup<T, U, F, E>(chain: &Arc<BeaconChain<T, U, F, E>>, log: &slog::Logger)
where
T: ClientDB,
T: Store,
U: SlotClock,
F: ForkChoice,
E: EthSpec,