Skip to content

Commit

Permalink
Replace redb with parity-db
Browse files Browse the repository at this point in the history
It still has much better compile times yet doesn't block when creating multiple
transactions. It also is actively maintained and doesn't grow our tree. The MPT
aspects are irrelevant.
  • Loading branch information
kayabaNerve committed Nov 30, 2023
1 parent 3b7bc5a commit ca17342
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 86 deletions.
11 changes: 1 addition & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions common/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
redb = { version = "1", default-features = false, optional = true }
parity-db = { version = "0.4", default-features = false, optional = true }
rocksdb = { version = "0.21", default-features = false, features = ["lz4"], optional = true }

[features]
redb = ["dep:redb"]
parity-db = ["dep:parity-db"]
rocksdb = ["dep:rocksdb"]
8 changes: 4 additions & 4 deletions common/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ mod rocks;
#[cfg(feature = "rocksdb")]
pub use rocks::{RocksDB, new_rocksdb};

#[cfg(feature = "redb")]
mod redb;
#[cfg(feature = "redb")]
pub use redb::{Redb, new_redb};
#[cfg(feature = "parity_db")]
mod parity_db;
#[cfg(feature = "parity_db")]
pub use parity_db::{ParityDb, new_parity_db};

/// An object implementing get.
pub trait Get {
Expand Down
41 changes: 41 additions & 0 deletions common/db/src/parity_db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::sync::Arc;

pub use ::parity_db::Db as ParityDb;
use ::redb::*;

use crate::*;

pub struct Transaction<'a>(&'a Arc<ParityDb>, Vec<(u8, Vec<u8>, Option<Vec<u8>>)>);

impl Get for Transaction<'_> {
fn get(&self, key: impl AsRef<[u8]>) -> Option<Vec<u8>> {
self.0.get(key)
}
}
impl DbTxn for Transaction<'_> {
fn put(&mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>) {
self.1.push((0, key.as_ref().to_vec(), Some(value.as_ref().to_vec())))
}
fn del(&mut self, key: impl AsRef<[u8]>) {
self.1.push((0, key.as_ref().to_vec(), None))
}
fn commit(self) {
self.0.commit(self.1).unwrap()
}
}

impl Get for Arc<ParityDb> {
fn get(&self, key: impl AsRef<[u8]>) -> Option<Vec<u8>> {
ParityDb::get(&*self, 0, key.as_ref()).unwrap()
}
}
impl Db for Arc<ParityDb> {
type Transaction<'a> = Transaction<'a>;
fn txn(&mut self) -> Self::Transaction<'_> {
Transaction(self, vec![])
}
}

pub fn new_parity_db(path: &str) -> Arc<ParityDb> {
Arc::new(ParityDb::open_or_crate(Options::with_columns(path, 1)).unwrap())
}
46 changes: 0 additions & 46 deletions common/db/src/redb.rs

This file was deleted.

2 changes: 1 addition & 1 deletion coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ sp-application-crypto = { git = "https://github.com/serai-dex/substrate", defaul
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false, features = ["std"] }

