From 3b976bc9f5ee7a058604cab6f22d2845dc77b97a Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:26:43 +0200 Subject: [PATCH] chore: make eyre optional in reth-db (#9351) --- crates/storage/db/Cargo.toml | 16 +++++++++------- crates/storage/db/src/mdbx.rs | 24 ++++++++++-------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/crates/storage/db/Cargo.toml b/crates/storage/db/Cargo.toml index 336cc75d2..117ec5ccc 100644 --- a/crates/storage/db/Cargo.toml +++ b/crates/storage/db/Cargo.toml @@ -18,16 +18,19 @@ reth-primitives.workspace = true reth-primitives-traits.workspace = true reth-fs-util.workspace = true reth-storage-errors.workspace = true -reth-libmdbx = { workspace = true, optional = true, features = [ - "return-borrowed", - "read-tx-timeouts", -] } reth-nippy-jar.workspace = true reth-prune-types.workspace = true reth-stages-types.workspace = true reth-tracing.workspace = true reth-trie-common.workspace = true +# mdbx +reth-libmdbx = { workspace = true, optional = true, features = [ + "return-borrowed", + "read-tx-timeouts", +] } +eyre = { workspace = true, optional = true } + # codecs serde = { workspace = true, default-features = false } @@ -41,7 +44,6 @@ page_size = "0.6.0" thiserror.workspace = true tempfile = { workspace = true, optional = true } derive_more.workspace = true -eyre.workspace = true paste.workspace = true rustc-hash.workspace = true sysinfo = { version = "0.30", default-features = false } @@ -75,8 +77,8 @@ assert_matches.workspace = true [features] default = ["mdbx"] -test-utils = ["tempfile", "arbitrary"] -mdbx = ["reth-libmdbx"] +mdbx = ["dep:reth-libmdbx", "dep:eyre"] +test-utils = ["dep:tempfile", "arbitrary"] bench = [] arbitrary = ["reth-primitives/arbitrary", "reth-db-api/arbitrary"] optimism = [] diff --git a/crates/storage/db/src/mdbx.rs b/crates/storage/db/src/mdbx.rs index 328b9caab..d6947e10b 100644 --- a/crates/storage/db/src/mdbx.rs +++ b/crates/storage/db/src/mdbx.rs @@ -1,12 +1,12 @@ //! Bindings for [MDBX](https://libmdbx.dqdkfa.ru/). -pub use crate::implementation::mdbx::*; -pub use reth_libmdbx::*; - use crate::is_database_empty; use eyre::Context; use std::path::Path; +pub use crate::implementation::mdbx::*; +pub use reth_libmdbx::*; + /// Creates a new database at the specified path if it doesn't exist. Does NOT create tables. Check /// [`init_db`]. pub fn create_db>(path: P, args: DatabaseArguments) -> eyre::Result { @@ -31,21 +31,17 @@ pub fn create_db>(path: P, args: DatabaseArguments) -> eyre::Resu /// Opens up an existing database or creates a new one at the specified path. Creates tables if /// necessary. Read/Write mode. pub fn init_db>(path: P, args: DatabaseArguments) -> eyre::Result { - { - let client_version = args.client_version().clone(); - let db = create_db(path, args)?; - db.create_tables()?; - db.record_client_version(client_version)?; - Ok(db) - } + let client_version = args.client_version().clone(); + let db = create_db(path, args)?; + db.create_tables()?; + db.record_client_version(client_version)?; + Ok(db) } /// Opens up an existing database. Read only mode. It doesn't create it or create tables if missing. pub fn open_db_read_only(path: &Path, args: DatabaseArguments) -> eyre::Result { - { - DatabaseEnv::open(path, DatabaseEnvKind::RO, args) - .with_context(|| format!("Could not open database at path: {}", path.display())) - } + DatabaseEnv::open(path, DatabaseEnvKind::RO, args) + .with_context(|| format!("Could not open database at path: {}", path.display())) } /// Opens up an existing database. Read/Write mode with `WriteMap` enabled. It doesn't create it or