chore: make eyre optional in reth-db (#9351)

This commit is contained in:
DaniPopes
2024-07-06 20:26:43 +02:00
committed by GitHub
parent a4ba294fa5
commit 3b976bc9f5
2 changed files with 19 additions and 21 deletions

View File

@ -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 = []

View File

@ -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<P: AsRef<Path>>(path: P, args: DatabaseArguments) -> eyre::Result<DatabaseEnv> {
@ -31,21 +31,17 @@ pub fn create_db<P: AsRef<Path>>(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<P: AsRef<Path>>(path: P, args: DatabaseArguments) -> eyre::Result<DatabaseEnv> {
{
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> {
{
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