[features]
redb = ["serai-db/redb"]
parity-db = ["serai-db/parity-db"]
rocksdb = ["serai-db/rocksdb"]
9 changes: 5 additions & 4 deletions coordinator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,10 +1200,11 @@ async fn main() {

#[allow(unused_variables, unreachable_code)]
let db = {
#[cfg(all(feature = "redb", feature = "rocksdb"))]
panic!("built with redb and rocksdb");
#[cfg(all(feature = "redb", not(feature = "rocksdb")))]
let db = serai_db::new_redb(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
#[cfg(all(feature = "parity-db", feature = "rocksdb"))]
panic!("built with parity-db and rocksdb");
#[cfg(all(feature = "parity-db", not(feature = "rocksdb")))]
let db =
serai_db::new_parity_db(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
#[cfg(feature = "rocksdb")]
let db =
serai_db::new_rocksdb(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
Expand Down
2 changes: 1 addition & 1 deletion message-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ serai-env = { path = "../common/env" }
serai-primitives = { path = "../substrate/primitives", features = ["borsh"] }

[features]
redb = ["serai-db/redb"]
parity-db = ["serai-db/parity-db"]
rocksdb = ["serai-db/rocksdb"]
11 changes: 6 additions & 5 deletions message-queue/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) use crate::messages::*;

pub(crate) use crate::queue::Queue;

#[cfg(all(feature = "redb", not(feature = "rocksdb")))]
#[cfg(all(feature = "parity-db", not(feature = "rocksdb")))]
pub(crate) type Db = Arc<serai_db::Redb>;
#[cfg(feature = "rocksdb")]
pub(crate) type Db = serai_db::RocksDB;
Expand Down Expand Up @@ -166,10 +166,11 @@ async fn main() {
// Open the DB
#[allow(unused_variables, unreachable_code)]
let db = {
#[cfg(all(feature = "redb", feature = "rocksdb"))]
panic!("built with redb and rocksdb");
#[cfg(all(feature = "redb", not(feature = "rocksdb")))]
let db = serai_db::new_redb(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
#[cfg(all(feature = "parity-db", feature = "rocksdb"))]
panic!("built with parity-db and rocksdb");
#[cfg(all(feature = "parity-db", not(feature = "rocksdb")))]
let db =
serai_db::new_parity_db(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
#[cfg(feature = "rocksdb")]
let db =
serai_db::new_rocksdb(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
Expand Down
2 changes: 1 addition & 1 deletion orchestration/coordinator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN --mount=type=cache,target=/root/.cargo \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/serai/target \
mkdir /serai/bin && \
cargo build -p serai-coordinator --features redb && \
cargo build -p serai-coordinator --features parity-db && \
mv /serai/target/debug/serai-coordinator /serai/bin
FROM debian:bookworm-slim as image

Expand Down
2 changes: 1 addition & 1 deletion orchestration/coordinator/Dockerfile.coordinator
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cargo build -p serai-coordinator --features redb && \
cargo build -p serai-coordinator --features parity-db && \
mv /serai/target/debug/serai-coordinator /serai/bin
2 changes: 1 addition & 1 deletion orchestration/message-queue/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN --mount=type=cache,target=/root/.cargo \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/serai/target \
mkdir /serai/bin && \
cargo build --features redb -p serai-message-queue && \
cargo build --features parity-db -p serai-message-queue && \
mv /serai/target/debug/serai-message-queue /serai/bin
FROM debian:bookworm-slim as image

Expand Down
2 changes: 1 addition & 1 deletion orchestration/message-queue/Dockerfile.message-queue
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cargo build --features redb -p serai-message-queue && \
cargo build --features parity-db -p serai-message-queue && \
mv /serai/target/debug/serai-message-queue /serai/bin
2 changes: 1 addition & 1 deletion orchestration/processor/bitcoin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN --mount=type=cache,target=/root/.cargo \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/serai/target \
mkdir /serai/bin && \
cargo build --features "binaries redb bitcoin" -p serai-processor && \
cargo build --features "binaries parity-db bitcoin" -p serai-processor && \
mv /serai/target/debug/serai-processor /serai/bin
FROM debian:bookworm-slim as image

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cargo build --features "binaries redb bitcoin" -p serai-processor && \
cargo build --features "binaries parity-db bitcoin" -p serai-processor && \
mv /serai/target/debug/serai-processor /serai/bin
2 changes: 1 addition & 1 deletion orchestration/processor/monero/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN --mount=type=cache,target=/root/.cargo \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/serai/target \
mkdir /serai/bin && \
cargo build --features "binaries redb monero" -p serai-processor && \
cargo build --features "binaries parity-db monero" -p serai-processor && \
mv /serai/target/debug/serai-processor /serai/bin
FROM debian:bookworm-slim as image

Expand Down
2 changes: 1 addition & 1 deletion orchestration/processor/monero/Dockerfile.processor.monero
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cargo build --features "binaries redb monero" -p serai-processor && \
cargo build --features "binaries parity-db monero" -p serai-processor && \
mv /serai/target/debug/serai-processor /serai/bin
2 changes: 1 addition & 1 deletion processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ ed25519 = ["dalek-ff-group", "frost/ed25519"]
monero = ["ed25519", "monero-serai", "serai-client/monero"]

binaries = ["env_logger", "serai-env", "messages", "message-queue"]
redb = ["serai-db/redb"]
parity-db = ["serai-db/parity-db"]
rocksdb = ["serai-db/rocksdb"]
9 changes: 5 additions & 4 deletions processor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,11 @@ async fn main() {

#[allow(unused_variables, unreachable_code)]
let db = {
#[cfg(all(feature = "redb", feature = "rocksdb"))]
panic!("built with redb and rocksdb");
#[cfg(all(feature = "redb", not(feature = "rocksdb")))]
let db = serai_db::new_redb(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
#[cfg(all(feature = "parity-db", feature = "rocksdb"))]
panic!("built with parity-db and rocksdb");
#[cfg(all(feature = "parity-db", not(feature = "rocksdb")))]
let db =
serai_db::new_parity_db(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
#[cfg(feature = "rocksdb")]
let db =
serai_db::new_rocksdb(&serai_env::var("DB_PATH").expect("path to DB wasn't specified"));
Expand Down

0 comments on commit ca17342

Please sign in to comment.