From 4522fd8baf4dbbedf7db2ad44c839d0dc24e0b86 Mon Sep 17 00:00:00 2001 From: back <104515688+justcode740@users.noreply.github.com> Date: Mon, 3 Jun 2024 09:47:15 -0700 Subject: [PATCH] feat(cli): override static files datadir (#7212) Co-authored-by: Oliver Nordbjerg Co-authored-by: Alexey Shekhirin Co-authored-by: Oliver Nordbjerg --- bin/reth/src/commands/db/mod.rs | 21 ++---- .../src/commands/debug_cmd/build_block.rs | 18 ++--- bin/reth/src/commands/debug_cmd/execution.rs | 20 ++---- .../commands/debug_cmd/in_memory_merkle.rs | 18 ++--- bin/reth/src/commands/debug_cmd/merkle.rs | 20 ++---- .../src/commands/debug_cmd/replay_engine.rs | 20 ++---- bin/reth/src/commands/import.rs | 18 ++--- bin/reth/src/commands/import_op.rs | 17 ++--- bin/reth/src/commands/import_receipts_op.rs | 24 ++----- bin/reth/src/commands/init_cmd.rs | 26 +++----- bin/reth/src/commands/init_state.rs | 25 +++---- bin/reth/src/commands/node/mod.rs | 40 +++++------- bin/reth/src/commands/p2p/mod.rs | 24 +++---- .../src/commands/recover/storage_tries.rs | 22 ++----- bin/reth/src/commands/stage/drop.rs | 18 ++--- bin/reth/src/commands/stage/dump/mod.rs | 30 +++------ bin/reth/src/commands/stage/run.rs | 30 ++++----- bin/reth/src/commands/stage/unwind.rs | 18 ++--- book/cli/reth/db.md | 26 ++++---- book/cli/reth/db/checksum.md | 17 +---- book/cli/reth/db/clear.md | 11 ---- book/cli/reth/db/clear/mdbx.md | 11 ---- book/cli/reth/db/clear/static-file.md | 11 ---- book/cli/reth/db/diff.md | 17 +---- book/cli/reth/db/drop.md | 17 +---- book/cli/reth/db/get.md | 11 ---- book/cli/reth/db/get/mdbx.md | 17 +---- book/cli/reth/db/get/static-file.md | 17 +---- book/cli/reth/db/list.md | 21 ++---- book/cli/reth/db/path.md | 11 ---- book/cli/reth/db/stats.md | 17 +---- book/cli/reth/db/version.md | 11 ---- book/cli/reth/import.md | 26 ++++---- book/cli/reth/init-state.md | 65 ++++++++++--------- book/cli/reth/init.md | 26 ++++---- book/cli/reth/node.md | 26 ++++---- book/cli/reth/p2p.md | 28 ++++---- book/cli/reth/recover/storage-tries.md | 26 ++++---- book/cli/reth/stage/drop.md | 26 ++++---- book/cli/reth/stage/dump.md | 26 ++++---- book/cli/reth/stage/run.md | 42 ++++++------ book/cli/reth/stage/unwind.md | 26 ++++---- book/cli/reth/stage/unwind/num-blocks.md | 11 ---- book/cli/reth/stage/unwind/to-block.md | 11 ---- crates/node-core/src/args/datadir_args.rs | 53 +++++++++++++++ crates/node-core/src/args/mod.rs | 4 ++ crates/node-core/src/dirs.rs | 53 +++++++++------ crates/node-core/src/node_config.rs | 17 ++++- crates/node/builder/src/builder/mod.rs | 14 ++-- crates/node/builder/src/launch/common.rs | 2 + 50 files changed, 460 insertions(+), 646 deletions(-) create mode 100644 crates/node-core/src/args/datadir_args.rs diff --git a/bin/reth/src/commands/db/mod.rs b/bin/reth/src/commands/db/mod.rs index e7edc19a9856..11d614cb86dc 100644 --- a/bin/reth/src/commands/db/mod.rs +++ b/bin/reth/src/commands/db/mod.rs @@ -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, - /// 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, + #[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)); } } diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 7df2e895ad1f..a1a628e4ab2a 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -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, - /// 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, + #[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)?; diff --git a/bin/reth/src/commands/debug_cmd/execution.rs b/bin/reth/src/commands/debug_cmd/execution.rs index f76b09849a14..c23683642fbe 100644 --- a/bin/reth/src/commands/debug_cmd/execution.rs +++ b/bin/reth/src/commands/debug_cmd/execution.rs @@ -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, - /// 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, + #[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 diff --git a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs index dbd1663fd726..a53625e15839 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -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, - /// 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, + #[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)?; diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index 3cc79a0370b5..405a8c57c0ee 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -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, - /// 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, + #[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)?; diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs index 212fdb2414da..dbd407fdb80b 100644 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ b/bin/reth/src/commands/debug_cmd/replay_engine.rs @@ -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, - /// 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, + #[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)?; diff --git a/bin/reth/src/commands/import.rs b/bin/reth/src/commands/import.rs index 9fb967dd9e1d..774339241831 100644 --- a/bin/reth/src/commands/import.rs +++ b/bin/reth/src/commands/import.rs @@ -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, - /// 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, - /// 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, + #[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())?; diff --git a/bin/reth/src/commands/import_op.rs b/bin/reth/src/commands/import_op.rs index bb2ef4567b69..4fe11d3119b6 100644 --- a/bin/reth/src/commands/import_op.rs +++ b/bin/reth/src/commands/import_op.rs @@ -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, - /// 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, - /// Chunk byte length to read from file. #[arg(long, value_name = "CHUNK_LEN", verbatim_doc_comment)] chunk_len: Option, + #[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())?; diff --git a/bin/reth/src/commands/import_receipts_op.rs b/bin/reth/src/commands/import_receipts_op.rs index 6fefc4ea2a35..3a5b2a10f281 100644 --- a/bin/reth/src/commands/import_receipts_op.rs +++ b/bin/reth/src/commands/import_receipts_op.rs @@ -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, + #[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"); diff --git a/bin/reth/src/commands/init_cmd.rs b/bin/reth/src/commands/init_cmd.rs index 0da65aba5033..e59c4c46ceaf 100644 --- a/bin/reth/src/commands/init_cmd.rs +++ b/bin/reth/src/commands/init_cmd.rs @@ -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, - /// 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, + #[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"); diff --git a/bin/reth/src/commands/init_state.rs b/bin/reth/src/commands/init_state.rs index b672f11f2063..45bdde2279f8 100644 --- a/bin/reth/src/commands/init_state.rs +++ b/bin/reth/src/commands/init_state.rs @@ -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, - /// 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, + #[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())?); diff --git a/bin/reth/src/commands/node/mod.rs b/bin/reth/src/commands/node/mod.rs index 7f8e278f7edd..e84044f0c096 100644 --- a/bin/reth/src/commands/node/mod.rs +++ b/bin/reth/src/commands/node/mod.rs @@ -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 { - /// 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, - /// The path to the configuration file to use. #[arg(long, value_name = "FILE", verbatim_doc_comment)] pub config: Option, @@ -76,6 +63,10 @@ pub struct NodeCommand { #[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 NodeCommand { // set up node config let mut node_config = NodeConfig { + datadir, config, chain, metrics, @@ -179,7 +171,7 @@ impl NodeCommand { // 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")); } diff --git a/bin/reth/src/commands/p2p/mod.rs b/bin/reth/src/commands/p2p/mod.rs index 627c2d36b44f..a85891af7e58 100644 --- a/bin/reth/src/commands/p2p/mod.rs +++ b/bin/reth/src/commands/p2p/mod.rs @@ -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, - /// 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, - - /// 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(); diff --git a/bin/reth/src/commands/recover/storage_tries.rs b/bin/reth/src/commands/recover/storage_tries.rs index 8aa568974925..db3470e8f847 100644 --- a/bin/reth/src/commands/recover/storage_tries.rs +++ b/bin/reth/src/commands/recover/storage_tries.rs @@ -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, - /// 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, + #[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())?); diff --git a/bin/reth/src/commands/stage/drop.rs b/bin/reth/src/commands/stage/drop.rs index 042bafa3ada7..9e61755cdf32 100644 --- a/bin/reth/src/commands/stage/drop.rs +++ b/bin/reth/src/commands/stage/drop.rs @@ -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, - /// 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, + #[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)?; diff --git a/bin/reth/src/commands/stage/dump/mod.rs b/bin/reth/src/commands/stage/dump/mod.rs index 3ba4fd78977b..e126d3fa1b42 100644 --- a/bin/reth/src/commands/stage/dump/mod.rs +++ b/bin/reth/src/commands/stage/dump/mod.rs @@ -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, - /// 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, + #[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? diff --git a/bin/reth/src/commands/stage/run.rs b/bin/reth/src/commands/stage/run.rs index 9c1d9009151c..d397ec93df02 100644 --- a/bin/reth/src/commands/stage/run.rs +++ b/bin/reth/src/commands/stage/run.rs @@ -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, - /// 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, - /// 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(); diff --git a/bin/reth/src/commands/stage/unwind.rs b/bin/reth/src/commands/stage/unwind.rs index e5714f57b708..1eadd88f5e58 100644 --- a/bin/reth/src/commands/stage/unwind.rs +++ b/bin/reth/src/commands/stage/unwind.rs @@ -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, - /// 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, + #[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.") diff --git a/book/cli/reth/db.md b/book/cli/reth/db.md index 85edd12afb61..8613e9222fb3 100644 --- a/book/cli/reth/db.md +++ b/book/cli/reth/db.md @@ -19,17 +19,6 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --datadir - 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 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 + 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 + The absolute path to store static files in. + Database: --db.log-level Database logging level. Levels higher than "notice" require a debug build diff --git a/book/cli/reth/db/checksum.md b/book/cli/reth/db/checksum.md index 912a2761cd86..9817f0c3c6ba 100644 --- a/book/cli/reth/db/checksum.md +++ b/book/cli/reth/db/checksum.md @@ -11,20 +11,6 @@ Arguments: The table name Options: - --datadir - 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 - The start of the range to checksum - --chain 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 + The start of the range to checksum + --end-key The end of the range to checksum diff --git a/book/cli/reth/db/clear.md b/book/cli/reth/db/clear.md index 6e89214cef53..d147d7d3ab9e 100644 --- a/book/cli/reth/db/clear.md +++ b/book/cli/reth/db/clear.md @@ -12,17 +12,6 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --datadir - 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 The chain this node is running. Possible values are either a built-in chain or the path to a chain specification file. diff --git a/book/cli/reth/db/clear/mdbx.md b/book/cli/reth/db/clear/mdbx.md index 72917730f08c..150a405b97e5 100644 --- a/book/cli/reth/db/clear/mdbx.md +++ b/book/cli/reth/db/clear/mdbx.md @@ -11,17 +11,6 @@ Arguments: Options: - --datadir - 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 The chain this node is running. Possible values are either a built-in chain or the path to a chain specification file. diff --git a/book/cli/reth/db/clear/static-file.md b/book/cli/reth/db/clear/static-file.md index e15f7795da09..799510e21c33 100644 --- a/book/cli/reth/db/clear/static-file.md +++ b/book/cli/reth/db/clear/static-file.md @@ -14,17 +14,6 @@ Arguments: - receipts: Static File segment responsible for the `Receipts` table Options: - --datadir - 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 The chain this node is running. Possible values are either a built-in chain or the path to a chain specification file. diff --git a/book/cli/reth/db/diff.md b/book/cli/reth/db/diff.md index 024ebaeac331..ed2f26194a5a 100644 --- a/book/cli/reth/db/diff.md +++ b/book/cli/reth/db/diff.md @@ -7,20 +7,6 @@ $ reth db diff --help Usage: reth db diff [OPTIONS] --secondary-datadir --output Options: - --datadir - 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 - The path to the data dir for all reth files and subdirectories. - --chain 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 + The path to the data dir for all reth files and subdirectories. + --instance Add a new instance of a node. diff --git a/book/cli/reth/db/drop.md b/book/cli/reth/db/drop.md index f03222f5149e..eb63ecac8fd6 100644 --- a/book/cli/reth/db/drop.md +++ b/book/cli/reth/db/drop.md @@ -7,20 +7,6 @@ $ reth db drop --help Usage: reth db drop [OPTIONS] Options: - --datadir - 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 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 Add a new instance of a node. diff --git a/book/cli/reth/db/get.md b/book/cli/reth/db/get.md index c23eab0d8706..c1384f18292e 100644 --- a/book/cli/reth/db/get.md +++ b/book/cli/reth/db/get.md @@ -12,17 +12,6 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --datadir - 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 The chain this node is running. Possible values are either a built-in chain or the path to a chain specification file. diff --git a/book/cli/reth/db/get/mdbx.md b/book/cli/reth/db/get/mdbx.md index abac459327de..df1418c51c42 100644 --- a/book/cli/reth/db/get/mdbx.md +++ b/book/cli/reth/db/get/mdbx.md @@ -17,20 +17,6 @@ Arguments: The subkey to get content for Options: - --datadir - 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 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 Add a new instance of a node. diff --git a/book/cli/reth/db/get/static-file.md b/book/cli/reth/db/get/static-file.md index 47ad2603a2de..f1a3ac07ebc1 100644 --- a/book/cli/reth/db/get/static-file.md +++ b/book/cli/reth/db/get/static-file.md @@ -17,20 +17,6 @@ Arguments: The key to get content for Options: - --datadir - 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 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 Add a new instance of a node. diff --git a/book/cli/reth/db/list.md b/book/cli/reth/db/list.md index 0941536a9c60..be0b96a6eb4a 100644 --- a/book/cli/reth/db/list.md +++ b/book/cli/reth/db/list.md @@ -11,22 +11,6 @@ Arguments: The table name Options: - --datadir - 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 first N entries - - [default: 0] - --chain 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 first N entries + + [default: 0] + -r, --reverse Reverse the order of the entries. If enabled last table entries are read diff --git a/book/cli/reth/db/path.md b/book/cli/reth/db/path.md index 5318be6f713d..69f9f40f17c9 100644 --- a/book/cli/reth/db/path.md +++ b/book/cli/reth/db/path.md @@ -7,17 +7,6 @@ $ reth db path --help Usage: reth db path [OPTIONS] Options: - --datadir - 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 The chain this node is running. Possible values are either a built-in chain or the path to a chain specification file. diff --git a/book/cli/reth/db/stats.md b/book/cli/reth/db/stats.md index 835a1ad6013c..8cab5eda23c1 100644 --- a/book/cli/reth/db/stats.md +++ b/book/cli/reth/db/stats.md @@ -7,20 +7,6 @@ $ reth db stats --help Usage: reth db stats [OPTIONS] Options: - --datadir - 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 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 diff --git a/book/cli/reth/db/version.md b/book/cli/reth/db/version.md index 932928b26a02..1e19f72d94cd 100644 --- a/book/cli/reth/db/version.md +++ b/book/cli/reth/db/version.md @@ -7,17 +7,6 @@ $ reth db version --help Usage: reth db version [OPTIONS] Options: - --datadir - 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 The chain this node is running. Possible values are either a built-in chain or the path to a chain specification file. diff --git a/book/cli/reth/import.md b/book/cli/reth/import.md index 5386fd029d4c..855d9037a1bd 100644 --- a/book/cli/reth/import.md +++ b/book/cli/reth/import.md @@ -10,17 +10,6 @@ Options: --config The path to the configuration file to use. - --datadir - 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 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 + 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 + The absolute path to store static files in. + Database: --db.log-level Database logging level. Levels higher than "notice" require a debug build diff --git a/book/cli/reth/init-state.md b/book/cli/reth/init-state.md index 48421076c865..bf03e50d86f5 100644 --- a/book/cli/reth/init-state.md +++ b/book/cli/reth/init-state.md @@ -6,38 +6,7 @@ Initialize the database from a state dump file $ reth init-state --help Usage: reth init-state [OPTIONS] -Arguments: - - JSONL file with state dump. - - Must contain accounts in following format, additional account fields are ignored. Must - also contain { "root": \ } as first line. - { - "balance": "\", - "nonce": \, - "code": "\", - "storage": { - "\": "\", - .. - }, - "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 - 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 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 + 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 + The absolute path to store static files in. + + + JSONL file with state dump. + + Must contain accounts in following format, additional account fields are ignored. Must + also contain { "root": \ } as first line. + { + "balance": "\", + "nonce": \, + "code": "\", + "storage": { + "\": "\", + .. + }, + "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 Database logging level. Levels higher than "notice" require a debug build diff --git a/book/cli/reth/init.md b/book/cli/reth/init.md index f57388d68a41..9f010112dad8 100644 --- a/book/cli/reth/init.md +++ b/book/cli/reth/init.md @@ -7,17 +7,6 @@ $ reth init --help Usage: reth init [OPTIONS] Options: - --datadir - 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 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 + 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 + The absolute path to store static files in. + Database: --db.log-level Database logging level. Levels higher than "notice" require a debug build diff --git a/book/cli/reth/node.md b/book/cli/reth/node.md index 78b424966b59..29b1738d0bfc 100644 --- a/book/cli/reth/node.md +++ b/book/cli/reth/node.md @@ -7,17 +7,6 @@ $ reth node --help Usage: reth node [OPTIONS] Options: - --datadir - 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 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 + 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 + The absolute path to store static files in. + Networking: -d, --disable-discovery Disable the discovery service diff --git a/book/cli/reth/p2p.md b/book/cli/reth/p2p.md index 578aee3415b7..d10f09f8df45 100644 --- a/book/cli/reth/p2p.md +++ b/book/cli/reth/p2p.md @@ -24,16 +24,10 @@ Options: [default: mainnet] - --datadir - 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/` + --retries + The number of retries per request - [default: default] + [default: 5] --instance Add a new instance of a node. @@ -176,10 +170,20 @@ Networking: [default: 131072] - --retries - The number of retries per request +Datadir: + --datadir + 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 + The absolute path to store static files in. Database: --db.log-level diff --git a/book/cli/reth/recover/storage-tries.md b/book/cli/reth/recover/storage-tries.md index 245b95ec69e8..5538e071957b 100644 --- a/book/cli/reth/recover/storage-tries.md +++ b/book/cli/reth/recover/storage-tries.md @@ -7,17 +7,6 @@ $ reth recover storage-tries --help Usage: reth recover storage-tries [OPTIONS] Options: - --datadir - 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 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 + 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 + The absolute path to store static files in. + Database: --db.log-level Database logging level. Levels higher than "notice" require a debug build diff --git a/book/cli/reth/stage/drop.md b/book/cli/reth/stage/drop.md index c611b0cd0ed2..fed8f59135ba 100644 --- a/book/cli/reth/stage/drop.md +++ b/book/cli/reth/stage/drop.md @@ -7,17 +7,6 @@ $ reth stage drop --help Usage: reth stage drop [OPTIONS] Options: - --datadir - 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 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 + 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 + The absolute path to store static files in. + Database: --db.log-level Database logging level. Levels higher than "notice" require a debug build diff --git a/book/cli/reth/stage/dump.md b/book/cli/reth/stage/dump.md index ecff50054ce1..0271d4562264 100644 --- a/book/cli/reth/stage/dump.md +++ b/book/cli/reth/stage/dump.md @@ -14,17 +14,6 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --datadir - 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 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 + 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 + The absolute path to store static files in. + Database: --db.log-level Database logging level. Levels higher than "notice" require a debug build diff --git a/book/cli/reth/stage/run.md b/book/cli/reth/stage/run.md index a84bf06b8536..b2ea9feeead3 100644 --- a/book/cli/reth/stage/run.md +++ b/book/cli/reth/stage/run.md @@ -27,17 +27,6 @@ Options: --config The path to the configuration file to use. - --datadir - 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 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 Add a new instance of a node. @@ -86,6 +83,21 @@ Options: -h, --help Print help (see a summary with '-h') +Datadir: + --datadir + 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 + 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 The format to use for logs written to stdout diff --git a/book/cli/reth/stage/unwind.md b/book/cli/reth/stage/unwind.md index 23e90033f7f9..9196dcf9125d 100644 --- a/book/cli/reth/stage/unwind.md +++ b/book/cli/reth/stage/unwind.md @@ -12,17 +12,6 @@ Commands: help Print this message or the help of the given subcommand(s) Options: - --datadir - 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 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 + 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 + The absolute path to store static files in. + Database: --db.log-level Database logging level. Levels higher than "notice" require a debug build diff --git a/book/cli/reth/stage/unwind/num-blocks.md b/book/cli/reth/stage/unwind/num-blocks.md index 74a3f469bd2c..81146d6a481a 100644 --- a/book/cli/reth/stage/unwind/num-blocks.md +++ b/book/cli/reth/stage/unwind/num-blocks.md @@ -11,17 +11,6 @@ Arguments: Options: - --datadir - 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 The chain this node is running. Possible values are either a built-in chain or the path to a chain specification file. diff --git a/book/cli/reth/stage/unwind/to-block.md b/book/cli/reth/stage/unwind/to-block.md index 4994206a8c77..d01f48e0bfab 100644 --- a/book/cli/reth/stage/unwind/to-block.md +++ b/book/cli/reth/stage/unwind/to-block.md @@ -11,17 +11,6 @@ Arguments: Options: - --datadir - 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 The chain this node is running. Possible values are either a built-in chain or the path to a chain specification file. diff --git a/crates/node-core/src/args/datadir_args.rs b/crates/node-core/src/args/datadir_args.rs new file mode 100644 index 000000000000..3d8dc490d292 --- /dev/null +++ b/crates/node-core/src/args/datadir_args.rs @@ -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, + + /// The absolute path to store static files in. + #[arg(long = "datadir.static_files", verbatim_doc_comment, value_name = "PATH")] + pub static_files_path: Option, +} + +impl DatadirArgs { + /// Resolves the final datadir path. + pub fn resolve_datadir(self, chain: Chain) -> ChainPath { + 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 { + #[command(flatten)] + args: T, + } + + #[test] + fn test_parse_datadir_args() { + let default_args = DatadirArgs::default(); + let args = CommandParser::::parse_from(["reth"]).args; + assert_eq!(args, default_args); + } +} diff --git a/crates/node-core/src/args/mod.rs b/crates/node-core/src/args/mod.rs index 270c757bc369..04fc02217d08 100644 --- a/crates/node-core/src/args/mod.rs +++ b/crates/node-core/src/args/mod.rs @@ -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; diff --git a/crates/node-core/src/dirs.rs b/crates/node-core/src/dirs.rs index 6c84e6ef9455..e8ee5b83207f 100644 --- a/crates/node-core/src/dirs.rs +++ b/crates/node-core/src/dirs.rs @@ -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 { /// /// 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 PlatformPath { impl PlatformPath { /// Converts the path to a `ChainPath` with the given `Chain`. - pub fn with_chain(&self, chain: Chain) -> ChainPath { + pub fn with_chain(&self, chain: Chain, datadir_args: DatadirArgs) -> ChainPath { // extract chain name - let chain_name = config_path_prefix(chain); + let platform_path = self.platform_path_from_chain(chain); - let path = self.0.join(chain_name); + ChainPath::new(platform_path, chain, datadir_args) + } - let platform_path = Self(path, std::marker::PhantomData); - ChainPath::new(platform_path, chain) + fn platform_path_from_chain(&self, chain: Chain) -> Self { + let chain_name = config_path_prefix(chain); + let path = self.0.join(chain_name); + Self(path, std::marker::PhantomData) } /// Map the inner path to a new type `T`. @@ -181,16 +184,19 @@ pub struct MaybePlatformPath(Option>); impl MaybePlatformPath { /// 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 { + pub fn unwrap_or_chain_default(&self, chain: Chain, datadir_args: DatadirArgs) -> ChainPath { 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 { - 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 From for MaybePlatformPath { /// Otherwise, the path will be dependent on the chain ID: /// * `/` #[derive(Clone, Debug, PartialEq, Eq)] -pub struct ChainPath(PlatformPath, Chain); +pub struct ChainPath(PlatformPath, Chain, DatadirArgs); impl ChainPath { /// Returns a new `ChainPath` given a `PlatformPath` and a `Chain`. - pub const fn new(path: PlatformPath, chain: Chain) -> Self { - Self(path, chain) + pub const fn new(path: PlatformPath, 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 ChainPath { 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. /// /// `//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::::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::::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::::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::::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::::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:?}"); } } diff --git a/crates/node-core/src/node_config.rs b/crates/node-core/src/node_config.rs index f4519846b5ab..166cbf86f3f1 100644 --- a/crates/node-core/src/node_config.rs +++ b/crates/node-core/src/node_config.rs @@ -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 = /// ``` #[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, @@ -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) -> 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 { + 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(), } } } diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index 571d36b98e4a..84e1c7e4e827 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -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 NodeBuilder { self, task_executor: TaskExecutor, ) -> WithLaunchContext>>> { - let db = create_test_rw_db(); - let db_path_str = db.path().to_str().expect("Path is not valid unicode"); - let path = - MaybePlatformPath::::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::::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 } } diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index 646ce28a3a71..701519306502 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -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> { + println!("datadir: {:?}", self.data_dir()); + let factory = ProviderFactory::new( self.right().clone(), self.chain_spec(),