From 3f509fdfe06d6e48379eb8dcd4b5d32bcbf68216 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Thu, 18 Jul 2024 12:14:21 +0800 Subject: [PATCH 1/3] chore(reth-db): no_std support --- Cargo.toml | 2 +- crates/storage/db/Cargo.toml | 20 ++++++++++++-------- crates/storage/db/src/lib.rs | 3 +++ crates/storage/db/src/tables/mod.rs | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b81e5f5962c7..050fa756d127 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -451,7 +451,7 @@ humantime-serde = "1.1" rand = "0.8.5" rustc-hash = { version = "2.0", default-features = false } schnellru = "0.2" -strum = "0.26" +strum = { version = "0.26", default-features = false } rayon = "1.7" itertools = "0.13" parking_lot = "0.12" diff --git a/crates/storage/db/Cargo.toml b/crates/storage/db/Cargo.toml index 117ec5ccc7b6..4c939619cbea 100644 --- a/crates/storage/db/Cargo.toml +++ b/crates/storage/db/Cargo.toml @@ -34,22 +34,22 @@ eyre = { workspace = true, optional = true } # codecs serde = { workspace = true, default-features = false } -# metrics -reth-metrics.workspace = true -metrics.workspace = true +# `metrics` feature +reth-metrics = { workspace = true, optional = true } +metrics = { workspace = true, optional = true } # misc bytes.workspace = true -page_size = "0.6.0" +page_size = { version = "0.6.0", optional = true } thiserror.workspace = true tempfile = { workspace = true, optional = true } derive_more.workspace = true paste.workspace = true -rustc-hash.workspace = true +rustc-hash = { workspace = true, optional = true } sysinfo = { version = "0.30", default-features = false } # arbitrary utils -strum = { workspace = true, features = ["derive"] } +strum = { workspace = true, features = ["derive"], optional = true } [dev-dependencies] # reth libs with arbitrary @@ -76,13 +76,17 @@ paste.workspace = true assert_matches.workspace = true [features] -default = ["mdbx"] -mdbx = ["dep:reth-libmdbx", "dep:eyre"] +default = ["std","mdbx", "metrics"] +mdbx = ["dep:reth-libmdbx", "dep:eyre", "dep:page_size"] +metrics = ["reth-metrics", "dep:metrics", "dep:strum"] test-utils = ["dep:tempfile", "arbitrary"] bench = [] arbitrary = ["reth-primitives/arbitrary", "reth-db-api/arbitrary"] optimism = [] disable-lock = [] +std = ["rustc-hash/std"] +rustc-hash =["dep:rustc-hash"] +strum = ["dep:strum"] [[bench]] name = "hash_keys" diff --git a/crates/storage/db/src/lib.rs b/crates/storage/db/src/lib.rs index e5414b574328..bf3a7f5092b8 100644 --- a/crates/storage/db/src/lib.rs +++ b/crates/storage/db/src/lib.rs @@ -17,9 +17,11 @@ mod implementation; pub mod lockfile; +#[cfg(feature = "metrics")] mod metrics; pub mod static_file; pub mod tables; +#[cfg(feature = "mdbx")] mod utils; pub mod version; @@ -28,6 +30,7 @@ pub mod mdbx; pub use reth_storage_errors::db::{DatabaseError, DatabaseWriteOperation}; pub use tables::*; +#[cfg(feature = "mdbx")] pub use utils::is_database_empty; #[cfg(feature = "mdbx")] diff --git a/crates/storage/db/src/tables/mod.rs b/crates/storage/db/src/tables/mod.rs index c3c0d0b3f8ae..fb64fa86fcf8 100644 --- a/crates/storage/db/src/tables/mod.rs +++ b/crates/storage/db/src/tables/mod.rs @@ -16,6 +16,7 @@ pub mod codecs; mod raw; pub use raw::{RawDupSort, RawKey, RawTable, RawValue, TableRawRow}; +#[cfg(feature = "mdbx")] pub(crate) mod utils; use reth_db_api::{ From e49bf71231fe76d3808907b38de1e785808a591a Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Thu, 18 Jul 2024 12:31:57 +0800 Subject: [PATCH 2/3] fix test --- crates/storage/db/Cargo.toml | 16 ++++++++++------ crates/storage/db/src/lib.rs | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/storage/db/Cargo.toml b/crates/storage/db/Cargo.toml index 4c939619cbea..262d8f6afe90 100644 --- a/crates/storage/db/Cargo.toml +++ b/crates/storage/db/Cargo.toml @@ -76,17 +76,21 @@ paste.workspace = true assert_matches.workspace = true [features] -default = ["std","mdbx", "metrics"] -mdbx = ["dep:reth-libmdbx", "dep:eyre", "dep:page_size"] -metrics = ["reth-metrics", "dep:metrics", "dep:strum"] +default = ["mdbx"] +mdbx = [ + "dep:reth-libmdbx", + "dep:eyre", + "dep:page_size", + "reth-metrics", + "dep:metrics", + "dep:strum", + "dep:rustc-hash", +] test-utils = ["dep:tempfile", "arbitrary"] bench = [] arbitrary = ["reth-primitives/arbitrary", "reth-db-api/arbitrary"] optimism = [] disable-lock = [] -std = ["rustc-hash/std"] -rustc-hash =["dep:rustc-hash"] -strum = ["dep:strum"] [[bench]] name = "hash_keys" diff --git a/crates/storage/db/src/lib.rs b/crates/storage/db/src/lib.rs index bf3a7f5092b8..c16f2b73c4e9 100644 --- a/crates/storage/db/src/lib.rs +++ b/crates/storage/db/src/lib.rs @@ -17,7 +17,7 @@ mod implementation; pub mod lockfile; -#[cfg(feature = "metrics")] +#[cfg(feature = "mdbx")] mod metrics; pub mod static_file; pub mod tables; From e814e310d00c1450a6de716bbf4d7a2274cef1b9 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Thu, 18 Jul 2024 12:49:00 +0800 Subject: [PATCH 3/3] update --- crates/storage/db/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/db/Cargo.toml b/crates/storage/db/Cargo.toml index 262d8f6afe90..9782a592f375 100644 --- a/crates/storage/db/Cargo.toml +++ b/crates/storage/db/Cargo.toml @@ -34,7 +34,7 @@ eyre = { workspace = true, optional = true } # codecs serde = { workspace = true, default-features = false } -# `metrics` feature +# metrics reth-metrics = { workspace = true, optional = true } metrics = { workspace = true, optional = true }