Drop unused EthSpec generic from Stores (#9281)

Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
Lion - dapplion
2026-05-21 02:35:35 -06:00
committed by GitHub
parent a9637c1650
commit 1caaa10fa8
31 changed files with 141 additions and 183 deletions

View File

@@ -6,18 +6,17 @@ use crate::{ColumnIter, ColumnKeyIter, DBColumn, Error, ItemStore, Key, KeyValue
use crate::{KeyValueStoreOp, StoreConfig, config::DatabaseBackend};
use std::collections::HashSet;
use std::path::Path;
use types::EthSpec;
pub enum BeaconNodeBackend<E: EthSpec> {
pub enum BeaconNodeBackend {
#[cfg(feature = "leveldb")]
LevelDb(leveldb_impl::LevelDB<E>),
LevelDb(leveldb_impl::LevelDB),
#[cfg(feature = "redb")]
Redb(redb_impl::Redb<E>),
Redb(redb_impl::Redb),
}
impl<E: EthSpec> ItemStore<E> for BeaconNodeBackend<E> {}
impl ItemStore for BeaconNodeBackend {}
impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
impl KeyValueStore for BeaconNodeBackend {
fn get_bytes(&self, column: DBColumn, key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
match self {
#[cfg(feature = "leveldb")]
@@ -183,7 +182,7 @@ impl<E: EthSpec> KeyValueStore<E> for BeaconNodeBackend<E> {
}
}
impl<E: EthSpec> BeaconNodeBackend<E> {
impl BeaconNodeBackend {
pub fn open(config: &StoreConfig, path: &Path) -> Result<Self, Error> {
metrics::inc_counter_vec(&metrics::DISK_DB_TYPE, &[&config.backend.to_string()]);
match config.backend {

View File

@@ -15,15 +15,13 @@ use leveldb::{
options::{Options, ReadOptions},
};
use std::collections::HashSet;
use std::marker::PhantomData;
use std::path::Path;
use types::{EthSpec, Hash256};
use types::Hash256;
use super::interface::WriteOptions;
pub struct LevelDB<E: EthSpec> {
pub struct LevelDB {
db: Database<BytesKey>,
_phantom: PhantomData<E>,
}
impl From<WriteOptions> for leveldb::options::WriteOptions {
@@ -34,7 +32,7 @@ impl From<WriteOptions> for leveldb::options::WriteOptions {
}
}
impl<E: EthSpec> LevelDB<E> {
impl LevelDB {
pub fn open(path: &Path) -> Result<Self, Error> {
let mut options = Options::new();
@@ -42,10 +40,7 @@ impl<E: EthSpec> LevelDB<E> {
let db = Database::open(path, options)?;
Ok(Self {
db,
_phantom: PhantomData,
})
Ok(Self { db })
}
pub fn read_options(&self) -> ReadOptions<'_, BytesKey> {

View File

@@ -3,17 +3,15 @@ use crate::{DBColumn, Error, KeyValueStoreOp};
use parking_lot::RwLock;
use redb::TableDefinition;
use std::collections::HashSet;
use std::{borrow::BorrowMut, marker::PhantomData, path::Path};
use std::{borrow::BorrowMut, path::Path};
use strum::IntoEnumIterator;
use types::EthSpec;
use super::interface::WriteOptions;
pub const DB_FILE_NAME: &str = "database.redb";
pub struct Redb<E: EthSpec> {
pub struct Redb {
db: RwLock<redb::Database>,
_phantom: PhantomData<E>,
}
impl From<WriteOptions> for redb::Durability {
@@ -26,19 +24,16 @@ impl From<WriteOptions> for redb::Durability {
}
}
impl<E: EthSpec> Redb<E> {
impl Redb {
pub fn open(path: &Path) -> Result<Self, Error> {
let db_file = path.join(DB_FILE_NAME);
let db = redb::Database::create(db_file)?;
for column in DBColumn::iter() {
Redb::<E>::create_table(&db, column.into())?;
Self::create_table(&db, column.into())?;
}
Ok(Self {
db: db.into(),
_phantom: PhantomData,
})
Ok(Self { db: db.into() })
}
fn create_table(db: &redb::Database, table_name: &str) -> Result<(), Error> {

View File

@@ -9,7 +9,7 @@ pub type HybridForwardsBlockRootsIterator<'a, E, Hot, Cold> =
pub type HybridForwardsStateRootsIterator<'a, E, Hot, Cold> =
HybridForwardsIterator<'a, E, Hot, Cold>;
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold> {
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> HotColdDB<E, Hot, Cold> {
fn simple_forwards_iterator(
&self,
column: DBColumn,
@@ -116,7 +116,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
}
/// Forwards root iterator that makes use of a slot -> root mapping in the freezer DB.
pub struct FrozenForwardsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
pub struct FrozenForwardsIterator<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> {
inner: ColumnIter<'a, Vec<u8>>,
column: DBColumn,
next_slot: Slot,
@@ -124,9 +124,7 @@ pub struct FrozenForwardsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemS
_phantom: PhantomData<(E, Hot, Cold)>,
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
FrozenForwardsIterator<'a, E, Hot, Cold>
{
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> FrozenForwardsIterator<'a, E, Hot, Cold> {
/// `end_slot` is EXCLUSIVE here.
pub fn new(
store: &'a HotColdDB<E, Hot, Cold>,
@@ -148,7 +146,7 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
}
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Iterator
for FrozenForwardsIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, Slot)>;
@@ -199,7 +197,7 @@ impl Iterator for SimpleForwardsIterator {
}
/// Fusion of the above two approaches to forwards iteration. Fast and efficient.
pub enum HybridForwardsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
pub enum HybridForwardsIterator<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> {
PreFinalization {
iter: Box<FrozenForwardsIterator<'a, E, Hot, Cold>>,
store: &'a HotColdDB<E, Hot, Cold>,
@@ -220,9 +218,7 @@ pub enum HybridForwardsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemSto
Finished,
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
HybridForwardsIterator<'a, E, Hot, Cold>
{
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> HybridForwardsIterator<'a, E, Hot, Cold> {
/// Construct a new hybrid iterator.
///
/// The `get_state` closure should return a beacon state and final block/state root to backtrack
@@ -349,7 +345,7 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
}
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Iterator
for HybridForwardsIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, Slot)>;

View File

@@ -49,7 +49,7 @@ use zstd::{Decoder, Encoder};
/// Stores vector fields like the `block_roots` and `state_roots` separately, and only stores
/// intermittent "restore point" states pre-finalization.
#[derive(Debug)]
pub struct HotColdDB<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
pub struct HotColdDB<E: EthSpec, Hot: ItemStore, Cold: ItemStore> {
/// The slot and state root at the point where the database is split between hot and cold.
///
/// States with slots less than `split.slot` are in the cold DB, while states with slots
@@ -217,11 +217,11 @@ pub enum HotColdDBError {
Rollback,
}
impl<E: EthSpec> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> {
impl<E: EthSpec> HotColdDB<E, MemoryStore, MemoryStore> {
pub fn open_ephemeral(
config: StoreConfig,
spec: Arc<ChainSpec>,
) -> Result<HotColdDB<E, MemoryStore<E>, MemoryStore<E>>, Error> {
) -> Result<HotColdDB<E, MemoryStore, MemoryStore>, Error> {
config.verify::<E>()?;
let hierarchy = config.hierarchy_config.to_moduli()?;
@@ -258,7 +258,7 @@ impl<E: EthSpec> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> {
}
}
impl<E: EthSpec> HotColdDB<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>> {
impl<E: EthSpec> HotColdDB<E, BeaconNodeBackend, BeaconNodeBackend> {
/// Open a new or existing database, with the given paths to the hot and cold DBs.
///
/// The `migrate_schema` function is passed in so that the parent `BeaconChain` can provide
@@ -451,7 +451,7 @@ impl<E: EthSpec> HotColdDB<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>> {
}
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold> {
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> HotColdDB<E, Hot, Cold> {
fn cold_storage_strategy(&self, slot: Slot) -> Result<StorageStrategy, Error> {
// The start slot for the freezer HDiff is always 0
Ok(self.hierarchy.storage_strategy(slot, Slot::new(0))?)
@@ -3575,7 +3575,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
/// This function previously did a combination of freezer migration alongside pruning. Now it is
/// *just* responsible for copying relevant data to the freezer, while pruning is implemented
/// in `prune_hot_db`.
pub fn migrate_database<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
pub fn migrate_database<E: EthSpec, Hot: ItemStore, Cold: ItemStore>(
store: Arc<HotColdDB<E, Hot, Cold>>,
finalized_state_root: Hash256,
finalized_block_root: Hash256,
@@ -3786,7 +3786,7 @@ pub enum StateSummaryIteratorError {
/// Return the ancestor state root of a state beyond SlotsPerHistoricalRoot using the roots iterator
/// and the store
pub fn get_ancestor_state_root<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
pub fn get_ancestor_state_root<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore>(
store: &'a HotColdDB<E, Hot, Cold>,
from_state: &'a BeaconState<E>,
target_slot: Slot,
@@ -3993,7 +3993,7 @@ impl StoreItem for HotStateSummary {
impl HotStateSummary {
/// Construct a new summary of the given state.
pub fn new<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
pub fn new<E: EthSpec, Hot: ItemStore, Cold: ItemStore>(
store: &HotColdDB<E, Hot, Cold>,
state_root: Hash256,
state: &BeaconState<E>,

View File

@@ -242,7 +242,7 @@ pub enum InvariantViolation {
ColdStateBaseSummaryMissing { slot: Slot, base_slot: Slot },
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold> {
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> HotColdDB<E, Hot, Cold> {
/// Run all database invariant checks.
///
/// The `ctx` parameter provides data from the beacon chain layer (fork choice, state cache,

View File

@@ -13,12 +13,12 @@ use types::{
///
/// It is assumed that all ancestors for this object are stored in the database. If this is not the
/// case, the iterator will start returning `None` prior to genesis.
pub trait AncestorIter<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>, I: Iterator> {
pub trait AncestorIter<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore, I: Iterator> {
/// Returns an iterator over the roots of the ancestors of `self`.
fn try_iter_ancestor_roots(&self, store: &'a HotColdDB<E, Hot, Cold>) -> Option<I>;
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore>
AncestorIter<'a, E, Hot, Cold, BlockRootsIterator<'a, E, Hot, Cold>> for SignedBeaconBlock<E>
{
/// Iterates across all available prior block roots of `self`, starting at the most recent and ending
@@ -37,7 +37,7 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
}
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore>
AncestorIter<'a, E, Hot, Cold, StateRootsIterator<'a, E, Hot, Cold>> for BeaconState<E>
{
/// Iterates across all available prior state roots of `self`, starting at the most recent and ending
@@ -51,13 +51,11 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
}
}
pub struct StateRootsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
pub struct StateRootsIterator<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> {
inner: RootsIterator<'a, E, Hot, Cold>,
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
for StateRootsIterator<'_, E, Hot, Cold>
{
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Clone for StateRootsIterator<'_, E, Hot, Cold> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
@@ -65,7 +63,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
}
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> StateRootsIterator<'a, E, Hot, Cold> {
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> StateRootsIterator<'a, E, Hot, Cold> {
pub fn new(store: &'a HotColdDB<E, Hot, Cold>, beacon_state: &'a BeaconState<E>) -> Self {
Self {
inner: RootsIterator::new(store, beacon_state),
@@ -79,7 +77,7 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> StateRootsIterator<'
}
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Iterator
for StateRootsIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, Slot), Error>;
@@ -99,13 +97,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
/// exhausted.
///
/// Returns `None` for roots prior to genesis or when there is an error reading from `Store`.
pub struct BlockRootsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
pub struct BlockRootsIterator<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> {
inner: RootsIterator<'a, E, Hot, Cold>,
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
for BlockRootsIterator<'_, E, Hot, Cold>
{
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Clone for BlockRootsIterator<'_, E, Hot, Cold> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
@@ -113,7 +109,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone
}
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BlockRootsIterator<'a, E, Hot, Cold> {
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> BlockRootsIterator<'a, E, Hot, Cold> {
/// Create a new iterator over all block roots in the given `beacon_state` and prior states.
pub fn new(store: &'a HotColdDB<E, Hot, Cold>, beacon_state: &'a BeaconState<E>) -> Self {
Self {
@@ -138,7 +134,7 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BlockRootsIterator<'
}
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Iterator
for BlockRootsIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, Slot), Error>;
@@ -151,13 +147,13 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
}
/// Iterator over state and block roots that backtracks using the vectors from a `BeaconState`.
pub struct RootsIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
pub struct RootsIterator<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> {
store: &'a HotColdDB<E, Hot, Cold>,
beacon_state: Cow<'a, BeaconState<E>>,
slot: Slot,
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone for RootsIterator<'_, E, Hot, Cold> {
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Clone for RootsIterator<'_, E, Hot, Cold> {
fn clone(&self) -> Self {
Self {
store: self.store,
@@ -167,7 +163,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Clone for RootsIterator<
}
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> RootsIterator<'a, E, Hot, Cold> {
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> RootsIterator<'a, E, Hot, Cold> {
pub fn new(store: &'a HotColdDB<E, Hot, Cold>, beacon_state: &'a BeaconState<E>) -> Self {
Self {
store,
@@ -234,9 +230,7 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> RootsIterator<'a, E,
}
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for RootsIterator<'_, E, Hot, Cold>
{
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Iterator for RootsIterator<'_, E, Hot, Cold> {
/// (block_root, state_root, slot)
type Item = Result<(Hash256, Hash256, Slot), Error>;
@@ -246,15 +240,13 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
}
/// Block iterator that uses the `parent_root` of each block to backtrack.
pub struct ParentRootBlockIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
pub struct ParentRootBlockIterator<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> {
store: &'a HotColdDB<E, Hot, Cold>,
next_block_root: Hash256,
_phantom: PhantomData<E>,
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
ParentRootBlockIterator<'a, E, Hot, Cold>
{
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> ParentRootBlockIterator<'a, E, Hot, Cold> {
pub fn new(store: &'a HotColdDB<E, Hot, Cold>, start_block_root: Hash256) -> Self {
Self {
store,
@@ -283,7 +275,7 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>
}
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Iterator
for ParentRootBlockIterator<'_, E, Hot, Cold>
{
type Item = Result<(Hash256, SignedBeaconBlock<E, BlindedPayload<E>>), Error>;
@@ -295,11 +287,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
#[derive(Clone)]
/// Extends `BlockRootsIterator`, returning `SignedBeaconBlock` instances, instead of their roots.
pub struct BlockIterator<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
pub struct BlockIterator<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> {
roots: BlockRootsIterator<'a, E, Hot, Cold>,
}
impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BlockIterator<'a, E, Hot, Cold> {
impl<'a, E: EthSpec, Hot: ItemStore, Cold: ItemStore> BlockIterator<'a, E, Hot, Cold> {
/// Create a new iterator over all blocks in the given `beacon_state` and prior states.
pub fn new(store: &'a HotColdDB<E, Hot, Cold>, beacon_state: &'a BeaconState<E>) -> Self {
Self {
@@ -324,9 +316,7 @@ impl<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BlockIterator<'a, E,
}
}
impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
for BlockIterator<'_, E, Hot, Cold>
{
impl<E: EthSpec, Hot: ItemStore, Cold: ItemStore> Iterator for BlockIterator<'_, E, Hot, Cold> {
type Item = Result<SignedBeaconBlock<E, BlindedPayload<E>>, Error>;
fn next(&mut self) -> Option<Self::Item> {
@@ -338,7 +328,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> Iterator
///
/// Return `Err(HistoryUnavailable)` in the case where no more backtrack states are available
/// due to weak subjectivity sync.
fn next_historical_root_backtrack_state<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
fn next_historical_root_backtrack_state<E: EthSpec, Hot: ItemStore, Cold: ItemStore>(
store: &HotColdDB<E, Hot, Cold>,
current_state: &BeaconState<E>,
) -> Result<BeaconState<E>, Error> {
@@ -386,7 +376,7 @@ mod test {
harness.get_current_state()
}
fn get_store<E: EthSpec>() -> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> {
fn get_store<E: EthSpec>() -> HotColdDB<E, MemoryStore, MemoryStore> {
let store =
HotColdDB::open_ephemeral(Config::default(), Arc::new(E::default_spec())).unwrap();
// Init achor info so anchor slot is set. Use a random block as it is only used for the

View File

@@ -46,7 +46,7 @@ pub type ColumnKeyIter<'a, K> = Box<dyn Iterator<Item = Result<K, Error>> + 'a>;
pub type RawEntryIter<'a> =
Result<Box<dyn Iterator<Item = Result<(Vec<u8>, Vec<u8>), Error>> + 'a>, Error>;
pub trait KeyValueStore<E: EthSpec>: Sync + Send + Sized + 'static {
pub trait KeyValueStore: Sync + Send + Sized + 'static {
/// Retrieve some bytes in `column` with `key`.
fn get_bytes(&self, column: DBColumn, key: &[u8]) -> Result<Option<Vec<u8>>, Error>;
@@ -177,7 +177,7 @@ pub enum KeyValueStoreOp {
DeleteKey(DBColumn, Vec<u8>),
}
pub trait ItemStore<E: EthSpec>: KeyValueStore<E> + Sync + Send + Sized + 'static {
pub trait ItemStore: KeyValueStore + Sync + Send + Sized + 'static {
/// Store an item in `Self`.
fn put<I: StoreItem>(&self, key: &Hash256, item: &I) -> Result<(), Error> {
let column = I::db_column();
@@ -493,7 +493,7 @@ mod tests {
}
}
fn test_impl(store: impl ItemStore<MinimalEthSpec>) {
fn test_impl(store: impl ItemStore) {
let key = Hash256::random();
let item = StorableThing { a: 1, b: 42 };
@@ -531,7 +531,7 @@ mod tests {
#[test]
fn exists() {
let store = MemoryStore::<MinimalEthSpec>::open();
let store = MemoryStore::open();
let key = Hash256::random();
let item = StorableThing { a: 1, b: 42 };

View File

@@ -4,28 +4,24 @@ use crate::{
};
use parking_lot::RwLock;
use std::collections::{BTreeMap, HashSet};
use std::marker::PhantomData;
use types::*;
type DBMap = BTreeMap<BytesKey, Vec<u8>>;
/// A thread-safe `BTreeMap` wrapper.
pub struct MemoryStore<E: EthSpec> {
pub struct MemoryStore {
db: RwLock<DBMap>,
_phantom: PhantomData<E>,
}
impl<E: EthSpec> MemoryStore<E> {
impl MemoryStore {
/// Create a new, empty database.
pub fn open() -> Self {
Self {
db: RwLock::new(BTreeMap::new()),
_phantom: PhantomData,
}
}
}
impl<E: EthSpec> KeyValueStore<E> for MemoryStore<E> {
impl KeyValueStore for MemoryStore {
/// Get the value of some key from the database. Returns `None` if the key does not exist.
fn get_bytes(&self, col: DBColumn, key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
let column_key = BytesKey::from_vec(get_key_for_col(col, key));
@@ -148,4 +144,4 @@ impl<E: EthSpec> KeyValueStore<E> for MemoryStore<E> {
}
}
impl<E: EthSpec> ItemStore<E> for MemoryStore<E> {}
impl ItemStore for MemoryStore {}

View File

@@ -15,8 +15,8 @@ use types::{EthSpec, Slot};
impl<E, Hot, Cold> HotColdDB<E, Hot, Cold>
where
E: EthSpec,
Hot: ItemStore<E>,
Cold: ItemStore<E>,
Hot: ItemStore,
Cold: ItemStore,
{
pub fn reconstruct_historic_states(
self: &Arc<Self>,