From c9d8ef08b7aa21ad032dd5e91691937b33831890 Mon Sep 17 00:00:00 2001 From: Rahul Dogra Date: Sat, 24 Jun 2023 23:33:55 +0530 Subject: [PATCH] redb setup --- Cargo.lock | 26 ++++++++++++++++++++++++++ slasher/Cargo.toml | 4 +++- slasher/src/database.rs | 1 + slasher/src/database/interface.rs | 2 ++ slasher/src/database/redb_impl.rs | 30 ++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 slasher/src/database/redb_impl.rs diff --git a/Cargo.lock b/Cargo.lock index 82391837104..0defaf44c4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6445,6 +6445,16 @@ dependencies = [ "unescape", ] +[[package]] +name = "pyo3-build-config" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713eccf888fb05f1a96eb78c0dbc51907fee42b3377272dc902eb38985f418d5" +dependencies = [ + "once_cell", + "target-lexicon", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -6681,6 +6691,15 @@ dependencies = [ "yasna", ] +[[package]] +name = "redb" +version = "1.0.0" +source = "git+https://github.com/Gua00va/redb?rev=93280c5#93280c54440ec3bdd00c9449b1edbb0a5e75e669" +dependencies = [ + "libc", + "pyo3-build-config", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -7575,6 +7594,7 @@ dependencies = [ "parking_lot 0.12.1", "rand 0.8.5", "rayon", + "redb", "safe_arith", "serde", "serde_derive", @@ -8151,6 +8171,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "target-lexicon" +version = "0.12.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1c7f239eb94671427157bd93b3694320f3668d4e1eff08c7285366fd777fac" + [[package]] name = "target_check" version = "0.1.0" diff --git a/slasher/Cargo.toml b/slasher/Cargo.toml index bfa7b5f64c5..a916ddafddb 100644 --- a/slasher/Cargo.toml +++ b/slasher/Cargo.toml @@ -5,9 +5,10 @@ authors = ["Michael Sproul "] edition = "2021" [features] -default = ["lmdb"] +default = ["redb"] mdbx = ["dep:mdbx"] lmdb = ["lmdb-rkv", "lmdb-rkv-sys"] +redb = ["dep:redb"] [dependencies] bincode = "1.3.1" @@ -35,6 +36,7 @@ strum = { version = "0.24.1", features = ["derive"] } mdbx = { package = "libmdbx", git = "https://github.com/sigp/libmdbx-rs", tag = "v0.1.4", optional = true } lmdb-rkv = { git = "https://github.com/sigp/lmdb-rs", rev = "f33845c6469b94265319aac0ed5085597862c27e", optional = true } lmdb-rkv-sys = { git = "https://github.com/sigp/lmdb-rs", rev = "f33845c6469b94265319aac0ed5085597862c27e", optional = true } +redb = { git = "https://github.com/Gua00va/redb", rev = "93280c5", optional = true } [dev-dependencies] maplit = "1.0.2" diff --git a/slasher/src/database.rs b/slasher/src/database.rs index 49d2b00a4cd..4b5081ced42 100644 --- a/slasher/src/database.rs +++ b/slasher/src/database.rs @@ -1,6 +1,7 @@ pub mod interface; mod lmdb_impl; mod mdbx_impl; +mod redb_impl; use crate::{ metrics, AttesterRecord, AttesterSlashingStatus, CompactAttesterRecord, Config, Error, diff --git a/slasher/src/database/interface.rs b/slasher/src/database/interface.rs index 5bb920383c3..73638f7c986 100644 --- a/slasher/src/database/interface.rs +++ b/slasher/src/database/interface.rs @@ -7,6 +7,8 @@ use std::path::PathBuf; use crate::database::lmdb_impl; #[cfg(feature = "mdbx")] use crate::database::mdbx_impl; +#[cfg(feature = "redb")] +use crate::database::redb_impl; #[derive(Debug)] pub enum Environment { diff --git a/slasher/src/database/redb_impl.rs b/slasher/src/database/redb_impl.rs new file mode 100644 index 00000000000..d2f3bb41c06 --- /dev/null +++ b/slasher/src/database/redb_impl.rs @@ -0,0 +1,30 @@ +#![cfg(feature = "redb")] + +use std::marker::PhantomData; +use crate::config::{Config}; + +pub struct Builder { + builder: redb::Builder, +} + +#[derive(Debug)] +pub struct Database<'db> { + db: redb::Database, + _phantom: PhantomData<&'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> +} + +impl Builder { + pub fn new(config: &Config) -> Builder { + let builder = redb::Builder::new(); + + Builder{ builder } + } +} \ No newline at end of file