From 40b7a4708c5bdf283f0b7a4e1275817f599ad1a6 Mon Sep 17 00:00:00 2001 From: WillQ Date: Sun, 31 Dec 2023 11:42:37 +0800 Subject: [PATCH] feat: add mdbx feature flag --- bin/silius/Cargo.toml | 2 +- crates/mempool/Cargo.toml | 7 +++++-- crates/mempool/src/lib.rs | 2 ++ crates/mempool/src/mempool.rs | 5 +++++ crates/mempool/src/reputation.rs | 7 ++++++- examples/storage/Cargo.toml | 2 +- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bin/silius/Cargo.toml b/bin/silius/Cargo.toml index ef21acec..d4102cd4 100644 --- a/bin/silius/Cargo.toml +++ b/bin/silius/Cargo.toml @@ -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 } diff --git a/crates/mempool/Cargo.toml b/crates/mempool/Cargo.toml index b97e65d0..308b5fbb 100644 --- a/crates/mempool/Cargo.toml +++ b/crates/mempool/Cargo.toml @@ -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 } @@ -50,3 +50,6 @@ silius-primitives = { workspace = true, features = ["test-utils"] } # misc tempdir = "0.3.7" + +[features] +mdbx = ["dep:reth-db", "dep:reth-libmdbx"] diff --git a/crates/mempool/src/lib.rs b/crates/mempool/src/lib.rs index a90de607..33841c5f 100644 --- a/crates/mempool/src/lib.rs +++ b/crates/mempool/src/lib.rs @@ -2,6 +2,7 @@ #![allow(dead_code)] mod builder; +#[cfg(feature = "mdbx")] mod database; mod memory; mod mempool; @@ -11,6 +12,7 @@ mod utils; pub mod validate; pub use builder::UoPoolBuilder; +#[cfg(feature = "mdbx")] pub use database::{ init_env, tables::{ diff --git a/crates/mempool/src/mempool.rs b/crates/mempool/src/mempool.rs index 09a23ee6..b1689d9b 100644 --- a/crates/mempool/src/mempool.rs +++ b/crates/mempool/src/mempool.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "mdbx")] use crate::DBError; use ethers::{ abi::AbiEncode, @@ -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 for MempoolError { fn from(e: DBError) -> Self { Self::DBError(e) } } +#[cfg(feature = "mdbx")] impl From for MempoolError { fn from(e: reth_db::Error) -> Self { Self::DBError(e.into()) } } +#[cfg(feature = "mdbx")] impl From for DBError { fn from(e: MempoolError) -> Self { match e { diff --git a/crates/mempool/src/reputation.rs b/crates/mempool/src/reputation.rs index aa2b1396..159c839b 100644 --- a/crates/mempool/src/reputation.rs +++ b/crates/mempool/src/reputation.rs @@ -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::{ @@ -9,6 +11,7 @@ use std::{fmt::Debug, ops::Deref, sync::Arc}; #[derive(Debug)] pub enum ReputationOpError { + #[cfg(feature = "mdbx")] DBError(DBError), ReputationError(ReputationError), } @@ -19,12 +22,14 @@ impl From for ReputationOpError { } } +#[cfg(feature = "mdbx")] impl From for ReputationOpError { fn from(value: DBError) -> Self { Self::DBError(value) } } +#[cfg(feature = "mdbx")] impl From for ReputationOpError { fn from(value: reth_db::Error) -> Self { Self::DBError(DBError::DBInternalError(value)) diff --git a/examples/storage/Cargo.toml b/examples/storage/Cargo.toml index 119298ca..8f26be9c 100644 --- a/examples/storage/Cargo.toml +++ b/examples/storage/Cargo.toml @@ -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