diff --git a/beacon_node/db2/src/lib.rs b/beacon_node/db2/src/lib.rs index 1ed9d5984..da00262e6 100644 --- a/beacon_node/db2/src/lib.rs +++ b/beacon_node/db2/src/lib.rs @@ -9,20 +9,20 @@ pub use errors::Error; pub use types::*; pub type DBValue = Vec; -pub trait StoreDB: Sync + Send + Sized { - fn put(&self, key: &Hash256, item: &impl DBRecord) -> Result<(), Error> { +pub trait Store: Sync + Send + Sized { + fn put(&self, key: &Hash256, item: &impl StorableItem) -> Result<(), Error> { item.db_put(self, key) } - fn get(&self, key: &Hash256) -> Result, Error> { + fn get(&self, key: &Hash256) -> Result, Error> { I::db_get(self, key) } - fn exists(&self, key: &Hash256) -> Result { + fn exists(&self, key: &Hash256) -> Result { I::db_exists(self, key) } - fn delete(&self, key: &Hash256) -> Result<(), Error> { + fn delete(&self, key: &Hash256) -> Result<(), Error> { I::db_delete(self, key) } @@ -35,17 +35,6 @@ pub trait StoreDB: Sync + Send + Sized { fn key_delete(&self, col: &str, key: &[u8]) -> Result<(), Error>; } -pub trait DBStore { - fn db_column(&self) -> DBColumn; -} - -/// Currently available database options -#[derive(Debug, Clone)] -pub enum DBType { - Memory, - RocksDB, -} - pub enum DBColumn { Block, State, @@ -63,10 +52,10 @@ impl<'a> Into<&'a str> for DBColumn { } } -pub trait DBRecord: DBEncode + DBDecode { +pub trait StorableItem: DBEncode + DBDecode { fn db_column() -> DBColumn; - fn db_put(&self, store: &impl StoreDB, key: &Hash256) -> Result<(), Error> { + fn db_put(&self, store: &impl Store, key: &Hash256) -> Result<(), Error> { let column = Self::db_column().into(); let key = key.as_bytes(); @@ -75,7 +64,7 @@ pub trait DBRecord: DBEncode + DBDecode { .map_err(|e| e.into()) } - fn db_get(store: &impl StoreDB, key: &Hash256) -> Result, Error> { + fn db_get(store: &impl Store, key: &Hash256) -> Result, Error> { let column = Self::db_column().into(); let key = key.as_bytes(); @@ -88,14 +77,14 @@ pub trait DBRecord: DBEncode + DBDecode { } } - fn db_exists(store: &impl StoreDB, key: &Hash256) -> Result { + fn db_exists(store: &impl Store, key: &Hash256) -> Result { let column = Self::db_column().into(); let key = key.as_bytes(); store.key_exists(column, key) } - fn db_delete(store: &impl StoreDB, key: &Hash256) -> Result<(), Error> { + fn db_delete(store: &impl Store, key: &Hash256) -> Result<(), Error> { let column = Self::db_column().into(); let key = key.as_bytes(); @@ -116,7 +105,7 @@ mod tests { b: u64, } - impl DBRecord for StorableThing { + impl StorableItem for StorableThing { fn db_column() -> DBColumn { DBColumn::Block } diff --git a/beacon_node/db2/src/memory_db.rs b/beacon_node/db2/src/memory_db.rs index bc736e525..83ff77ce1 100644 --- a/beacon_node/db2/src/memory_db.rs +++ b/beacon_node/db2/src/memory_db.rs @@ -1,4 +1,4 @@ -use super::{DBValue, Error, StoreDB}; +use super::{DBValue, Error, Store}; use parking_lot::RwLock; use std::collections::HashMap; @@ -22,7 +22,7 @@ impl MemoryDB { } } -impl StoreDB for MemoryDB { +impl Store for MemoryDB { /// 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, Error> { let column_key = MemoryDB::get_key_for_col(col, key);