Rename db crate to store

This commit is contained in:
Paul Hauner 2019-05-21 18:20:23 +10:00
parent 29427cf0e6
commit 3bcf5ba706
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
30 changed files with 76 additions and 90 deletions

View File

@ -22,7 +22,7 @@ members = [
"eth2/utils/fisher_yates_shuffle", "eth2/utils/fisher_yates_shuffle",
"eth2/utils/test_random_derive", "eth2/utils/test_random_derive",
"beacon_node", "beacon_node",
"beacon_node/db", "beacon_node/store",
"beacon_node/client", "beacon_node/client",
"beacon_node/network", "beacon_node/network",
"beacon_node/eth2-libp2p", "beacon_node/eth2-libp2p",

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
types = { path = "../eth2/types" } types = { path = "../eth2/types" }
db = { path = "./db" } store = { path = "./store" }
client = { path = "client" } client = { path = "client" }
version = { path = "version" } version = { path = "version" }
clap = "2.32.0" clap = "2.32.0"

View File

@ -7,7 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
bls = { path = "../../eth2/utils/bls" } bls = { path = "../../eth2/utils/bls" }
boolean-bitfield = { path = "../../eth2/utils/boolean-bitfield" } boolean-bitfield = { path = "../../eth2/utils/boolean-bitfield" }
db = { path = "../db" } store = { path = "../store" }
failure = "0.1" failure = "0.1"
failure_derive = "0.1" failure_derive = "0.1"
hashing = { path = "../../eth2/utils/hashing" } hashing = { path = "../../eth2/utils/hashing" }

View File

@ -1,6 +1,5 @@
use crate::checkpoint::CheckPoint; use crate::checkpoint::CheckPoint;
use crate::errors::{BeaconChainError as Error, BlockProductionError}; use crate::errors::{BeaconChainError as Error, BlockProductionError};
use db::{Error as DBError, Store};
use fork_choice::{ForkChoice, ForkChoiceError}; use fork_choice::{ForkChoice, ForkChoiceError};
use log::{debug, trace}; use log::{debug, trace};
use operation_pool::DepositInsertStatus; use operation_pool::DepositInsertStatus;
@ -16,6 +15,7 @@ use state_processing::{
per_slot_processing, BlockProcessingError, SlotProcessingError, per_slot_processing, BlockProcessingError, SlotProcessingError,
}; };
use std::sync::Arc; use std::sync::Arc;
use store::{Error as DBError, Store};
use types::*; use types::*;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View File

