diff --git a/bin/reth/src/commands/p2p/mod.rs b/bin/reth/src/commands/p2p/mod.rs index a96ef8ac1..b70c84845 100644 --- a/bin/reth/src/commands/p2p/mod.rs +++ b/bin/reth/src/commands/p2p/mod.rs @@ -12,7 +12,7 @@ use crate::{ use backon::{ConstantBuilder, Retryable}; use clap::{Parser, Subcommand}; use reth_config::Config; -use reth_db::open_db; +use reth_db::create_db; use reth_discv4::NatResolver; use reth_interfaces::p2p::bodies::client::BodiesClient; use reth_primitives::{BlockHashOrNumber, ChainSpec, NodeRecord}; @@ -100,7 +100,7 @@ impl Command { /// Execute `p2p` command pub async fn execute(&self) -> eyre::Result<()> { let tempdir = tempfile::TempDir::new()?; - let noop_db = Arc::new(open_db(&tempdir.into_path(), self.db.database_args())?); + let noop_db = Arc::new(create_db(tempdir.into_path(), self.db.database_args())?); // add network name to data dir let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain); diff --git a/crates/storage/db/src/lib.rs b/crates/storage/db/src/lib.rs index 938a94d46..c0737cc42 100644 --- a/crates/storage/db/src/lib.rs +++ b/crates/storage/db/src/lib.rs @@ -92,9 +92,9 @@ use crate::mdbx::DatabaseArguments; use eyre::WrapErr; use std::path::Path; -/// 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 { +/// 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 { use crate::version::{check_db_version_file, create_db_version_file, DatabaseVersionError}; let rpath = path.as_ref(); @@ -109,11 +109,26 @@ pub fn init_db>(path: P, args: DatabaseArguments) -> eyre::Result Err(err) => return Err(err.into()), } } + #[cfg(feature = "mdbx")] { - let db = DatabaseEnv::open(rpath, DatabaseEnvKind::RW, args.clone())?; + Ok(DatabaseEnv::open(rpath, DatabaseEnvKind::RW, args)?) + } + #[cfg(not(feature = "mdbx"))] + { + unimplemented!(); + } +} + +/// 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 { + #[cfg(feature = "mdbx")] + { + let client_version = args.client_version().clone(); + let db = create_db(path, args)?; db.create_tables()?; - db.record_client_version(args.client_version().clone())?; + db.record_client_version(client_version)?; Ok(db) } #[cfg(not(feature = "mdbx"))]