2019-05-21 08:49:24 +00:00
|
|
|
//! Storage functionality for Lighthouse.
|
|
|
|
//!
|
|
|
|
//! Provides the following stores:
|
|
|
|
//!
|
|
|
|
//! - `DiskStore`: an on-disk store backed by leveldb. Used in production.
|
|
|
|
//! - `MemoryStore`: an in-memory store backed by a hash-map. Used for testing.
|
|
|
|
//!
|
|
|
|
//! Provides a simple API for storing/retrieving all types that sometimes needs type-hints. See
|
|
|
|
//! tests for implementation examples.
|
2019-08-19 11:02:34 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
2019-05-21 08:49:24 +00:00
|
|
|
|
2019-05-20 08:01:51 +00:00
|
|
|
mod block_at_slot;
|
2019-11-26 23:54:46 +00:00
|
|
|
pub mod chunked_vector;
|
2019-05-20 08:01:51 +00:00
|
|
|
mod errors;
|
2019-11-26 23:54:46 +00:00
|
|
|
mod hot_cold_store;
|
2019-05-20 08:01:51 +00:00
|
|
|
mod impls;
|
2019-05-21 06:29:34 +00:00
|
|
|
mod leveldb_store;
|
2019-05-21 08:49:24 +00:00
|
|
|
mod memory_store;
|
2019-08-19 11:02:34 +00:00
|
|
|
mod metrics;
|
2019-11-26 23:54:46 +00:00
|
|
|
mod partial_beacon_state;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-06-15 13:56:41 +00:00
|
|
|
pub mod iter;
|
2019-11-26 23:54:46 +00:00
|
|
|
pub mod migrate;
|
2019-06-15 13:56:41 +00:00
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
pub use self::hot_cold_store::HotColdDB as DiskStore;
|
|
|
|
pub use self::leveldb_store::LevelDB as SimpleDiskStore;
|
2019-05-21 08:49:24 +00:00
|
|
|
pub use self::memory_store::MemoryStore;
|
2019-11-26 23:54:46 +00:00
|
|
|
pub use self::migrate::Migrate;
|
|
|
|
pub use self::partial_beacon_state::PartialBeaconState;
|
2019-05-20 08:01:51 +00:00
|
|
|
pub use errors::Error;
|
2019-08-19 11:02:34 +00:00
|
|
|
pub use metrics::scrape_for_metrics;
|
2019-05-20 08:01:51 +00:00
|
|
|
pub use types::*;
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// An object capable of storing and retrieving objects implementing `StoreItem`.
|
|
|
|
///
|
|
|
|
/// A `Store` is fundamentally backed by a key-value database, however it provides support for
|
|
|
|
/// columns. A simple column implementation might involve prefixing a key with some bytes unique to
|
|
|
|
/// each column.
|
2019-11-26 23:54:46 +00:00
|
|
|
pub trait Store: Sync + Send + Sized + 'static {
|
|
|
|
/// Retrieve some bytes in `column` with `key`.
|
|
|
|
fn get_bytes(&self, column: &str, key: &[u8]) -> Result<Option<Vec<u8>>, Error>;
|
|
|
|
|
|
|
|
/// Store some `value` in `column`, indexed with `key`.
|
|
|
|
fn put_bytes(&self, column: &str, key: &[u8], value: &[u8]) -> Result<(), Error>;
|
|
|
|
|
|
|
|
/// Return `true` if `key` exists in `column`.
|
|
|
|
fn key_exists(&self, column: &str, key: &[u8]) -> Result<bool, Error>;
|
|
|
|
|
|
|
|
/// Removes `key` from `column`.
|
|
|
|
fn key_delete(&self, column: &str, key: &[u8]) -> Result<(), Error>;
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Store an item in `Self`.
|
2019-11-26 23:54:46 +00:00
|
|
|
fn put<I: StoreItem>(&self, key: &Hash256, item: &I) -> Result<(), Error> {
|
2019-05-20 08:01:51 +00:00
|
|
|
item.db_put(self, key)
|
|
|
|
}
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Retrieve an item from `Self`.
|
2019-05-20 08:01:51 +00:00
|
|
|
fn get<I: StoreItem>(&self, key: &Hash256) -> Result<Option<I>, Error> {
|
|
|
|
I::db_get(self, key)
|
|
|
|
}
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Returns `true` if the given key represents an item in `Self`.
|
2019-05-20 08:01:51 +00:00
|
|
|
fn exists<I: StoreItem>(&self, key: &Hash256) -> Result<bool, Error> {
|
|
|
|
I::db_exists(self, key)
|
|
|
|
}
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Remove an item from `Self`.
|
2019-05-20 08:01:51 +00:00
|
|
|
fn delete<I: StoreItem>(&self, key: &Hash256) -> Result<(), Error> {
|
|
|
|
I::db_delete(self, key)
|
|
|
|
}
|
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
/// Store a state in the store.
|
|
|
|
fn put_state<E: EthSpec>(
|
|
|
|
&self,
|
|
|
|
state_root: &Hash256,
|
|
|
|
state: &BeaconState<E>,
|
|
|
|
) -> Result<(), Error>;
|
|
|
|
|
|
|
|
/// Fetch a state from the store.
|
|
|
|
fn get_state<E: EthSpec>(
|
|
|
|
&self,
|
|
|
|
state_root: &Hash256,
|
|
|
|
slot: Option<Slot>,
|
|
|
|
) -> Result<Option<BeaconState<E>>, Error>;
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Given the root of an existing block in the store (`start_block_root`), return a parent
|
|
|
|
/// block with the specified `slot`.
|
|
|
|
///
|
|
|
|
/// Returns `None` if no parent block exists at that slot, or if `slot` is greater than the
|
|
|
|
/// slot of `start_block_root`.
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
fn get_block_at_preceeding_slot<E: EthSpec>(
|
2019-05-20 08:01:51 +00:00
|
|
|
&self,
|
|
|
|
start_block_root: Hash256,
|
2019-05-21 02:58:11 +00:00
|
|
|
slot: Slot,
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
) -> Result<Option<(Hash256, BeaconBlock<E>)>, Error> {
|
|
|
|
block_at_slot::get_block_at_preceeding_slot::<_, E>(self, slot, start_block_root)
|
2019-05-20 08:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
/// (Optionally) Move all data before the frozen slot to the freezer database.
|
|
|
|
fn freeze_to_state<E: EthSpec>(
|
|
|
|
_store: Arc<Self>,
|
|
|
|
_frozen_head_root: Hash256,
|
|
|
|
_frozen_head: &BeaconState<E>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-05-20 08:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// A unique column identifier.
|
2019-11-26 23:54:46 +00:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
2019-05-20 08:01:51 +00:00
|
|
|
pub enum DBColumn {
|
2019-11-26 23:54:46 +00:00
|
|
|
/// For data related to the database itself.
|
|
|
|
BeaconMeta,
|
2019-05-20 08:01:51 +00:00
|
|
|
BeaconBlock,
|
|
|
|
BeaconState,
|
|
|
|
BeaconChain,
|
2019-11-26 23:54:46 +00:00
|
|
|
BeaconBlockRoots,
|
|
|
|
BeaconStateRoots,
|
|
|
|
BeaconHistoricalRoots,
|
|
|
|
BeaconRandaoMixes,
|
2019-05-20 08:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
impl Into<&'static str> for DBColumn {
|
2019-05-20 08:01:51 +00:00
|
|
|
/// Returns a `&str` that can be used for keying a key-value data base.
|
2019-11-26 23:54:46 +00:00
|
|
|
fn into(self) -> &'static str {
|
2019-05-20 08:01:51 +00:00
|
|
|
match self {
|
2019-11-26 23:54:46 +00:00
|
|
|
DBColumn::BeaconMeta => "bma",
|
|
|
|
DBColumn::BeaconBlock => "blk",
|
|
|
|
DBColumn::BeaconState => "ste",
|
|
|
|
DBColumn::BeaconChain => "bch",
|
|
|
|
DBColumn::BeaconBlockRoots => "bbr",
|
|
|
|
DBColumn::BeaconStateRoots => "bsr",
|
|
|
|
DBColumn::BeaconHistoricalRoots => "bhr",
|
|
|
|
DBColumn::BeaconRandaoMixes => "brm",
|
2019-05-20 08:01:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
/// An item that may stored in a `Store` by serializing and deserializing from bytes.
|
|
|
|
pub trait SimpleStoreItem: Sized {
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Identifies which column this item should be placed in.
|
2019-05-20 08:01:51 +00:00
|
|
|
fn db_column() -> DBColumn;
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Serialize `self` as bytes.
|
2019-05-20 08:01:51 +00:00
|
|
|
fn as_store_bytes(&self) -> Vec<u8>;
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// De-serialize `self` from bytes.
|
2019-11-26 23:54:46 +00:00
|
|
|
///
|
|
|
|
/// Return an instance of the type and the number of bytes that were read.
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error>;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// An item that may be stored in a `Store`.
|
|
|
|
pub trait StoreItem: Sized {
|
|
|
|
/// Store `self`.
|
|
|
|
fn db_put<S: Store>(&self, store: &S, key: &Hash256) -> Result<(), Error>;
|
|
|
|
|
|
|
|
/// Retrieve an instance of `Self` from `store`.
|
|
|
|
fn db_get<S: Store>(store: &S, key: &Hash256) -> Result<Option<Self>, Error>;
|
|
|
|
|
|
|
|
/// Return `true` if an instance of `Self` exists in `store`.
|
|
|
|
fn db_exists<S: Store>(store: &S, key: &Hash256) -> Result<bool, Error>;
|
|
|
|
|
|
|
|
/// Delete an instance of `Self` from `store`.
|
|
|
|
fn db_delete<S: Store>(store: &S, key: &Hash256) -> Result<(), Error>;
|
|
|
|
}
|
2019-05-20 08:01:51 +00:00
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
impl<T> StoreItem for T
|
|
|
|
where
|
|
|
|
T: SimpleStoreItem,
|
|
|
|
{
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Store `self`.
|
2019-11-26 23:54:46 +00:00
|
|
|
fn db_put<S: Store>(&self, store: &S, key: &Hash256) -> Result<(), Error> {
|
2019-05-20 08:01:51 +00:00
|
|
|
let column = Self::db_column().into();
|
|
|
|
let key = key.as_bytes();
|
|
|
|
|
|
|
|
store
|
|
|
|
.put_bytes(column, key, &self.as_store_bytes())
|
2019-05-21 08:49:24 +00:00
|
|
|
.map_err(Into::into)
|
2019-05-20 08:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Retrieve an instance of `Self`.
|
2019-11-26 23:54:46 +00:00
|
|
|
fn db_get<S: Store>(store: &S, key: &Hash256) -> Result<Option<Self>, Error> {
|
2019-05-20 08:01:51 +00:00
|
|
|
let column = Self::db_column().into();
|
|
|
|
let key = key.as_bytes();
|
|
|
|
|
|
|
|
match store.get_bytes(column, key)? {
|
2019-11-26 23:54:46 +00:00
|
|
|
Some(bytes) => Ok(Some(Self::from_store_bytes(&bytes[..])?)),
|
2019-05-20 08:01:51 +00:00
|
|
|
None => Ok(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Return `true` if an instance of `Self` exists in `Store`.
|
2019-11-26 23:54:46 +00:00
|
|
|
fn db_exists<S: Store>(store: &S, key: &Hash256) -> Result<bool, Error> {
|
2019-05-20 08:01:51 +00:00
|
|
|
let column = Self::db_column().into();
|
|
|
|
let key = key.as_bytes();
|
|
|
|
|
|
|
|
store.key_exists(column, key)
|
|
|
|
}
|
|
|
|
|
2019-05-21 08:49:24 +00:00
|
|
|
/// Delete `self` from the `Store`.
|
2019-11-26 23:54:46 +00:00
|
|
|
fn db_delete<S: Store>(store: &S, key: &Hash256) -> Result<(), Error> {
|
2019-05-20 08:01:51 +00:00
|
|
|
let column = Self::db_column().into();
|
|
|
|
let key = key.as_bytes();
|
|
|
|
|
|
|
|
store.key_delete(column, key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use ssz::{Decode, Encode};
|
|
|
|
use ssz_derive::{Decode, Encode};
|
2019-05-21 06:29:34 +00:00
|
|
|
use tempfile::tempdir;
|
2019-05-20 08:01:51 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Debug, Encode, Decode)]
|
|
|
|
struct StorableThing {
|
|
|
|
a: u64,
|
|
|
|
b: u64,
|
|
|
|
}
|
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
impl SimpleStoreItem for StorableThing {
|
2019-05-20 08:01:51 +00:00
|
|
|
fn db_column() -> DBColumn {
|
|
|
|
DBColumn::BeaconBlock
|
|
|
|
}
|
|
|
|
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
|
|
self.as_ssz_bytes()
|
|
|
|
}
|
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
2019-05-20 08:01:51 +00:00
|
|
|
Self::from_ssz_bytes(bytes).map_err(Into::into)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 06:37:15 +00:00
|
|
|
fn test_impl(store: impl Store) {
|
2019-05-21 06:29:34 +00:00
|
|
|
let key = Hash256::random();
|
|
|
|
let item = StorableThing { a: 1, b: 42 };
|
|
|
|
|
2019-05-21 06:37:15 +00:00
|
|
|
assert_eq!(store.exists::<StorableThing>(&key), Ok(false));
|
|
|
|
|
2019-05-21 06:29:34 +00:00
|
|
|
store.put(&key, &item).unwrap();
|
|
|
|
|
2019-05-21 06:37:15 +00:00
|
|
|
assert_eq!(store.exists::<StorableThing>(&key), Ok(true));
|
2019-05-21 06:29:34 +00:00
|
|
|
|
2019-05-21 06:37:15 +00:00
|
|
|
let retrieved = store.get(&key).unwrap().unwrap();
|
2019-05-21 06:29:34 +00:00
|
|
|
assert_eq!(item, retrieved);
|
2019-05-21 06:37:15 +00:00
|
|
|
|
|
|
|
store.delete::<StorableThing>(&key).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(store.exists::<StorableThing>(&key), Ok(false));
|
|
|
|
|
|
|
|
assert_eq!(store.get::<StorableThing>(&key), Ok(None));
|
2019-05-21 06:29:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 08:01:51 +00:00
|
|
|
#[test]
|
2019-05-21 06:49:56 +00:00
|
|
|
fn diskdb() {
|
2019-11-26 23:54:46 +00:00
|
|
|
use sloggers::{null::NullLoggerBuilder, Build};
|
|
|
|
|
|
|
|
let hot_dir = tempdir().unwrap();
|
|
|
|
let cold_dir = tempdir().unwrap();
|
|
|
|
let spec = MinimalEthSpec::default_spec();
|
|
|
|
let log = NullLoggerBuilder.build().unwrap();
|
|
|
|
let store = DiskStore::open(&hot_dir.path(), &cold_dir.path(), spec, log).unwrap();
|
|
|
|
|
|
|
|
test_impl(store);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simplediskdb() {
|
2019-05-21 06:37:15 +00:00
|
|
|
let dir = tempdir().unwrap();
|
|
|
|
let path = dir.path();
|
2019-11-26 23:54:46 +00:00
|
|
|
let store = SimpleDiskStore::open(&path).unwrap();
|
2019-05-20 08:01:51 +00:00
|
|
|
|
2019-05-21 06:37:15 +00:00
|
|
|
test_impl(store);
|
|
|
|
}
|
2019-05-20 08:01:51 +00:00
|
|
|
|
2019-05-21 06:37:15 +00:00
|
|
|
#[test]
|
|
|
|
fn memorydb() {
|
2019-05-21 08:20:23 +00:00
|
|
|
let store = MemoryStore::open();
|
2019-05-20 08:01:51 +00:00
|
|
|
|
2019-05-21 06:37:15 +00:00
|
|
|
test_impl(store);
|
2019-05-20 08:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn exists() {
|
2019-05-21 08:20:23 +00:00
|
|
|
let store = MemoryStore::open();
|
2019-05-20 08:01:51 +00:00
|
|
|
let key = Hash256::random();
|
|
|
|
let item = StorableThing { a: 1, b: 42 };
|
|
|
|
|
|
|
|
assert_eq!(store.exists::<StorableThing>(&key).unwrap(), false);
|
|
|
|
|
|
|
|
store.put(&key, &item).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(store.exists::<StorableThing>(&key).unwrap(), true);
|
|
|
|
|
|
|
|
store.delete::<StorableThing>(&key).unwrap();
|
2019-02-27 23:24:27 +00:00
|
|
|
|
2019-05-20 08:01:51 +00:00
|
|
|
assert_eq!(store.exists::<StorableThing>(&key).unwrap(), false);
|
|
|
|
}
|
2019-02-27 23:24:27 +00:00
|
|
|
}
|