mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-01 05:37:05 +00:00
Drop unused EthSpec generic from Stores (#9281)
Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user