Rename db
crate to store
This commit is contained in:
parent
29427cf0e6
commit
3bcf5ba706
@ -22,7 +22,7 @@ members = [
|
||||
"eth2/utils/fisher_yates_shuffle",
|
||||
"eth2/utils/test_random_derive",
|
||||
"beacon_node",
|
||||
"beacon_node/db",
|
||||
"beacon_node/store",
|
||||
"beacon_node/client",
|
||||
"beacon_node/network",
|
||||
"beacon_node/eth2-libp2p",
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
types = { path = "../eth2/types" }
|
||||
db = { path = "./db" }
|
||||
store = { path = "./store" }
|
||||
client = { path = "client" }
|
||||
version = { path = "version" }
|
||||
clap = "2.32.0"
|
||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
bls = { path = "../../eth2/utils/bls" }
|
||||
boolean-bitfield = { path = "../../eth2/utils/boolean-bitfield" }
|
||||
db = { path = "../db" }
|
||||
store = { path = "../store" }
|
||||
failure = "0.1"
|
||||
failure_derive = "0.1"
|
||||
hashing = { path = "../../eth2/utils/hashing" }
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::checkpoint::CheckPoint;
|
||||
use crate::errors::{BeaconChainError as Error, BlockProductionError};
|
||||
use db::{Error as DBError, Store};
|
||||
use fork_choice::{ForkChoice, ForkChoiceError};
|
||||
use log::{debug, trace};
|
||||
use operation_pool::DepositInsertStatus;
|
||||
@ -16,6 +15,7 @@ use state_processing::{
|
||||
per_slot_processing, BlockProcessingError, SlotProcessingError,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use store::{Error as DBError, Store};
|
||||
use types::*;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
@ -20,7 +20,7 @@ pub enum BeaconChainError {
|
||||
UnableToReadSlot,
|
||||
BeaconStateError(BeaconStateError),
|
||||
DBInconsistent(String),
|
||||
DBError(db::Error),
|
||||
DBError(store::Error),
|
||||
ForkChoiceError(ForkChoiceError),
|
||||
MissingBeaconBlock(Hash256),
|
||||
MissingBeaconState(Hash256),
|
||||
|
@ -3,11 +3,11 @@
|
||||
// testnet. These are examples. Also. there is code duplication which can/should be cleaned up.
|
||||
|
||||
use crate::BeaconChain;
|
||||
use db::{DiskDB, MemoryDB};
|
||||
use fork_choice::BitwiseLMDGhost;
|
||||
use slot_clock::SystemTimeSlotClock;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use store::{DiskStore, MemoryStore};
|
||||
use tree_hash::TreeHash;
|
||||
use types::test_utils::TestingBeaconStateBuilder;
|
||||
use types::{BeaconBlock, ChainSpec, FewValidatorsEthSpec, FoundationEthSpec, Hash256};
|
||||
@ -19,14 +19,14 @@ pub fn initialise_beacon_chain(
|
||||
db_name: Option<&PathBuf>,
|
||||
) -> Arc<
|
||||
BeaconChain<
|
||||
DiskDB,
|
||||
DiskStore,
|
||||
SystemTimeSlotClock,
|
||||
BitwiseLMDGhost<DiskDB, FoundationEthSpec>,
|
||||
BitwiseLMDGhost<DiskStore, FoundationEthSpec>,
|
||||
FoundationEthSpec,
|
||||
>,
|
||||
> {
|
||||
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 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>,
|
||||
) -> Arc<
|
||||
BeaconChain<
|
||||
MemoryDB,
|
||||
MemoryStore,
|
||||
SystemTimeSlotClock,
|
||||
BitwiseLMDGhost<MemoryDB, FewValidatorsEthSpec>,
|
||||
BitwiseLMDGhost<MemoryStore, 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 (genesis_state, _keypairs) = state_builder.build();
|
||||
@ -111,14 +111,14 @@ pub fn initialise_test_beacon_chain_with_disk_db(
|
||||
db_name: Option<&PathBuf>,
|
||||
) -> Arc<
|
||||
BeaconChain<
|
||||
DiskDB,
|
||||
DiskStore,
|
||||
SystemTimeSlotClock,
|
||||
BitwiseLMDGhost<DiskDB, FewValidatorsEthSpec>,
|
||||
BitwiseLMDGhost<DiskStore, FewValidatorsEthSpec>,
|
||||
FewValidatorsEthSpec,
|
||||
>,
|
||||
> {
|
||||
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 state_builder = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(8, spec);
|
||||
|
@ -7,7 +7,6 @@ pub mod test_utils;
|
||||
pub use self::beacon_chain::{BeaconChain, BlockProcessingOutcome, InvalidBlock, ValidBlock};
|
||||
pub use self::checkpoint::CheckPoint;
|
||||
pub use self::errors::{BeaconChainError, BlockProductionError};
|
||||
pub use db;
|
||||
pub use fork_choice;
|
||||
pub use parking_lot;
|
||||
pub use slot_clock;
|
||||
@ -15,4 +14,5 @@ pub use state_processing::per_block_processing::errors::{
|
||||
AttestationValidationError, AttesterSlashingValidationError, DepositValidationError,
|
||||
ExitValidationError, ProposerSlashingValidationError, TransferValidationError,
|
||||
};
|
||||
pub use store;
|
||||
pub use types;
|
||||
|
@ -1,14 +1,18 @@
|
||||
pub use crate::{BeaconChain, BeaconChainError, CheckPoint};
|
||||
use db::MemoryDB;
|
||||
use fork_choice::BitwiseLMDGhost;
|
||||
use slot_clock::TestingSlotClock;
|
||||
use std::sync::Arc;
|
||||
use store::MemoryStore;
|
||||
use tree_hash::TreeHash;
|
||||
use types::*;
|
||||
use types::{test_utils::TestingBeaconStateBuilder, EthSpec, FewValidatorsEthSpec};
|
||||
|
||||
type TestingBeaconChain<E> =
|
||||
BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB, FewValidatorsEthSpec>, E>;
|
||||
type TestingBeaconChain<E> = BeaconChain<
|
||||
MemoryStore,
|
||||
TestingSlotClock,
|
||||
BitwiseLMDGhost<MemoryStore, FewValidatorsEthSpec>,
|
||||
E,
|
||||
>;
|
||||
|
||||
pub struct TestingBeaconChainBuilder<E: EthSpec> {
|
||||
state_builder: TestingBeaconStateBuilder<E>,
|
||||
@ -16,7 +20,7 @@ pub struct TestingBeaconChainBuilder<E: EthSpec> {
|
||||
|
||||
impl<E: EthSpec> TestingBeaconChainBuilder<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 fork_choice = BitwiseLMDGhost::new(store.clone());
|
||||
|
||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
beacon_chain = { path = "../beacon_chain" }
|
||||
network = { path = "../network" }
|
||||
db = { path = "../db" }
|
||||
store = { path = "../store" }
|
||||
rpc = { path = "../rpc" }
|
||||
fork_choice = { path = "../../eth2/fork_choice" }
|
||||
types = { path = "../../eth2/types" }
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::{ArcBeaconChain, ClientConfig};
|
||||
use beacon_chain::{
|
||||
db::{DiskDB, MemoryDB, Store},
|
||||
fork_choice::BitwiseLMDGhost,
|
||||
initialise,
|
||||
slot_clock::{SlotClock, SystemTimeSlotClock},
|
||||
store::{DiskStore, MemoryStore, Store},
|
||||
};
|
||||
use fork_choice::ForkChoice;
|
||||
use types::{EthSpec, FewValidatorsEthSpec, FoundationEthSpec};
|
||||
@ -22,7 +22,7 @@ pub trait ClientTypes {
|
||||
pub struct StandardClientType;
|
||||
|
||||
impl ClientTypes for StandardClientType {
|
||||
type DB = DiskDB;
|
||||
type DB = DiskStore;
|
||||
type SlotClock = SystemTimeSlotClock;
|
||||
type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>;
|
||||
type EthSpec = FoundationEthSpec;
|
||||
@ -34,10 +34,10 @@ impl ClientTypes for StandardClientType {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MemoryDBTestingClientType;
|
||||
pub struct MemoryStoreTestingClientType;
|
||||
|
||||
impl ClientTypes for MemoryDBTestingClientType {
|
||||
type DB = MemoryDB;
|
||||
impl ClientTypes for MemoryStoreTestingClientType {
|
||||
type DB = MemoryStore;
|
||||
type SlotClock = SystemTimeSlotClock;
|
||||
type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>;
|
||||
type EthSpec = FewValidatorsEthSpec;
|
||||
@ -49,10 +49,10 @@ impl ClientTypes for MemoryDBTestingClientType {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DiskDBTestingClientType;
|
||||
pub struct DiskStoreTestingClientType;
|
||||
|
||||
impl ClientTypes for DiskDBTestingClientType {
|
||||
type DB = DiskDB;
|
||||
impl ClientTypes for DiskStoreTestingClientType {
|
||||
type DB = DiskStore;
|
||||
type SlotClock = SystemTimeSlotClock;
|
||||
type ForkChoice = BitwiseLMDGhost<Self::DB, Self::EthSpec>;
|
||||
type EthSpec = FewValidatorsEthSpec;
|
||||
|
@ -8,7 +8,6 @@ pub mod notifier;
|
||||
use beacon_chain::BeaconChain;
|
||||
pub use client_config::{ClientConfig, DBType};
|
||||
pub use client_types::ClientTypes;
|
||||
use db::Store;
|
||||
use exit_future::Signal;
|
||||
use fork_choice::ForkChoice;
|
||||
use futures::{future::Future, Stream};
|
||||
@ -18,6 +17,7 @@ use slot_clock::SlotClock;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use store::Store;
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use tokio::timer::Interval;
|
||||
use types::EthSpec;
|
||||
|
@ -1,9 +1,9 @@
|
||||
use beacon_chain::BeaconChain as RawBeaconChain;
|
||||
use beacon_chain::{
|
||||
db::Store,
|
||||
fork_choice::ForkChoice,
|
||||
parking_lot::RwLockReadGuard,
|
||||
slot_clock::SlotClock,
|
||||
store::Store,
|
||||
types::{BeaconState, ChainSpec},
|
||||
AttestationValidationError, CheckPoint,
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ protos = { path = "../../protos" }
|
||||
grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] }
|
||||
protobuf = "2.0.2"
|
||||
clap = "2.32.0"
|
||||
db = { path = "../db" }
|
||||
store = { path = "../store" }
|
||||
dirs = "1.0.3"
|
||||
futures = "0.1.23"
|
||||
slog = "^2.2.3"
|
||||
|
@ -1,9 +1,9 @@
|
||||
use beacon_chain::BeaconChain as RawBeaconChain;
|
||||
use beacon_chain::{
|
||||
db::Store,
|
||||
fork_choice::ForkChoice,
|
||||
parking_lot::{RwLockReadGuard, RwLockWriteGuard},
|
||||
slot_clock::SlotClock,
|
||||
store::Store,
|
||||
types::{BeaconState, ChainSpec, Signature},
|
||||
AttestationValidationError, BlockProductionError,
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
use client::client_types::{DiskDBTestingClientType, MemoryDBTestingClientType};
|
||||
use client::client_types::{DiskStoreTestingClientType, MemoryStoreTestingClientType};
|
||||
use client::{error, DBType};
|
||||
use client::{notifier, Client, ClientConfig, ClientTypes};
|
||||
use futures::sync::oneshot;
|
||||
@ -29,9 +29,9 @@ pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Resul
|
||||
info!(
|
||||
log,
|
||||
"BeaconNode starting";
|
||||
"type" => "DiskDBTestingClientType"
|
||||
"type" => "DiskStoreTestingClientType"
|
||||
);
|
||||
let client: Client<DiskDBTestingClientType> =
|
||||
let client: Client<DiskStoreTestingClientType> =
|
||||
Client::new(config, log.clone(), &executor)?;
|
||||
|
||||
run(client, executor, runtime, log)
|
||||
@ -40,9 +40,9 @@ pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Resul
|
||||
info!(
|
||||
log,
|
||||
"BeaconNode starting";
|
||||
"type" => "MemoryDBTestingClientType"
|
||||
"type" => "MemoryStoreTestingClientType"
|
||||
);
|
||||
let client: Client<MemoryDBTestingClientType> =
|
||||
let client: Client<MemoryStoreTestingClientType> =
|
||||
Client::new(config, log.clone(), &executor)?;
|
||||
|
||||
run(client, executor, runtime, log)
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "db"
|
||||
name = "store"
|
||||
version = "0.1.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
@ -121,7 +121,7 @@ mod tests {
|
||||
#[test]
|
||||
fn chain_without_skips() {
|
||||
let n: usize = 10;
|
||||
let store = MemoryDB::open();
|
||||
let store = MemoryStore::open();
|
||||
let spec = FewValidatorsEthSpec::spec();
|
||||
|
||||
let slots: Vec<usize> = (0..n).collect();
|
||||
@ -145,7 +145,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn chain_with_skips() {
|
||||
let store = MemoryDB::open();
|
||||
let store = MemoryStore::open();
|
||||
let spec = FewValidatorsEthSpec::spec();
|
||||
|
||||
let slots = vec![0, 1, 2, 5];
|
@ -10,11 +10,11 @@ use std::path::Path;
|
||||
/// A on-disk database which implements the ClientDB trait.
|
||||
///
|
||||
/// This implementation uses RocksDB with default options.
|
||||
pub struct DiskDB {
|
||||
pub struct DiskStore {
|
||||
db: DB,
|
||||
}
|
||||
|
||||
impl DiskDB {
|
||||
impl DiskStore {
|
||||
/// Open the RocksDB database, optionally supplying columns if required.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
/// Corresponds to the `get_cf()` method on the RocksDB API.
|
||||
@ -154,7 +154,7 @@ mod tests {
|
||||
let col_name: &str = "TestColumn";
|
||||
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 {
|
||||
db.create_col(&cf).unwrap();
|
@ -5,8 +5,8 @@ mod impls;
|
||||
mod leveldb_store;
|
||||
mod memory_db;
|
||||
|
||||
pub use self::leveldb_store::LevelDB as DiskDB;
|
||||
pub use self::memory_db::MemoryDB;
|
||||
pub use self::leveldb_store::LevelDB as DiskStore;
|
||||
pub use self::memory_db::MemoryStore;
|
||||
pub use errors::Error;
|
||||
pub use types::*;
|
||||
pub type DBValue = Vec<u8>;
|
||||
@ -154,21 +154,21 @@ mod tests {
|
||||
fn diskdb() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path();
|
||||
let store = DiskDB::open(&path).unwrap();
|
||||
let store = DiskStore::open(&path).unwrap();
|
||||
|
||||
test_impl(store);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memorydb() {
|
||||
let store = MemoryDB::open();
|
||||
let store = MemoryStore::open();
|
||||
|
||||
test_impl(store);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exists() {
|
||||
let store = MemoryDB::open();
|
||||
let store = MemoryStore::open();
|
||||
let key = Hash256::random();
|
||||
let item = StorableThing { a: 1, b: 42 };
|
||||
|
@ -4,11 +4,11 @@ use std::collections::HashMap;
|
||||
|
||||
type DBHashMap = HashMap<Vec<u8>, Vec<u8>>;
|
||||
|
||||
pub struct MemoryDB {
|
||||
pub struct MemoryStore {
|
||||
db: RwLock<DBHashMap>,
|
||||
}
|
||||
|
||||
impl MemoryDB {
|
||||
impl MemoryStore {
|
||||
pub fn open() -> Self {
|
||||
Self {
|
||||
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.
|
||||
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
|
||||
.db
|
||||
@ -36,7 +36,7 @@ impl Store for MemoryDB {
|
||||
|
||||
/// Puts a key in the database.
|
||||
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());
|
||||
|
||||
@ -45,14 +45,14 @@ impl Store for MemoryDB {
|
||||
|
||||
/// Return true if some key exists in some column.
|
||||
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))
|
||||
}
|
||||
|
||||
/// Delete some key from the database.
|
||||
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);
|
||||
|
@ -5,7 +5,7 @@ authors = ["Age Manning <Age@AgeManning.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
db = { path = "../../beacon_node/db" }
|
||||
store = { path = "../../beacon_node/store" }
|
||||
ssz = { path = "../utils/ssz" }
|
||||
types = { path = "../types" }
|
||||
log = "0.4.6"
|
||||
|
@ -1,13 +1,11 @@
|
||||
//! The optimised bitwise LMD-GHOST fork choice rule.
|
||||
extern crate bit_vec;
|
||||
|
||||
use crate::{ForkChoice, ForkChoiceError};
|
||||
use bit_vec::BitVec;
|
||||
use db::Store;
|
||||
use log::{debug, trace};
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use store::Store;
|
||||
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight};
|
||||
|
||||
//TODO: Pruning - Children
|
||||
|
@ -21,9 +21,9 @@ pub mod longest_chain;
|
||||
pub mod optimized_lmd_ghost;
|
||||
pub mod slow_lmd_ghost;
|
||||
|
||||
// use db::stores::BeaconBlockAtSlotError;
|
||||
// use db::DBError;
|
||||
use db::Error as DBError;
|
||||
// use store::stores::BeaconBlockAtSlotError;
|
||||
// use store::DBError;
|
||||
use store::Error as DBError;
|
||||
use types::{BeaconBlock, ChainSpec, Hash256};
|
||||
|
||||
pub use bitwise_lmd_ghost::BitwiseLMDGhost;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{ForkChoice, ForkChoiceError};
|
||||
use db::Store;
|
||||
use std::sync::Arc;
|
||||
use store::Store;
|
||||
use types::{BeaconBlock, ChainSpec, Hash256, Slot};
|
||||
|
||||
pub struct LongestChain<T> {
|
||||
|
@ -1,13 +1,11 @@
|
||||
//! The optimised bitwise LMD-GHOST fork choice rule.
|
||||
extern crate bit_vec;
|
||||
|
||||
use crate::{ForkChoice, ForkChoiceError};
|
||||
use db::Store;
|
||||
use log::{debug, trace};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use store::Store;
|
||||
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot, SlotHeight};
|
||||
|
||||
//TODO: Pruning - Children
|
||||
|
@ -1,11 +1,9 @@
|
||||
extern crate db;
|
||||
|
||||
use crate::{ForkChoice, ForkChoiceError};
|
||||
use db::Store;
|
||||
use log::{debug, trace};
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use store::Store;
|
||||
use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot};
|
||||
|
||||
//TODO: Pruning and syncing
|
||||
|
@ -1,26 +1,14 @@
|
||||
#![cfg(not(debug_assertions))]
|
||||
// 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;
|
||||
use bls::Signature;
|
||||
use db::MemoryDB;
|
||||
use db::Store;
|
||||
use store::MemoryStore;
|
||||
use store::Store;
|
||||
// use env_logger::{Builder, Env};
|
||||
use fork_choice::{
|
||||
BitwiseLMDGhost, ForkChoice, ForkChoiceAlgorithm, LongestChain, OptimizedLMDGhost, SlowLMDGhost,
|
||||
};
|
||||
use ssz::ssz_encode;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
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(
|
||||
fork_choice_algo: &ForkChoiceAlgorithm,
|
||||
num_validators: usize,
|
||||
) -> (Box<ForkChoice>, Arc<MemoryDB>, Hash256) {
|
||||
let store = Arc::new(MemoryDB::open());
|
||||
) -> (Box<ForkChoice>, Arc<MemoryStore>, Hash256) {
|
||||
let store = Arc::new(MemoryStore::open());
|
||||
|
||||
// the fork choice instantiation
|
||||
let fork_choice: Box<ForkChoice> = match fork_choice_algo {
|
||||
ForkChoiceAlgorithm::OptimizedLMDGhost => {
|
||||
let f: OptimizedLMDGhost<MemoryDB, FoundationEthSpec> =
|
||||
let f: OptimizedLMDGhost<MemoryStore, FoundationEthSpec> =
|
||||
OptimizedLMDGhost::new(store.clone());
|
||||
Box::new(f)
|
||||
}
|
||||
ForkChoiceAlgorithm::BitwiseLMDGhost => {
|
||||
let f: BitwiseLMDGhost<MemoryDB, FoundationEthSpec> =
|
||||
let f: BitwiseLMDGhost<MemoryStore, FoundationEthSpec> =
|
||||
BitwiseLMDGhost::new(store.clone());
|
||||
Box::new(f)
|
||||
}
|
||||
ForkChoiceAlgorithm::SlowLMDGhost => {
|
||||
let f: SlowLMDGhost<MemoryDB, FoundationEthSpec> = SlowLMDGhost::new(store.clone());
|
||||
let f: SlowLMDGhost<MemoryStore, FoundationEthSpec> = SlowLMDGhost::new(store.clone());
|
||||
Box::new(f)
|
||||
}
|
||||
ForkChoiceAlgorithm::LongestChain => Box::new(LongestChain::new(store.clone())),
|
||||
|
Loading…
Reference in New Issue
Block a user