Skip to content

Commit

Permalink
feat: add mdbx feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Dec 31, 2023
1 parent a84cb80 commit 40b7a47
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/silius/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ homepage = "https://github.com/silius-rs/silius/tree/main/bin/silius"
silius-bundler = { workspace = true }
silius-contracts = { workspace = true }
silius-grpc = { workspace = true }
silius-mempool = { workspace = true }
silius-mempool = { workspace = true , features = ["mdbx"]}
silius-p2p = { workspace = true }
silius-primitives = { workspace = true }
silius-rpc = { workspace = true }
Expand Down
7 changes: 5 additions & 2 deletions crates/mempool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ alloy-chains = { workspace = true }
ethers = { workspace = true }

# reth
reth-db = { git = "https://github.com/paradigmxyz/reth.git", rev = "aa6f2cb0610fb4fa0926b42cfed7f8ff51e0db8a" }
reth-libmdbx = { git = "https://github.com/paradigmxyz/reth.git", rev = "aa6f2cb0610fb4fa0926b42cfed7f8ff51e0db8a" }
reth-db = { git = "https://github.com/paradigmxyz/reth.git", rev = "aa6f2cb0610fb4fa0926b42cfed7f8ff51e0db8a", optional = true }
reth-libmdbx = { git = "https://github.com/paradigmxyz/reth.git", rev = "aa6f2cb0610fb4fa0926b42cfed7f8ff51e0db8a", optional = true }

# async
async-trait = { workspace = true }
Expand Down Expand Up @@ -50,3 +50,6 @@ silius-primitives = { workspace = true, features = ["test-utils"] }

# misc
tempdir = "0.3.7"

[features]
mdbx = ["dep:reth-db", "dep:reth-libmdbx"]
2 changes: 2 additions & 0 deletions crates/mempool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(dead_code)]

mod builder;
#[cfg(feature = "mdbx")]
mod database;
mod memory;
mod mempool;
Expand All @@ -11,6 +12,7 @@ mod utils;
pub mod validate;

pub use builder::UoPoolBuilder;
#[cfg(feature = "mdbx")]
pub use database::{
init_env,
tables::{
Expand Down
5 changes: 5 additions & 0 deletions crates/mempool/src/mempool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "mdbx")]
use crate::DBError;
use ethers::{
abi::AbiEncode,
Expand All @@ -18,21 +19,25 @@ pub fn mempool_id(ep: &Address, chain_id: &U256) -> MempoolId {

#[derive(Debug)]
pub enum MempoolError {
#[cfg(feature = "mdbx")]
DBError(DBError),
}

#[cfg(feature = "mdbx")]
impl From<DBError> for MempoolError {
fn from(e: DBError) -> Self {
Self::DBError(e)
}
}

#[cfg(feature = "mdbx")]
impl From<reth_db::Error> for MempoolError {
fn from(e: reth_db::Error) -> Self {
Self::DBError(e.into())
}
}

#[cfg(feature = "mdbx")]
impl From<MempoolError> for DBError {
fn from(e: MempoolError) -> Self {
match e {
Expand Down
7 changes: 6 additions & 1 deletion crates/mempool/src/reputation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{mempool::ClearOp, DBError};
use crate::mempool::ClearOp;
#[cfg(feature = "mdbx")]
use crate::DBError;
use ethers::types::{Address, Bytes, U256};
use parking_lot::RwLock;
use silius_primitives::{
Expand All @@ -9,6 +11,7 @@ use std::{fmt::Debug, ops::Deref, sync::Arc};

#[derive(Debug)]
pub enum ReputationOpError {
#[cfg(feature = "mdbx")]
DBError(DBError),
ReputationError(ReputationError),
}
Expand All @@ -19,12 +22,14 @@ impl From<ReputationError> for ReputationOpError {
}
}

#[cfg(feature = "mdbx")]
impl From<DBError> for ReputationOpError {
fn from(value: DBError) -> Self {
Self::DBError(value)
}
}

#[cfg(feature = "mdbx")]
impl From<reth_db::Error> for ReputationOpError {
fn from(value: reth_db::Error) -> Self {
Self::DBError(DBError::DBInternalError(value))
Expand Down
2 changes: 1 addition & 1 deletion examples/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ homepage = "https://github.com/silius-rs/silius/tree/main/examples/storage"
[dependencies]
# silius dependencies
silius-contracts = { workspace = true } # replace with git url: git = "https://github.com/silius-rs/silius.git"
silius-mempool = { workspace = true } # replace with git url: git = "https://github.com/silius-rs/silius.git"
silius-mempool = { workspace = true, features = ["mdbx"] } # replace with git url: git = "https://github.com/silius-rs/silius.git"
silius-primitives = { workspace = true } # replace with git url: git = "https://github.com/silius-rs/silius.git"

# eth
Expand Down

0 comments on commit 40b7a47

Please sign in to comment.