@ -20,7 +20,7 @@ pub enum BeaconChainError {
UnableToReadSlot, UnableToReadSlot,
BeaconStateError(BeaconStateError), BeaconStateError(BeaconStateError),
DBInconsistent(String), DBInconsistent(String),
DBError(db::Error), DBError(store::Error),
ForkChoiceError(ForkChoiceError), ForkChoiceError(ForkChoiceError),
MissingBeaconBlock(Hash256), MissingBeaconBlock(Hash256),
MissingBeaconState(Hash256), MissingBeaconState(Hash256),

View File

@ -3,11 +3,11 @@
// testnet. These are examples. Also. there is code duplication which can/should be cleaned up. // testnet. These are examples. Also. there is code duplication which can/should be cleaned up.
use crate::BeaconChain; use crate::BeaconChain;
use db::{DiskDB, MemoryDB};
use fork_choice::BitwiseLMDGhost; use fork_choice::BitwiseLMDGhost;
use slot_clock::SystemTimeSlotClock; use slot_clock::SystemTimeSlotClock;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
use store::{DiskStore, MemoryStore};
use tree_hash::TreeHash; use tree_hash::TreeHash;
use types::test_utils::TestingBeaconStateBuilder; use types::test_utils::TestingBeaconStateBuilder;
use types::{BeaconBlock, ChainSpec, FewValidatorsEthSpec, FoundationEthSpec, Hash256}; use types::{BeaconBlock, ChainSpec, FewValidatorsEthSpec, FoundationEthSpec, Hash256};
@ -19,14 +19,14 @@ pub fn initialise_beacon_chain(
db_name: Option<&PathBuf>, db_name: Option<&PathBuf>,
) -> Arc< ) -> Arc<
BeaconChain< BeaconChain<
DiskDB, DiskStore,
SystemTimeSlotClock, SystemTimeSlotClock,
BitwiseLMDGhost<DiskDB, FoundationEthSpec>, BitwiseLMDGhost<DiskStore, FoundationEthSpec>,
FoundationEthSpec, FoundationEthSpec,
>, >,
> { > {
let path = db_name.expect("db_name cannot be None."); let path = db_name.expect("db_name cannot be None.");
let store = DiskDB::open(path).expect("Unable to open DB."); let store = DiskStore::open(path).expect("Unable to open DB.");
let store = Arc::new(store); let store = Arc::new(store);
let state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(8, &spec); let state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(8, &spec);
@ -66,13 +66,13 @@ pub fn initialise_test_beacon_chain_with_memory_db(
_db_name: Option<&PathBuf>, _db_name: Option<&PathBuf>,
) -> Arc< ) -> Arc<
BeaconChain< BeaconChain<
MemoryDB, MemoryStore,
SystemTimeSlotClock, SystemTimeSlotClock,
BitwiseLMDGhost<MemoryDB, FewValidatorsEthSpec>, BitwiseLMDGhost<MemoryStore, FewValidatorsEthSpec>,
FewValidatorsEthSpec, FewValidatorsEthSpec,
>, >,
> { > {
let store = Arc::new(MemoryDB::open()); let store = Arc::new(MemoryStore::open());
let state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(8, spec); let state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(8, spec);
let (genesis_state, _keypairs) = state_builder.build(); let (genesis_state, _keypairs) = state_builder.build();
@ -111,14 +111,14 @@ pub fn initialise_test_beacon_chain_with_disk_db(
db_name: Option<&PathBuf>, db_name: Option<&PathBuf>,
) -> Arc< ) -> Arc<
BeaconChain< BeaconChain<
DiskDB, DiskStore,
SystemTimeSlotClock, SystemTimeSlotClock,
BitwiseLMDGhost<DiskDB, FewValidatorsEthSpec>, BitwiseLMDGhost<DiskStore, FewValidatorsEthSpec>,
FewValidatorsEthSpec, FewValidatorsEthSpec,
>, >,
> { > {
let path = db_name.expect("db_name cannot be None."); let path = db_name.expect("db_name cannot be None.");
let store = DiskDB::open(path).expect("Unable to open DB."); let store = DiskStore::open(path).expect("Unable to open DB.");
let store = Arc::new(store); let store = Arc::new(store);
let state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(8, spec); let state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(8, spec);

View File

@ -7,7 +7,6 @@ pub mod test_utils;
pub use self::beacon_chain::{BeaconChain, BlockProcessingOutcome, InvalidBlock, ValidBlock}; pub use self::beacon_chain::{BeaconChain, BlockProcessingOutcome, InvalidBlock, ValidBlock};
pub use self::checkpoint::CheckPoint; pub use self::checkpoint::CheckPoint;
pub use self::errors::{BeaconChainError, BlockProductionError}; pub use self::errors::{BeaconChainError, BlockProductionError};
pub use db;
pub use fork_choice; pub use fork_choice;
pub use parking_lot; pub use parking_lot;
pub use slot_clock; pub use slot_clock;
@ -15,4 +14,5 @@ pub use state_processing::per_block_processing::errors::{
AttestationValidationError, AttesterSlashingValidationError, DepositValidationError, AttestationValidationError, AttesterSlashingValidationError, DepositValidationError,
ExitValidationError, ProposerSlashingValidationError, TransferValidationError, ExitValidationError, ProposerSlashingValidationError, TransferValidationError,
}; };
pub use store;
pub use types; pub use types;

View File

@ -1,14 +1,18 @@
pub use crate::{BeaconChain, BeaconChainError, CheckPoint}; pub use crate::{BeaconChain, BeaconChainError, CheckPoint};
use db::MemoryDB;
use fork_choice::BitwiseLMDGhost; use fork_choice::BitwiseLMDGhost;
use slot_clock::TestingSlotClock; use slot_clock::TestingSlotClock;
use std::sync::Arc; use std::sync::Arc;
use store::MemoryStore;
use tree_hash::TreeHash; use tree_hash::TreeHash;
use types::*; use types::*;
use types::{test_utils::TestingBeaconStateBuilder, EthSpec, FewValidatorsEthSpec}; use types::{test_utils::TestingBeaconStateBuilder, EthSpec, FewValidatorsEthSpec};
type TestingBeaconChain<E> = type TestingBeaconChain<E> = BeaconChain<
BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB, FewValidatorsEthSpec>, E>; MemoryStore,
TestingSlotClock,
BitwiseLMDGhost<MemoryStore, FewValidatorsEthSpec>,
E,
>;
pub struct TestingBeaconChainBuilder<E: EthSpec> { pub struct TestingBeaconChainBuilder<E: EthSpec> {
state_builder: TestingBeaconStateBuilder<E>, state_builder: TestingBeaconStateBuilder<E>,
@ -16,7 +20,7 @@ pub struct TestingBeaconChainBuilder<E: EthSpec> {
impl<E: EthSpec> TestingBeaconChainBuilder<E> { impl<E: EthSpec> TestingBeaconChainBuilder<E> {
pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain<E> { pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain<E> {
let store = Arc::new(MemoryDB::open()); let store = Arc::new(MemoryStore::open());
let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64()); let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64());
let fork_choice = BitwiseLMDGhost::new(store.clone()); let fork_choice = BitwiseLMDGhost::new(store.clone());

View File

@ -7,7 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
beacon_chain = { path = "../beacon_chain" } beacon_chain = { path = "../beacon_chain" }
network = { path = "../network" } network = { path = "../network" }
db = { path = "../db" } store = { path = "../store" }
rpc = { path = "../rpc" } rpc = { path = "../rpc" }
fork_choice = { path = "../../eth2/fork_choice" } fork_choice = { path = "../../eth2/fork_choice" }
types = { path = "../../eth2/types" } types = { path = "../../eth2/types" }

View File

@ -1,9 +1,9 @@
use crate::{ArcBeaconChain, ClientConfig}; use crate::{ArcBeaconChain, ClientConfig};
use beacon_chain::{ use beacon_chain::{
db::{DiskDB, MemoryDB, Store},
fork_choice::BitwiseLMDGhost, fork_choice::BitwiseLMDGhost,
initialise, initialise,
slot_clock::{SlotClock, SystemTimeSlotClock}, slot_clock::{SlotClock, SystemTimeSlotClock},
store::{DiskStore, MemoryStore, Store},
}; };
use fork_choice::ForkChoice; use fork_choice::ForkChoice;
use types::{EthSpec, FewValidatorsEthSpec, FoundationEthSpec}; use types::{EthSpec, FewValidatorsEthSpec, FoundationEthSpec};
@ -22,7 +22,7 @@ pub trait ClientTypes {
pub struct StandardClientType; pub struct StandardClientType;
impl ClientTypes for StandardClientType { impl ClientTypes for StandardClientType {
type DB = DiskDB; type DB = DiskStore;
type SlotClock = SystemTimeSlotClock; type SlotClock = SystemTimeSlotClock;
type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>; type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>;
type EthSpec = FoundationEthSpec; type EthSpec = FoundationEthSpec;
@ -34,10 +34,10 @@ impl ClientTypes for StandardClientType {
} }
} }
pub struct MemoryDBTestingClientType; pub struct MemoryStoreTestingClientType;
impl ClientTypes for MemoryDBTestingClientType { impl ClientTypes for MemoryStoreTestingClientType {
type DB = MemoryDB; type DB = MemoryStore;
type SlotClock = SystemTimeSlotClock; type SlotClock = SystemTimeSlotClock;
type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>; type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>;
type EthSpec = FewValidatorsEthSpec; type EthSpec = FewValidatorsEthSpec;
@ -49,10 +49,10 @@ impl ClientTypes for MemoryDBTestingClientType {
} }
} }
pub struct DiskDBTestingClientType; pub struct DiskStoreTestingClientType;
impl ClientTypes for DiskDBTestingClientType { impl ClientTypes for DiskStoreTestingClientType {
type DB = DiskDB; type DB = DiskStore;
type SlotClock = SystemTimeSlotClock; type SlotClock = SystemTimeSlotClock;
type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>; type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>;
type EthSpec = FewValidatorsEthSpec; type EthSpec = FewValidatorsEthSpec;

View File

@ -8,7 +8,6 @@ pub mod notifier;
use beacon_chain::BeaconChain; use beacon_chain::BeaconChain;
pub use client_config::{ClientConfig, DBType}; pub use client_config::{ClientConfig, DBType};
pub use client_types::ClientTypes; pub use client_types::ClientTypes;
use db::Store;
use exit_future::Signal; use exit_future::Signal;
use fork_choice::ForkChoice; use fork_choice::ForkChoice;
use futures::{future::Future, Stream}; use futures::{future::Future, Stream};
@ -18,6 +17,7 @@ use slot_clock::SlotClock;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use store::Store;
use tokio::runtime::TaskExecutor; use tokio::runtime::TaskExecutor;
use tokio::timer::Interval; use tokio::timer::Interval;
use types::EthSpec; use types::EthSpec;

View File

@ -1,9 +1,9 @@
use beacon_chain::BeaconChain as RawBeaconChain; use beacon_chain::BeaconChain as RawBeaconChain;
use beacon_chain::{ use beacon_chain::{
db::Store,
fork_choice::ForkChoice, fork_choice::ForkChoice,
parking_lot::RwLockReadGuard, parking_lot::RwLockReadGuard,
slot_clock::SlotClock, slot_clock::SlotClock,
store::Store,
types::{BeaconState, ChainSpec}, types::{BeaconState, ChainSpec},
AttestationValidationError, CheckPoint, AttestationValidationError, CheckPoint,
}; };

View File

@ -17,7 +17,7 @@ protos = { path = "../../protos" }
grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] } grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] }
protobuf = "2.0.2" protobuf = "2.0.2"
clap = "2.32.0" clap = "2.32.0"
db = { path = "../db" } store = { path = "../store" }
dirs = "1.0.3" dirs = "1.0.3"
futures = "0.1.23" futures = "0.1.23"
slog = "^2.2.3" slog = "^2.2.3"

View File

@ -1,9 +1,9 @@
use beacon_chain::BeaconChain as RawBeaconChain; use beacon_chain::BeaconChain as RawBeaconChain;
use beacon_chain::{ use beacon_chain::{
db::Store,
fork_choice::ForkChoice, fork_choice::ForkChoice,
parking_lot::{RwLockReadGuard, RwLockWriteGuard}, parking_lot::{RwLockReadGuard, RwLockWriteGuard},
slot_clock::SlotClock, slot_clock::SlotClock,
store::Store,
types::{BeaconState, ChainSpec, Signature}, types::{BeaconState, ChainSpec, Signature},
AttestationValidationError, BlockProductionError, AttestationValidationError, BlockProductionError,
}; };

View File

@ -1,4 +1,4 @@
use client::client_types::{DiskDBTestingClientType, MemoryDBTestingClientType}; use client::client_types::{DiskStoreTestingClientType, MemoryStoreTestingClientType};
use client::{error, DBType}; use client::{error, DBType};
use client::{notifier, Client, ClientConfig, ClientTypes}; use client::{notifier, Client, ClientConfig, ClientTypes};
use futures::sync::oneshot; use futures::sync::oneshot;
@ -29,9 +29,9 @@ pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Resul
info!( info!(
log, log,
"BeaconNode starting"; "BeaconNode starting";
"type" => "DiskDBTestingClientType" "type" => "DiskStoreTestingClientType"
); );
let client: Client<DiskDBTestingClientType> = let client: Client<DiskStoreTestingClientType> =
Client::new(config, log.clone(), &executor)?; Client::new(config, log.clone(), &executor)?;
run(client, executor, runtime, log) run(client, executor, runtime, log)
@ -40,9 +40,9 @@ pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Resul
info!( info!(
log, log,
"BeaconNode starting"; "BeaconNode starting";
"type" => "MemoryDBTestingClientType" "type" => "MemoryStoreTestingClientType"
); );
let client: Client<MemoryDBTestingClientType> = let client: Client<MemoryStoreTestingClientType> =
Client::new(config, log.clone(), &executor)?; Client::new(config, log.clone(), &executor)?;
run(client, executor, runtime, log) run(client, executor, runtime, log)

View File

@ -1,5 +1,5 @@
[package] [package]
name = "db" name = "store"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018" edition = "2018"

View File

@ -121,7 +121,7 @@ mod tests {
#[test] #[test]
fn chain_without_skips() { fn chain_without_skips() {
let n: usize = 10; let n: usize = 10;
let store = MemoryDB::open(); let store = MemoryStore::open();
let spec = FewValidatorsEthSpec::spec(); let spec = FewValidatorsEthSpec::spec();
let slots: Vec<usize> = (0..n).collect(); let slots: Vec<usize> = (0..n).collect();
@ -145,7 +145,7 @@ mod tests {
#[test] #[test]
fn chain_with_skips() { fn chain_with_skips() {
let store = MemoryDB::open(); let store = MemoryStore::open();
let spec = FewValidatorsEthSpec::spec(); let spec = FewValidatorsEthSpec::spec();
let slots = vec![0, 1, 2, 5]; let slots = vec![0, 1, 2, 5];

View File

@ -10,11 +10,11 @@ use std::path::Path;
/// A on-disk database which implements the ClientDB trait. /// A on-disk database which implements the ClientDB trait.
/// ///
/// This implementation uses RocksDB with default options. /// This implementation uses RocksDB with default options.
pub struct DiskDB { pub struct DiskStore {
db: DB, db: DB,
} }
impl DiskDB { impl DiskStore {
/// Open the RocksDB database, optionally supplying columns if required. /// Open the RocksDB database, optionally supplying columns if required.
/// ///
/// The RocksDB database will be contained in a directory titled /// The RocksDB database will be contained in a directory titled
@ -71,7 +71,7 @@ impl From<RocksError> for DBError {
} }
} }
impl ClientDB for DiskDB { impl ClientDB for DiskStore {
/// Get the value for some key on some column. /// Get the value for some key on some column.
/// ///
/// Corresponds to the `get_cf()` method on the RocksDB API. /// Corresponds to the `get_cf()` method on the RocksDB API.
@ -154,7 +154,7 @@ mod tests {
let col_name: &str = "TestColumn"; let col_name: &str = "TestColumn";
let column_families = vec![col_name]; let column_families = vec![col_name];
let mut db = DiskDB::open(&path, None); let mut db = DiskStore::open(&path, None);
for cf in column_families { for cf in column_families {
db.create_col(&cf).unwrap(); db.create_col(&cf).unwrap();

View File

@ -5,8 +5,8 @@ mod impls;
mod leveldb_store; mod leveldb_store;
mod memory_db; mod memory_db;
pub use self::leveldb_store::LevelDB as DiskDB; pub use self::leveldb_store::LevelDB as DiskStore;
pub use self::memory_db::MemoryDB; pub use self::memory_db::MemoryStore;
pub use errors::Error; pub use errors::Error;
pub use types::*; pub use types::*;
pub type DBValue = Vec<u8>; pub type DBValue = Vec<u8>;
@ -154,21 +154,21 @@ mod tests {
fn diskdb() { fn diskdb() {
let dir = tempdir().unwrap(); let dir = tempdir().unwrap();
let path = dir.path(); let path = dir.path();
let store = DiskDB::open(&path).unwrap(); let store = DiskStore::open(&path).unwrap();
test_impl(store); test_impl(store);
} }
#[test] #[test]
fn memorydb() { fn memorydb() {
let store = MemoryDB::open(); let store = MemoryStore::open();
test_impl(store); test_impl(store);
} }
#[test] #[test]
fn exists() { fn exists() {
let store = MemoryDB::open(); let store = MemoryStore::open();
let key = Hash256::random(); let key = Hash256::random();
let item = StorableThing { a: 1, b: 42 }; let item = StorableThing { a: 1, b: 42 };

View File

@ -4,11 +4,11 @@ use std::collections::HashMap;
type DBHashMap = HashMap<Vec<u8>, Vec<u8>>; type DBHashMap = HashMap<Vec<u8>, Vec<u8>>;
pub struct MemoryDB { pub struct MemoryStore {
db: RwLock<DBHashMap>, db: RwLock<DBHashMap>,
} }
impl MemoryDB { impl MemoryStore {
pub fn open() -> Self { pub fn open() -> Self {
Self { Self {
db: RwLock::new(HashMap::new()), db: RwLock::new(HashMap::new()),
@ -22,10 +22,10 @@ impl MemoryDB {
} }
} }
impl Store for MemoryDB { impl Store for MemoryStore {
/// Get the value of some key from the database. Returns `None` if the key does not exist. /// Get the value of some key from the database. Returns `None` if the key does not exist.
fn get_bytes(&self, col: &str, key: &[u8]) -> Result<Option<DBValue>, Error> { fn get_bytes(&self, col: &str, key: &[u8]) -> Result<Option<DBValue>, Error> {
let column_key = MemoryDB::get_key_for_col(col, key); let column_key = MemoryStore::get_key_for_col(col, key);
Ok(self Ok(self
.db .db
@ -36,7 +36,7 @@ impl Store for MemoryDB {
/// Puts a key in the database. /// Puts a key in the database.
fn put_bytes(&self, col: &str, key: &[u8], val: &[u8]) -> Result<(), Error> { fn put_bytes(&self, col: &str, key: &[u8], val: &[u8]) -> Result<(), Error> {
let column_key = MemoryDB::get_key_for_col(col, key); let column_key = MemoryStore::get_key_for_col(col, key);
self.db.write().insert(column_key, val.to_vec()); self.db.write().insert(column_key, val.to_vec());
@ -45,14 +45,14 @@ impl Store for MemoryDB {
/// Return true if some key exists in some column. /// Return true if some key exists in some column.
fn key_exists(&self, col: &str, key: &[u8]) -> Result<bool, Error> { fn key_exists(&self, col: &str, key: &[u8]) -> Result<bool, Error> {
let column_key = MemoryDB::get_key_for_col(col, key); let column_key = MemoryStore::get_key_for_col(col, key);
Ok(self.db.read().contains_key(&column_key)) Ok(self.db.read().contains_key(&column_key))
} }
/// Delete some key from the database. /// Delete some key from the database.
fn key_delete(&self, col: &str, key: &[u8]) -> Result<(), Error> { fn key_delete(&self, col: &str, key: &[u8]) -> Result<(), Error> {
let column_key = MemoryDB::get_key_for_col(col, key); let column_key = MemoryStore::get_key_for_col(col, key);
self.db.write().remove(&column_key); self.db.write().remove(&column_key);

View File

@ -5,7 +5,7 @@ authors = ["Age Manning <Age@AgeManning.com>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
db = { path = "../../beacon_node/db" } store = { path = "../../beacon_node/store" }
ssz = { path = "../utils/ssz" } ssz = { path = "../utils/ssz" }
types = { path = "../types" } types = { path = "../types" }
log = "0.4.6" log = "0.4.6"

View File

@ -1,13 +1,11 @@
//! The optimised bitwise LMD-GHOST fork choice rule. //! The optimised bitwise LMD-GHOST fork choice rule.
extern crate bit_vec;
use crate::{ForkChoice, ForkChoiceError}; use crate::{ForkChoice, ForkChoiceError};
use bit_vec::BitVec; use bit_vec::BitVec;
use db::Store;
use log::{debug, trace}; use log::{debug, trace};
use std::collections::HashMap; use std::collections::HashMap;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::sync::Arc; use std::sync::Arc;
use store::Store;
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight}; use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight};
//TODO: Pruning - Children //TODO: Pruning - Children

View File

@ -21,9 +21,9 @@ pub mod longest_chain;
pub mod optimized_lmd_ghost; pub mod optimized_lmd_ghost;
pub mod slow_lmd_ghost; pub mod slow_lmd_ghost;
// use db::stores::BeaconBlockAtSlotError; // use store::stores::BeaconBlockAtSlotError;
// use db::DBError; // use store::DBError;
use db::Error as DBError; use store::Error as DBError;
use types::{BeaconBlock, ChainSpec, Hash256}; use types::{BeaconBlock, ChainSpec, Hash256};
pub use bitwise_lmd_ghost::BitwiseLMDGhost; pub use bitwise_lmd_ghost::BitwiseLMDGhost;

View File

@ -1,6 +1,6 @@
use crate::{ForkChoice, ForkChoiceError}; use crate::{ForkChoice, ForkChoiceError};
use db::Store;
use std::sync::Arc; use std::sync::Arc;
use store::Store;
use types::{BeaconBlock, ChainSpec, Hash256, Slot}; use types::{BeaconBlock, ChainSpec, Hash256, Slot};
pub struct LongestChain<T> { pub struct LongestChain<T> {

View File

@ -1,13 +1,11 @@
//! The optimised bitwise LMD-GHOST fork choice rule. //! The optimised bitwise LMD-GHOST fork choice rule.
extern crate bit_vec;
use crate::{ForkChoice, ForkChoiceError}; use crate::{ForkChoice, ForkChoiceError};
use db::Store;
use log::{debug, trace}; use log::{debug, trace};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::HashMap; use std::collections::HashMap;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::sync::Arc; use std::sync::Arc;
use store::Store;
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight}; use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight};
//TODO: Pruning - Children //TODO: Pruning - Children

View File

@ -1,11 +1,9 @@
extern crate db;
use crate::{ForkChoice, ForkChoiceError}; use crate::{ForkChoice, ForkChoiceError};
use db::Store;
use log::{debug, trace}; use log::{debug, trace};
use std::collections::HashMap; use std::collections::HashMap;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::sync::Arc; use std::sync::Arc;
use store::Store;
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot}; use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot};
//TODO: Pruning and syncing //TODO: Pruning and syncing

View File

@ -1,26 +1,14 @@
#![cfg(not(debug_assertions))] #![cfg(not(debug_assertions))]
// Tests the available fork-choice algorithms // Tests the available fork-choice algorithms
extern crate beacon_chain;
extern crate bls;
extern crate db;
// extern crate env_logger; // for debugging
extern crate fork_choice;
extern crate hex;
extern crate log;
extern crate slot_clock;
extern crate types;
extern crate yaml_rust;
pub use beacon_chain::BeaconChain; pub use beacon_chain::BeaconChain;
use bls::Signature; use bls::Signature;
use db::MemoryDB; use store::MemoryStore;
use db::Store; use store::Store;
// use env_logger::{Builder, Env}; // use env_logger::{Builder, Env};
use fork_choice::{ use fork_choice::{
BitwiseLMDGhost, ForkChoice, ForkChoiceAlgorithm, LongestChain, OptimizedLMDGhost, SlowLMDGhost, BitwiseLMDGhost, ForkChoice, ForkChoiceAlgorithm, LongestChain, OptimizedLMDGhost, SlowLMDGhost,
}; };
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};
@ -220,23 +208,23 @@ fn load_test_cases_from_yaml(file_path: &str) -> Vec<yaml_rust::Yaml> {
fn setup_inital_state( fn setup_inital_state(
fork_choice_algo: &ForkChoiceAlgorithm, fork_choice_algo: &ForkChoiceAlgorithm,
num_validators: usize, num_validators: usize,
) -> (Box<ForkChoice>, Arc<MemoryDB>, Hash256) { ) -> (Box<ForkChoice>, Arc<MemoryStore>, Hash256) {
let store = Arc::new(MemoryDB::open()); let store = Arc::new(MemoryStore::open());
// the fork choice instantiation // the fork choice instantiation
let fork_choice: Box<ForkChoice> = match fork_choice_algo { let fork_choice: Box<ForkChoice> = match fork_choice_algo {
ForkChoiceAlgorithm::OptimizedLMDGhost => { ForkChoiceAlgorithm::OptimizedLMDGhost => {
let f: OptimizedLMDGhost<MemoryDB, FoundationEthSpec> = let f: OptimizedLMDGhost<MemoryStore, FoundationEthSpec> =
OptimizedLMDGhost::new(store.clone()); OptimizedLMDGhost::new(store.clone());
Box::new(f) Box::new(f)
} }
ForkChoiceAlgorithm::BitwiseLMDGhost => { ForkChoiceAlgorithm::BitwiseLMDGhost => {
let f: BitwiseLMDGhost<MemoryDB, FoundationEthSpec> = let f: BitwiseLMDGhost<MemoryStore, FoundationEthSpec> =
BitwiseLMDGhost::new(store.clone()); BitwiseLMDGhost::new(store.clone());
Box::new(f) Box::new(f)
} }
ForkChoiceAlgorithm::SlowLMDGhost => { ForkChoiceAlgorithm::SlowLMDGhost => {
let f: SlowLMDGhost<MemoryDB, FoundationEthSpec> = SlowLMDGhost::new(store.clone()); let f: SlowLMDGhost<MemoryStore, FoundationEthSpec> = SlowLMDGhost::new(store.clone());
Box::new(f) Box::new(f)
} }
ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(store.clone())), ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(store.clone())),