feat(cli): override static files datadir (#7212)

Co-authored-by: Oliver Nordbjerg <onbjerg@users.noreply.github.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
Co-authored-by: Oliver Nordbjerg <hi@notbjerg.me>
This commit is contained in:
back
2024-06-03 09:47:15 -07:00
committed by GitHub
parent 994f98f12d
commit 4522fd8baf
50 changed files with 460 additions and 646 deletions

View File

@ -5,7 +5,6 @@ use crate::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
utils::DbTool,
};
use clap::{Parser, Subcommand};
@ -13,6 +12,7 @@ use reth_db::{
open_db, open_db_read_only,
version::{get_db_version, DatabaseVersionError, DB_VERSION},
};
use reth_node_core::args::DatadirArgs;
use reth_primitives::ChainSpec;
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
use std::{
@ -32,16 +32,6 @@ mod tui;
/// `reth db` command
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t, global = true)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -55,6 +45,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -105,7 +98,7 @@ impl Command {
/// Execute `db` command
pub async fn execute(self) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
let db_args = self.db.database_args();
let static_files_path = data_dir.static_files();
@ -205,7 +198,7 @@ mod tests {
#[test]
fn parse_stats_globals() {
let path = format!("../{}", SUPPORTED_CHAINS[0]);
let cmd = Command::try_parse_from(["reth", "stats", "--datadir", &path]).unwrap();
assert_eq!(cmd.datadir.as_ref(), Some(Path::new(&path)));
let cmd = Command::try_parse_from(["reth", "--datadir", &path, "stats"]).unwrap();
assert_eq!(cmd.datadir.resolve_datadir(cmd.chain.chain).as_ref(), Path::new(&path));
}
}

View File

@ -3,9 +3,8 @@
use crate::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
DatabaseArgs, DatadirArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
};
use alloy_rlp::Decodable;
@ -53,16 +52,6 @@ use tracing::*;
/// The script will then parse the block and attempt to build a similar one.
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -75,6 +64,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
/// Database arguments.
#[command(flatten)]
db: DatabaseArgs,
@ -145,7 +137,7 @@ impl Command {
/// Execute `debug in-memory-merkle` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
fs::create_dir_all(&db_path)?;

View File

@ -4,9 +4,8 @@ use crate::{
args::{
get_secret_key,
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, NetworkArgs,
DatabaseArgs, DatadirArgs, NetworkArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
utils::get_single_header,
};
@ -48,16 +47,6 @@ use tracing::*;
/// `reth debug execution` command
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -70,6 +59,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
network: NetworkArgs,
@ -165,7 +157,7 @@ impl Command {
self.network.discovery.addr,
self.network.discovery.port,
))
.build(provider_factory.clone())
.build(provider_factory)
.start_network()
.await?;
info!(target: "reth::cli", peer_id = %network.peer_id(), local_addr = %network.local_addr(), "Connected to P2P network");
@ -196,7 +188,7 @@ impl Command {
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
let mut config = Config::default();
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
// Make sure ETL doesn't default to /tmp/, but to whatever datadir is set to

View File

@ -4,9 +4,8 @@ use crate::{
args::{
get_secret_key,
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, NetworkArgs,
DatabaseArgs, DatadirArgs, NetworkArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
utils::{get_single_body, get_single_header},
};
@ -38,16 +37,6 @@ use tracing::*;
/// merkle root for it.
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -60,6 +49,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -107,7 +99,7 @@ impl Command {
let config = Config::default();
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
fs::create_dir_all(&db_path)?;

View File

@ -4,9 +4,8 @@ use crate::{
args::{
get_secret_key,
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, NetworkArgs,
DatabaseArgs, DatadirArgs, NetworkArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
utils::get_single_header,
};
@ -40,16 +39,6 @@ use tracing::*;
/// `reth debug merkle` command
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -62,6 +51,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -100,7 +92,7 @@ impl Command {
self.network.discovery.addr,
self.network.discovery.port,
))
.build(provider_factory.clone())
.build(provider_factory)
.start_network()
.await?;
info!(target: "reth::cli", peer_id = %network.peer_id(), local_addr = %network.local_addr(), "Connected to P2P network");
@ -113,7 +105,7 @@ impl Command {
let config = Config::default();
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
fs::create_dir_all(&db_path)?;

View File

@ -2,9 +2,8 @@ use crate::{
args::{
get_secret_key,
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, NetworkArgs,
DatabaseArgs, DatadirArgs, NetworkArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
};
use clap::Parser;
@ -41,16 +40,6 @@ use tracing::*;
/// It does not require
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -63,6 +52,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -97,7 +89,7 @@ impl Command {
self.network.discovery.addr,
self.network.discovery.port,
))
.build(provider_factory.clone())
.build(provider_factory)
.start_network()
.await?;
info!(target: "reth::cli", peer_id = %network.peer_id(), local_addr = %network.local_addr(), "Connected to P2P network");
@ -110,7 +102,7 @@ impl Command {
let config = Config::default();
// Add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
fs::create_dir_all(&db_path)?;

View File

@ -3,9 +3,8 @@
use crate::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
DatabaseArgs, DatadirArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
version::SHORT_VERSION,
};
@ -46,16 +45,6 @@ pub struct ImportCommand {
#[arg(long, value_name = "FILE", verbatim_doc_comment)]
config: Option<PathBuf>,
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -76,6 +65,9 @@ pub struct ImportCommand {
#[arg(long, value_name = "CHUNK_LEN", verbatim_doc_comment)]
chunk_len: Option<u64>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -102,7 +94,7 @@ impl ImportCommand {
);
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.resolve_datadir(self.chain.chain);
let config_path = self.config.clone().unwrap_or_else(|| data_dir.config());
let mut config: Config = load_config(config_path.clone())?;

View File

@ -7,7 +7,6 @@ use crate::{
DatabaseArgs,
},
commands::import::{build_import_pipeline, load_config},
dirs::{DataDirPath, MaybePlatformPath},
version::SHORT_VERSION,
};
use clap::Parser;
@ -18,6 +17,7 @@ use reth_db_common::init::init_genesis;
use reth_downloaders::file_client::{
ChunkedFileReader, FileClient, DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE,
};
use reth_node_core::args::DatadirArgs;
use reth_optimism_primitives::bedrock_import::is_dup_tx;
use reth_primitives::{stage::StageId, PruneModes};
use reth_provider::{
@ -35,20 +35,13 @@ pub struct ImportOpCommand {
#[arg(long, value_name = "FILE", verbatim_doc_comment)]
config: Option<PathBuf>,
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// Chunk byte length to read from file.
#[arg(long, value_name = "CHUNK_LEN", verbatim_doc_comment)]
chunk_len: Option<u64>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -77,7 +70,7 @@ impl ImportOpCommand {
let chain_spec = genesis_value_parser(SUPPORTED_CHAINS[0])?;
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(chain_spec.chain);
let data_dir = self.datadir.resolve_datadir(chain_spec.chain);
let config_path = self.config.clone().unwrap_or_else(|| data_dir.config());
let mut config: Config = load_config(config_path.clone())?;

View File

@ -12,7 +12,7 @@ use reth_downloaders::{
file_client::{ChunkedFileReader, DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE},
receipt_file_client::ReceiptFileClient,
};
use reth_node_core::version::SHORT_VERSION;
use reth_node_core::{args::DatadirArgs, version::SHORT_VERSION};
use reth_optimism_primitives::bedrock_import::is_dup_tx;
use reth_primitives::{stage::StageId, Receipts, StaticFileSegment};
use reth_provider::{
@ -21,26 +21,16 @@ use reth_provider::{
};
use tracing::{debug, error, info, trace};
use crate::{
args::{
utils::{genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
use crate::args::{
utils::{genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
};
/// Initializes the database with the genesis block.
#[derive(Debug, Parser)]
pub struct ImportReceiptsOpCommand {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
#[command(flatten)]
datadir: DatadirArgs,
/// Chunk byte length to read from file.
#[arg(long, value_name = "CHUNK_LEN", verbatim_doc_comment)]
@ -70,7 +60,7 @@ impl ImportReceiptsOpCommand {
let chain_spec = genesis_value_parser(SUPPORTED_CHAINS[0])?;
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(chain_spec.chain);
let data_dir = self.datadir.resolve_datadir(chain_spec.chain);
let db_path = data_dir.db();
info!(target: "reth::cli", path = ?db_path, "Opening database");

View File

@ -1,11 +1,8 @@
//! Command that initializes the node from a genesis file.
use crate::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
use crate::args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, DatadirArgs,
};
use clap::Parser;
use reth_db::init_db;
@ -18,16 +15,6 @@ use tracing::info;
/// Initializes the database with the genesis block.
#[derive(Debug, Parser)]
pub struct InitCommand {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -40,6 +27,9 @@ pub struct InitCommand {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
}
@ -50,9 +40,9 @@ impl InitCommand {
info!(target: "reth::cli", "reth init starting");
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
info!(target: "reth::cli", path = ?db_path, "Opening database");
info!(target: "reth::cl", path = ?db_path, "Opening database");
let db = Arc::new(init_db(&db_path, self.db.database_args())?);
info!(target: "reth::cli", "Database opened");

View File

@ -1,16 +1,14 @@
//! Command that initializes the node from a genesis file.
use crate::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
use crate::args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
};
use clap::Parser;
use reth_config::config::EtlConfig;
use reth_db::{database::Database, init_db};
use reth_db_common::init::init_from_state_dump;
use reth_node_core::args::DatadirArgs;
use reth_primitives::{ChainSpec, B256};
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
@ -20,16 +18,6 @@ use tracing::info;
/// Initializes the database with the genesis block.
#[derive(Debug, Parser)]
pub struct InitStateCommand {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -42,6 +30,9 @@ pub struct InitStateCommand {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
/// JSONL file with state dump.
///
/// Must contain accounts in following format, additional account fields are ignored. Must
@ -72,7 +63,7 @@ impl InitStateCommand {
info!(target: "reth::cli", "Reth init-state starting");
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
info!(target: "reth::cli", path = ?db_path, "Opening database");
let db = Arc::new(init_db(&db_path, self.db.database_args())?);

View File

@ -1,12 +1,9 @@
//! Main node command for launching a node
use crate::{
args::{
utils::{chain_help, genesis_value_parser, parse_socket_address, SUPPORTED_CHAINS},
DatabaseArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs,
RpcServerArgs, TxPoolArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
use crate::args::{
utils::{chain_help, genesis_value_parser, parse_socket_address, SUPPORTED_CHAINS},
DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs,
RpcServerArgs, TxPoolArgs,
};
use clap::{value_parser, Args, Parser};
use reth_cli_runner::CliContext;
@ -19,16 +16,6 @@ use std::{ffi::OsString, fmt, future::Future, net::SocketAddr, path::PathBuf, sy
/// Start the node
#[derive(Debug, Parser)]
pub struct NodeCommand<Ext: clap::Args + fmt::Debug = NoArgs> {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
pub datadir: MaybePlatformPath<DataDirPath>,
/// The path to the configuration file to use.
#[arg(long, value_name = "FILE", verbatim_doc_comment)]
pub config: Option<PathBuf>,
@ -76,6 +63,10 @@ pub struct NodeCommand<Ext: clap::Args + fmt::Debug = NoArgs> {
#[arg(long, conflicts_with = "instance", global = true)]
pub with_unused_ports: bool,
/// All datadir related arguments
#[command(flatten)]
pub datadir: DatadirArgs,
/// All networking related arguments
#[command(flatten)]
pub network: NetworkArgs,
@ -161,6 +152,7 @@ impl<Ext: clap::Args + fmt::Debug> NodeCommand<Ext> {
// set up node config
let mut node_config = NodeConfig {
datadir,
config,
chain,
metrics,
@ -179,7 +171,7 @@ impl<Ext: clap::Args + fmt::Debug> NodeCommand<Ext> {
// because database init needs it to register metrics.
let _ = node_config.install_prometheus_recorder()?;
let data_dir = datadir.unwrap_or_chain_default(node_config.chain.chain);
let data_dir = node_config.datadir();
let db_path = data_dir.db();
tracing::info!(target: "reth::cli", path = ?db_path, "Opening database");
@ -279,30 +271,32 @@ mod tests {
let cmd =
NodeCommand::try_parse_args_from(["reth", "--config", "my/path/to/reth.toml"]).unwrap();
// always store reth.toml in the data dir, not the chain specific data dir
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let data_dir = cmd.datadir.resolve_datadir(cmd.chain.chain);
let config_path = cmd.config.unwrap_or_else(|| data_dir.config());
assert_eq!(config_path, Path::new("my/path/to/reth.toml"));
let cmd = NodeCommand::try_parse_args_from(["reth"]).unwrap();
// always store reth.toml in the data dir, not the chain specific data dir
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let data_dir = cmd.datadir.resolve_datadir(cmd.chain.chain);
let config_path = cmd.config.clone().unwrap_or_else(|| data_dir.config());
let end = format!("reth/{}/reth.toml", SUPPORTED_CHAINS[0]);
let end = format!("{}/reth.toml", SUPPORTED_CHAINS[0]);
assert!(config_path.ends_with(end), "{:?}", cmd.config);
}
#[test]
fn parse_db_path() {
let cmd = NodeCommand::try_parse_args_from(["reth"]).unwrap();
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let data_dir = cmd.datadir.resolve_datadir(cmd.chain.chain);
let db_path = data_dir.db();
let end = format!("reth/{}/db", SUPPORTED_CHAINS[0]);
assert!(db_path.ends_with(end), "{:?}", cmd.config);
let cmd =
NodeCommand::try_parse_args_from(["reth", "--datadir", "my/custom/path"]).unwrap();
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let data_dir = cmd.datadir.resolve_datadir(cmd.chain.chain);
let db_path = data_dir.db();
assert_eq!(db_path, Path::new("my/custom/path/db"));
}

View File

@ -6,7 +6,6 @@ use crate::{
utils::{chain_help, chain_spec_value_parser, hash_or_num_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, DiscoveryArgs, NetworkArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
utils::get_single_header,
};
use backon::{ConstantBuilder, Retryable};
@ -16,6 +15,7 @@ use reth_config::Config;
use reth_db::create_db;
use reth_network::NetworkConfigBuilder;
use reth_network_p2p::bodies::client::BodiesClient;
use reth_node_core::args::DatadirArgs;
use reth_primitives::{BlockHashOrNumber, ChainSpec};
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
use std::{
@ -43,24 +43,16 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// Disable the discovery service.
#[command(flatten)]
pub network: NetworkArgs,
/// The number of retries per request
#[arg(long, default_value = "5")]
retries: usize,
#[command(flatten)]
network: NetworkArgs,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -91,7 +83,7 @@ impl Command {
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);
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
let config_path = self.config.clone().unwrap_or_else(|| data_dir.config());
let mut config: Config = confy::load_path(&config_path).unwrap_or_default();

View File

@ -1,7 +1,4 @@
use crate::{
args::utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
dirs::{DataDirPath, MaybePlatformPath},
};
use crate::args::utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS};
use clap::Parser;
use reth_cli_runner::CliContext;
use reth_db::{
@ -10,7 +7,7 @@ use reth_db::{
transaction::DbTx,
};
use reth_db_common::init::init_genesis;
use reth_node_core::args::DatabaseArgs;
use reth_node_core::args::{DatabaseArgs, DatadirArgs};
use reth_primitives::ChainSpec;
use reth_provider::{
providers::StaticFileProvider, BlockNumReader, HeaderProvider, ProviderError, ProviderFactory,
@ -22,16 +19,6 @@ use tracing::*;
/// `reth recover storage-tries` command
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -44,6 +31,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
/// All database related arguments
#[command(flatten)]
pub db: DatabaseArgs,
@ -52,7 +42,7 @@ pub struct Command {
impl Command {
/// Execute `storage-tries` recovery command
pub async fn execute(self, _ctx: CliContext) -> eyre::Result<()> {
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
fs::create_dir_all(&db_path)?;
let db = Arc::new(init_db(db_path, self.db.database_args())?);

View File

@ -3,9 +3,8 @@
use crate::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, StageEnum,
DatabaseArgs, DatadirArgs, StageEnum,
},
dirs::{DataDirPath, MaybePlatformPath},
utils::DbTool,
};
use clap::Parser;
@ -25,16 +24,6 @@ use std::sync::Arc;
/// `reth drop-stage` command
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -47,6 +36,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -57,7 +49,7 @@ impl Command {
/// Execute `db` command
pub async fn execute(self) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
fs::create_dir_all(&db_path)?;

View File

@ -1,13 +1,10 @@
//! Database debugging tool
use crate::{
dirs::{DataDirPath, MaybePlatformPath},
utils::DbTool,
};
use crate::{dirs::DataDirPath, utils::DbTool};
use crate::args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
DatabaseArgs, DatadirArgs,
};
use clap::Parser;
use reth_db::{
@ -36,16 +33,6 @@ use merkle::dump_merkle_stage;
/// `reth dump-stage` command
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -58,6 +45,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -101,7 +91,7 @@ impl Command {
/// Execute `dump-stage` command
pub async fn execute(self) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
info!(target: "reth::cli", path = ?db_path, "Opening database");
let db = Arc::new(open_db_read_only(&db_path, self.db.database_args())?);
@ -121,7 +111,7 @@ impl Command {
&tool,
*from,
*to,
output_datadir.with_chain(self.chain.chain),
output_datadir.with_chain(self.chain.chain, self.datadir.clone()),
*dry_run,
)
.await?
@ -131,7 +121,7 @@ impl Command {
&tool,
*from,
*to,
output_datadir.with_chain(self.chain.chain),
output_datadir.with_chain(self.chain.chain, self.datadir.clone()),
*dry_run,
)
.await?
@ -141,7 +131,7 @@ impl Command {
&tool,
*from,
*to,
output_datadir.with_chain(self.chain.chain),
output_datadir.with_chain(self.chain.chain, self.datadir.clone()),
*dry_run,
)
.await?
@ -151,7 +141,7 @@ impl Command {
&tool,
*from,
*to,
output_datadir.with_chain(self.chain.chain),
output_datadir.with_chain(self.chain.chain, self.datadir.clone()),
*dry_run,
)
.await?

View File

@ -6,9 +6,8 @@ use crate::{
args::{
get_secret_key,
utils::{chain_help, chain_spec_value_parser, SUPPORTED_CHAINS},
DatabaseArgs, NetworkArgs, StageEnum,
DatabaseArgs, DatadirArgs, NetworkArgs, StageEnum,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
prometheus_exporter,
version::SHORT_VERSION,
@ -46,16 +45,6 @@ pub struct Command {
#[arg(long, value_name = "FILE", verbatim_doc_comment)]
config: Option<PathBuf>,
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -106,12 +95,6 @@ pub struct Command {
#[arg(long, short)]
skip_unwind: bool,
#[command(flatten)]
network: NetworkArgs,
#[command(flatten)]
db: DatabaseArgs,
/// Commits the changes in the database. WARNING: potentially destructive.
///
/// Useful when you want to run diagnostics on the database.
@ -123,6 +106,15 @@ pub struct Command {
/// Save stage checkpoints
#[arg(long)]
checkpoints: bool,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
network: NetworkArgs,
#[command(flatten)]
db: DatabaseArgs,
}
impl Command {
@ -133,7 +125,7 @@ impl Command {
let _ = fdlimit::raise_fd_limit();
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.resolve_datadir(self.chain.chain);
let config_path = self.config.clone().unwrap_or_else(|| data_dir.config());
let config: Config = confy::load_path(config_path).unwrap_or_default();

View File

@ -26,25 +26,14 @@ use tracing::info;
use crate::{
args::{
utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS},
DatabaseArgs,
DatabaseArgs, DatadirArgs,
},
dirs::{DataDirPath, MaybePlatformPath},
macros::block_executor,
};
/// `reth stage unwind` command
#[derive(Debug, Parser)]
pub struct Command {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t, global = true)]
datadir: MaybePlatformPath<DataDirPath>,
/// The chain this node is running.
///
/// Possible values are either a built-in chain or the path to a chain specification file.
@ -58,6 +47,9 @@ pub struct Command {
)]
chain: Arc<ChainSpec>,
#[command(flatten)]
datadir: DatadirArgs,
#[command(flatten)]
db: DatabaseArgs,
@ -72,7 +64,7 @@ impl Command {
/// Execute `db stage unwind` command
pub async fn execute(self) -> eyre::Result<()> {
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
let db_path = data_dir.db();
if !db_path.exists() {
eyre::bail!("Database {db_path:?} does not exist.")

26
book/cli/reth/db.md vendored
View File

@ -19,17 +19,6 @@ Commands:
help Print this message or the help of the given subcommand(s)
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -53,6 +42,21 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Database:
--db.log-level <LOG_LEVEL>
Database logging level. Levels higher than "notice" require a debug build

View File

@ -11,20 +11,6 @@ Arguments:
The table name
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--start-key <START_KEY>
The start of the range to checksum
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -34,6 +20,9 @@ Options:
[default: mainnet]
--start-key <START_KEY>
The start of the range to checksum
--end-key <END_KEY>
The end of the range to checksum

View File

@ -12,17 +12,6 @@ Commands:
help Print this message or the help of the given subcommand(s)
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.

View File

@ -11,17 +11,6 @@ Arguments:
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.

View File

@ -14,17 +14,6 @@ Arguments:
- receipts: Static File segment responsible for the `Receipts` table
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.

View File

@ -7,20 +7,6 @@ $ reth db diff --help
Usage: reth db diff [OPTIONS] --secondary-datadir <SECONDARY_DATADIR> --output <OUTPUT>
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--secondary-datadir <SECONDARY_DATADIR>
The path to the data dir for all reth files and subdirectories.
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -30,6 +16,9 @@ Options:
[default: mainnet]
--secondary-datadir <SECONDARY_DATADIR>
The path to the data dir for all reth files and subdirectories.
--instance <INSTANCE>
Add a new instance of a node.

View File

@ -7,20 +7,6 @@ $ reth db drop --help
Usage: reth db drop [OPTIONS]
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
-f, --force
Bypasses the interactive confirmation and drops the database directly
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -30,6 +16,9 @@ Options:
[default: mainnet]
-f, --force
Bypasses the interactive confirmation and drops the database directly
--instance <INSTANCE>
Add a new instance of a node.

View File

@ -12,17 +12,6 @@ Commands:
help Print this message or the help of the given subcommand(s)
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.

View File

@ -17,20 +17,6 @@ Arguments:
The subkey to get content for
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--raw
Output bytes instead of human-readable decoded value
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -40,6 +26,9 @@ Options:
[default: mainnet]
--raw
Output bytes instead of human-readable decoded value
--instance <INSTANCE>
Add a new instance of a node.

View File

@ -17,20 +17,6 @@ Arguments:
The key to get content for
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--raw
Output bytes instead of human-readable decoded value
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -40,6 +26,9 @@ Options:
[default: mainnet]
--raw
Output bytes instead of human-readable decoded value
--instance <INSTANCE>
Add a new instance of a node.

View File

@ -11,22 +11,6 @@ Arguments:
The table name
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
-s, --skip <SKIP>
Skip first N entries
[default: 0]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -36,6 +20,11 @@ Options:
[default: mainnet]
-s, --skip <SKIP>
Skip first N entries
[default: 0]
-r, --reverse
Reverse the order of the entries. If enabled last table entries are read

View File

@ -7,17 +7,6 @@ $ reth db path --help
Usage: reth db path [OPTIONS]
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.

View File

@ -7,20 +7,6 @@ $ reth db stats --help
Usage: reth db stats [OPTIONS]
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--detailed-sizes
Show only the total size for static files
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -30,6 +16,9 @@ Options:
[default: mainnet]
--detailed-sizes
Show only the total size for static files
--detailed-segments
Show detailed information per static file segment

View File

@ -7,17 +7,6 @@ $ reth db version --help
Usage: reth db version [OPTIONS]
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.

View File

@ -10,17 +10,6 @@ Options:
--config <FILE>
The path to the configuration file to use.
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -50,6 +39,21 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Database:
--db.log-level <LOG_LEVEL>
Database logging level. Levels higher than "notice" require a debug build

View File

@ -6,38 +6,7 @@ Initialize the database from a state dump file
$ reth init-state --help
Usage: reth init-state [OPTIONS] <STATE_DUMP_FILE>
Arguments:
<STATE_DUMP_FILE>
JSONL file with state dump.
Must contain accounts in following format, additional account fields are ignored. Must
also contain { "root": \<state-root\> } as first line.
{
"balance": "\<balance\>",
"nonce": \<nonce\>,
"code": "\<bytecode\>",
"storage": {
"\<key\>": "\<value\>",
..
},
"address": "\<address\>",
}
Allows init at a non-genesis block. Caution! Blocks must be manually imported up until
and including the non-genesis block to init chain at. See 'import' command.
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -61,6 +30,40 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
<STATE_DUMP_FILE>
JSONL file with state dump.
Must contain accounts in following format, additional account fields are ignored. Must
also contain { "root": \<state-root\> } as first line.
{
"balance": "\<balance\>",
"nonce": \<nonce\>,
"code": "\<bytecode\>",
"storage": {
"\<key\>": "\<value\>",
..
},
"address": "\<address\>",
}
Allows init at a non-genesis block. Caution! Blocks must be manually imported up until
and including the non-genesis block to init chain at. See 'import' command.
Database:
--db.log-level <LOG_LEVEL>
Database logging level. Levels higher than "notice" require a debug build

26
book/cli/reth/init.md vendored
View File

@ -7,17 +7,6 @@ $ reth init --help
Usage: reth init [OPTIONS]
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -41,6 +30,21 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Database:
--db.log-level <LOG_LEVEL>
Database logging level. Levels higher than "notice" require a debug build

26
book/cli/reth/node.md vendored
View File

@ -7,17 +7,6 @@ $ reth node --help
Usage: reth node [OPTIONS]
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--config <FILE>
The path to the configuration file to use.
@ -55,6 +44,21 @@ Metrics:
The metrics will be served at the given interface and port.
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Networking:
-d, --disable-discovery
Disable the discovery service

28
book/cli/reth/p2p.md vendored
View File

@ -24,16 +24,10 @@ Options:
[default: mainnet]
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
--retries <RETRIES>
The number of retries per request
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
[default: 5]
--instance <INSTANCE>
Add a new instance of a node.
@ -176,10 +170,20 @@ Networking:
[default: 131072]
--retries <RETRIES>
The number of retries per request
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
[default: 5]
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Database:
--db.log-level <LOG_LEVEL>

View File

@ -7,17 +7,6 @@ $ reth recover storage-tries --help
Usage: reth recover storage-tries [OPTIONS]
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -41,6 +30,21 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Database:
--db.log-level <LOG_LEVEL>
Database logging level. Levels higher than "notice" require a debug build

View File

@ -7,17 +7,6 @@ $ reth stage drop --help
Usage: reth stage drop [OPTIONS] <STAGE>
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -41,6 +30,21 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Database:
--db.log-level <LOG_LEVEL>
Database logging level. Levels higher than "notice" require a debug build

View File

@ -14,17 +14,6 @@ Commands:
help Print this message or the help of the given subcommand(s)
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -48,6 +37,21 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Database:
--db.log-level <LOG_LEVEL>
Database logging level. Levels higher than "notice" require a debug build

View File

@ -27,17 +27,6 @@ Options:
--config <FILE>
The path to the configuration file to use.
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -72,6 +61,14 @@ Options:
You can optionally skip the unwinding phase if you're syncing a block range that has not been synced before.
-c, --commit
Commits the changes in the database. WARNING: potentially destructive.
Useful when you want to run diagnostics on the database.
--checkpoints
Save stage checkpoints
--instance <INSTANCE>
Add a new instance of a node.
@ -86,6 +83,21 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Networking:
-d, --disable-discovery
Disable the discovery service
@ -232,14 +244,6 @@ Database:
[possible values: true, false]
-c, --commit
Commits the changes in the database. WARNING: potentially destructive.
Useful when you want to run diagnostics on the database.
--checkpoints
Save stage checkpoints
Logging:
--log.stdout.format <FORMAT>
The format to use for logs written to stdout

View File

@ -12,17 +12,6 @@ Commands:
help Print this message or the help of the given subcommand(s)
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.
@ -46,6 +35,21 @@ Options:
-h, --help
Print help (see a summary with '-h')
Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--datadir.static_files <PATH>
The absolute path to store static files in.
Database:
--db.log-level <LOG_LEVEL>
Database logging level. Levels higher than "notice" require a debug build

View File

@ -11,17 +11,6 @@ Arguments:
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.

View File

@ -11,17 +11,6 @@ Arguments:
Options:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Defaults to the OS-specific data directory:
- Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
- Windows: `{FOLDERID_RoamingAppData}/reth/`
- macOS: `$HOME/Library/Application Support/reth/`
[default: default]
--chain <CHAIN_OR_PATH>
The chain this node is running.
Possible values are either a built-in chain or the path to a chain specification file.

View File

@ -0,0 +1,53 @@
//! clap [Args](clap::Args) for datadir config
use crate::dirs::{ChainPath, DataDirPath, MaybePlatformPath};
use clap::Args;
use reth_primitives::Chain;
use std::path::PathBuf;
/// Parameters for datadir configuration
#[derive(Debug, Args, PartialEq, Eq, Default, Clone)]
#[command(next_help_heading = "Datadir")]
pub struct DatadirArgs {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
///
/// - Linux: `$XDG_DATA_HOME/reth/` or `$HOME/.local/share/reth/`
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
pub datadir: MaybePlatformPath<DataDirPath>,
/// The absolute path to store static files in.
#[arg(long = "datadir.static_files", verbatim_doc_comment, value_name = "PATH")]
pub static_files_path: Option<PathBuf>,
}
impl DatadirArgs {
/// Resolves the final datadir path.
pub fn resolve_datadir(self, chain: Chain) -> ChainPath<DataDirPath> {
let datadir = self.datadir.clone();
datadir.unwrap_or_chain_default(chain, self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
/// A helper type to parse Args more easily
#[derive(Parser)]
struct CommandParser<T: Args> {
#[command(flatten)]
args: T,
}
#[test]
fn test_parse_datadir_args() {
let default_args = DatadirArgs::default();
let args = CommandParser::<DatadirArgs>::parse_from(["reth"]).args;
assert_eq!(args, default_args);
}
}

View File

@ -51,6 +51,10 @@ pub use dev::DevArgs;
mod pruning;
pub use pruning::PruningArgs;
/// DatadirArgs for configuring data storage paths
mod datadir_args;
pub use datadir_args::DatadirArgs;
pub mod utils;
pub mod types;

View File

@ -1,6 +1,6 @@
//! reth data directories.
use crate::utils::parse_path;
use crate::{args::DatadirArgs, utils::parse_path};
use reth_primitives::Chain;
use std::{
env::VarError,
@ -53,7 +53,7 @@ pub fn logs_dir() -> Option<PathBuf> {
///
/// The data dir should contain a subdirectory for each chain, and those chain directories will
/// include all information for that chain, such as the p2p secret.
#[derive(Clone, Copy, Debug, Default)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
pub struct DataDirPath;
@ -66,7 +66,7 @@ impl XdgPath for DataDirPath {
/// Returns the path to the reth logs directory.
///
/// Refer to [`dirs_next::cache_dir`] for cross-platform behavior.
#[derive(Clone, Copy, Debug, Default)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
pub struct LogsDir;
@ -155,14 +155,17 @@ impl<D> PlatformPath<D> {
impl<D> PlatformPath<D> {
/// Converts the path to a `ChainPath` with the given `Chain`.
pub fn with_chain(&self, chain: Chain) -> ChainPath<D> {
pub fn with_chain(&self, chain: Chain, datadir_args: DatadirArgs) -> ChainPath<D> {
// extract chain name
let platform_path = self.platform_path_from_chain(chain);
ChainPath::new(platform_path, chain, datadir_args)
}
fn platform_path_from_chain(&self, chain: Chain) -> Self {
let chain_name = config_path_prefix(chain);
let path = self.0.join(chain_name);
let platform_path = Self(path, std::marker::PhantomData);
ChainPath::new(platform_path, chain)
Self(path, std::marker::PhantomData)
}
/// Map the inner path to a new type `T`.
@ -181,16 +184,19 @@ pub struct MaybePlatformPath<D>(Option<PlatformPath<D>>);
impl<D: XdgPath> MaybePlatformPath<D> {
/// Returns the path if it is set, otherwise returns the default path for the given chain.
pub fn unwrap_or_chain_default(&self, chain: Chain) -> ChainPath<D> {
pub fn unwrap_or_chain_default(&self, chain: Chain, datadir_args: DatadirArgs) -> ChainPath<D> {
ChainPath(
self.0.clone().unwrap_or_else(|| PlatformPath::default().with_chain(chain).0),
self.0
.clone()
.unwrap_or_else(|| PlatformPath::default().platform_path_from_chain(chain)),
chain,
datadir_args,
)
}
/// Returns the default platform path for the specified [Chain].
pub fn chain_default(chain: Chain) -> ChainPath<D> {
PlatformPath::default().with_chain(chain)
PlatformPath::default().with_chain(chain, DatadirArgs::default())
}
/// Returns true if a custom path is set
@ -261,12 +267,12 @@ impl<D> From<PathBuf> for MaybePlatformPath<D> {
/// Otherwise, the path will be dependent on the chain ID:
/// * `<DIR>/<CHAIN_ID>`
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ChainPath<D>(PlatformPath<D>, Chain);
pub struct ChainPath<D>(PlatformPath<D>, Chain, DatadirArgs);
impl<D> ChainPath<D> {
/// Returns a new `ChainPath` given a `PlatformPath` and a `Chain`.
pub const fn new(path: PlatformPath<D>, chain: Chain) -> Self {
Self(path, chain)
pub const fn new(path: PlatformPath<D>, chain: Chain, datadir_args: DatadirArgs) -> Self {
Self(path, chain, datadir_args)
}
/// Returns the path to the reth data directory for this chain.
@ -283,11 +289,16 @@ impl<D> ChainPath<D> {
self.data_dir().join("db")
}
/// Returns the path to the `static_files` directory for this chain.
/// Returns the path to the static files directory for this chain.
///
/// `<DIR>/<CHAIN_ID>/static_files`
pub fn static_files(&self) -> PathBuf {
self.data_dir().join("static_files")
let datadir_args = &self.2;
if let Some(static_files_path) = &datadir_args.static_files_path {
static_files_path.to_path_buf()
} else {
self.data_dir().join("static_files")
}
}
/// Returns the path to the reth p2p secret key for this chain.
@ -359,29 +370,29 @@ mod tests {
#[test]
fn test_maybe_data_dir_path() {
let path = MaybePlatformPath::<DataDirPath>::default();
let path = path.unwrap_or_chain_default(Chain::mainnet());
let path = path.unwrap_or_chain_default(Chain::mainnet(), DatadirArgs::default());
assert!(path.as_ref().ends_with("reth/mainnet"), "{path:?}");
let db_path = path.db();
assert!(db_path.ends_with("reth/mainnet/db"), "{db_path:?}");
let path = MaybePlatformPath::<DataDirPath>::from_str("my/path/to/datadir").unwrap();
let path = path.unwrap_or_chain_default(Chain::mainnet());
let path = path.unwrap_or_chain_default(Chain::mainnet(), DatadirArgs::default());
assert!(path.as_ref().ends_with("my/path/to/datadir"), "{path:?}");
}
#[test]
fn test_maybe_testnet_datadir_path() {
let path = MaybePlatformPath::<DataDirPath>::default();
let path = path.unwrap_or_chain_default(Chain::goerli());
let path = path.unwrap_or_chain_default(Chain::goerli(), DatadirArgs::default());
assert!(path.as_ref().ends_with("reth/goerli"), "{path:?}");
let path = MaybePlatformPath::<DataDirPath>::default();
let path = path.unwrap_or_chain_default(Chain::holesky());
let path = path.unwrap_or_chain_default(Chain::holesky(), DatadirArgs::default());
assert!(path.as_ref().ends_with("reth/holesky"), "{path:?}");
let path = MaybePlatformPath::<DataDirPath>::default();
let path = path.unwrap_or_chain_default(Chain::sepolia());
let path = path.unwrap_or_chain_default(Chain::sepolia(), DatadirArgs::default());
assert!(path.as_ref().ends_with("reth/sepolia"), "{path:?}");
}
}

View File

@ -2,7 +2,7 @@
use crate::{
args::{
get_secret_key, DatabaseArgs, DebugArgs, DevArgs, DiscoveryArgs, NetworkArgs,
get_secret_key, DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, DiscoveryArgs, NetworkArgs,
PayloadBuilderArgs, PruningArgs, RpcServerArgs, TxPoolArgs,
},
dirs::{ChainPath, DataDirPath},
@ -96,6 +96,9 @@ pub static PROMETHEUS_RECORDER_HANDLE: Lazy<PrometheusHandle> =
/// ```
#[derive(Debug, Clone)]
pub struct NodeConfig {
/// All data directory related arguments
pub datadir: DatadirArgs,
/// The path to the configuration file to use.
pub config: Option<PathBuf>,
@ -164,6 +167,12 @@ impl NodeConfig {
self
}
/// Set the data directory args for the node
pub fn with_datadir_args(mut self, datadir_args: DatadirArgs) -> Self {
self.datadir = datadir_args;
self
}
/// Set the config file for the node
pub fn with_config(mut self, config: impl Into<PathBuf>) -> Self {
self.config = Some(config.into());
@ -519,6 +528,11 @@ impl NodeConfig {
self.network = self.network.with_unused_ports();
self
}
/// Resolve the final datadir path.
pub fn datadir(&self) -> ChainPath<DataDirPath> {
self.datadir.clone().resolve_datadir(self.chain.chain)
}
}
impl Default for NodeConfig {
@ -536,6 +550,7 @@ impl Default for NodeConfig {
db: DatabaseArgs::default(),
dev: DevArgs::default(),
pruning: PruningArgs::default(),
datadir: DatadirArgs::default(),
}
}
}

View File

@ -12,7 +12,7 @@ use futures::Future;
use reth_db::{
database::Database,
database_metrics::{DatabaseMetadata, DatabaseMetrics},
test_utils::{create_test_rw_db, TempDatabase},
test_utils::{create_test_rw_db_with_path, tempdir_path, TempDatabase},
DatabaseEnv,
};
use reth_exex::ExExContext;
@ -30,7 +30,7 @@ use reth_provider::{providers::BlockchainProvider, ChainSpecProvider};
use reth_tasks::TaskExecutor;
use reth_transaction_pool::{PoolConfig, TransactionPool};
pub use states::*;
use std::{str::FromStr, sync::Arc};
use std::sync::Arc;
mod states;
@ -174,11 +174,11 @@ impl<DB> NodeBuilder<DB> {
self,
task_executor: TaskExecutor,
) -> WithLaunchContext<NodeBuilder<Arc<TempDatabase<DatabaseEnv>>>> {
let db = create_test_rw_db();
let db_path_str = db.path().to_str().expect("Path is not valid unicode");
let path =
MaybePlatformPath::<DataDirPath>::from_str(db_path_str).expect("Path is not valid");
let data_dir = path.unwrap_or_chain_default(self.config.chain.chain);
let path = MaybePlatformPath::<DataDirPath>::from(tempdir_path());
let data_dir =
path.unwrap_or_chain_default(self.config.chain.chain, self.config.datadir.clone());
let db = create_test_rw_db_with_path(data_dir.db());
WithLaunchContext { builder: self.with_database(db), task_executor, data_dir }
}

View File

@ -333,6 +333,8 @@ where
/// between the database and static files. **It may execute a pipeline unwind if it fails this
/// check.**
pub async fn create_provider_factory(&self) -> eyre::Result<ProviderFactory<DB>> {
println!("datadir: {:?}", self.data_dir());
let factory = ProviderFactory::new(
self.right().clone(),
self.chain_spec(),