diff --git a/slasher/src/database/interface.rs b/slasher/src/database/interface.rs index 1d51b443eb2..73638f7c986 100644 --- a/slasher/src/database/interface.rs +++ b/slasher/src/database/interface.rs @@ -34,8 +34,6 @@ pub enum Database<'env> { Mdbx(mdbx_impl::Database<'env>), #[cfg(feature = "lmdb")] Lmdb(lmdb_impl::Database<'env>), - #[cfg(feature = "redb")] - Redb(redb_impl::Database<'env>), Disabled(PhantomData<&'env ()>), } diff --git a/slasher/src/database/lmdb_impl.rs b/slasher/src/database/lmdb_impl.rs index ecf41a2f6cb..98839fcc46c 100644 --- a/slasher/src/database/lmdb_impl.rs +++ b/slasher/src/database/lmdb_impl.rs @@ -101,7 +101,7 @@ impl Environment { } impl<'env> RwTransaction<'env> { - pub fn x + ?Sized>( + pub fn get + ?Sized>( &'env self, db: &Database<'env>, key: &K, diff --git a/slasher/src/database/redb_impl.rs b/slasher/src/database/redb_impl.rs index 8f58e32c077..d2f3bb41c06 100644 --- a/slasher/src/database/redb_impl.rs +++ b/slasher/src/database/redb_impl.rs @@ -1,14 +1,7 @@ #![cfg(feature = "redb")] -use redb::{TableDefinition, ReadableTable}; - -use crate::config::Config; -use crate::database::{interface::OpenDatabases, *}; -use crate::Error; use std::marker::PhantomData; -use std::path::PathBuf; - -const TABLE: TableDefinition = TableDefinition::new("data"); +use crate::config::{Config}; pub struct Builder { builder: redb::Builder, @@ -17,104 +10,21 @@ pub struct Builder { #[derive(Debug)] pub struct Database<'db> { db: redb::Database, - _phantom: PhantomData<&'db ()>, + _phantom: PhantomData<&'db ()> } -pub struct RwTransaction<'db> { +pub struct WriteTransaction<'db> { txn: redb::WriteTransaction<'db>, } pub struct Table<'db, 'txn, K: redb::RedbKey + 'static, V: redb::RedbValue + 'static> { - table: redb::Table<'db, 'txn, K, V>, + table: redb::Table<'db, 'txn, K, V> } impl Builder { pub fn new(config: &Config) -> Builder { let builder = redb::Builder::new(); - Builder { builder } - } -} - -pub struct Environment { - builder: redb::Builder, - dbi_open_mutex: Mutex, - max_num_dbs: u32, - database_path: PathBuf, -} - -impl Environment { - pub fn new(config: &Config) -> Result { - let builder = redb::Builder::new(); - let mutex = Mutex::new(0); - Ok(Environment { - builder, - dbi_open_mutex: mutex, - max_num_dbs: MAX_NUM_DBS as u32, - database_path: config.database_path.clone(), - }) - } - - pub fn create_database(&self, name: &str) -> Result { - match self.builder.create(self.database_path.join(name)) { - Ok(database) => Ok(database), - Err(_) => { - panic!("Failed to create db") - } - } - } - - pub fn create_databases(&self) -> Result { - let mutex = self.dbi_open_mutex.lock(); - let indexed_attestation_db = self.create_database(INDEXED_ATTESTATION_DB).unwrap(); - let indexed_attestation_id_db = self.create_database(INDEXED_ATTESTATION_ID_DB).unwrap(); - let attesters_db = self.create_database(ATTESTERS_DB).unwrap(); - let attesters_max_targets_db = self.create_database(ATTESTERS_MAX_TARGETS_DB).unwrap(); - let min_targets_db = self.create_database(MIN_TARGETS_DB).unwrap(); - let max_targets_db = self.create_database(MAX_TARGETS_DB).unwrap(); - let current_epochs_db = self.create_database(CURRENT_EPOCHS_DB).unwrap(); - let proposers_db = self.create_database(PROPOSERS_DB).unwrap(); - let metadata_db = self.create_database(METADATA_DB).unwrap(); - - drop(mutex); - - let wrap = |db| { - crate::Database::Redb(Database { - db, - _phantom: PhantomData, - }) - }; - - Ok(OpenDatabases { - indexed_attestation_db: wrap(indexed_attestation_db), - indexed_attestation_id_db: wrap(indexed_attestation_id_db), - attesters_db: wrap(attesters_db), - attesters_max_targets_db: wrap(attesters_max_targets_db), - min_targets_db: wrap(min_targets_db), - max_targets_db: wrap(max_targets_db), - current_epochs_db: wrap(current_epochs_db), - proposers_db: wrap(proposers_db), - metadata_db: wrap(metadata_db), - }) - } - - pub fn begin_rw_txn(&self) -> Result { - todo!() + Builder{ builder } } - - pub fn filenames(&self, config: &Config) -> Vec { - todo!() - } -} - -impl<'db> RwTransaction<'db> { - pub fn get>( - &'db self, - db: &Database<'db>, - key: &K, - ) { - let tx = db.db.begin_read().unwrap(); - let table = tx.open_table(TABLE).unwrap(); - table.get(*key.clone()); - } -} +} \ No newline at end of file