diff --git a/Cargo.lock b/Cargo.lock index 335361424c8e..11212f0b3778 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1569,9 +1569,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.102" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "779e6b7d17797c0b42023d417228c02889300190e700cb074c3438d9c541d332" +checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" dependencies = [ "jobserver", "libc", @@ -1611,7 +1611,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -3765,9 +3765,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +checksum = "c4fe55fb7a772d59a5ff1dfbff4fe0258d19b89fec4b233e75d35d5d2316badc" dependencies = [ "bytes", "futures-channel", @@ -3806,9 +3806,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" +checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956" dependencies = [ "bytes", "futures-channel", @@ -4560,7 +4560,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" dependencies = [ "cfg-if", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -5458,7 +5458,7 @@ dependencies = [ "libc", "redox_syscall 0.5.2", "smallvec", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -5495,9 +5495,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" dependencies = [ "memchr", "thiserror", @@ -6300,6 +6300,7 @@ dependencies = [ "reth-chainspec", "reth-cli-commands", "reth-cli-runner", + "reth-cli-util", "reth-config", "reth-consensus", "reth-consensus-common", @@ -6619,6 +6620,19 @@ dependencies = [ "tracing", ] +[[package]] +name = "reth-cli-util" +version = "1.0.0" +dependencies = [ + "eyre", + "proptest", + "reth-fs-util", + "reth-network", + "reth-primitives", + "secp256k1", + "thiserror", +] + [[package]] name = "reth-codecs" version = "1.0.0" @@ -7643,6 +7657,7 @@ dependencies = [ "reth-beacon-consensus", "reth-blockchain-tree", "reth-chainspec", + "reth-cli-util", "reth-config", "reth-consensus", "reth-consensus-debug-client", @@ -7703,6 +7718,7 @@ dependencies = [ "proptest", "rand 0.8.5", "reth-chainspec", + "reth-cli-util", "reth-config", "reth-consensus-common", "reth-db", @@ -7732,7 +7748,6 @@ dependencies = [ "secp256k1", "serde_json", "shellexpand", - "thiserror", "tikv-jemalloc-ctl", "tokio", "tower", @@ -8923,9 +8938,9 @@ dependencies = [ [[package]] name = "roaring" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7699249cc2c7d71939f30868f47e9d7add0bdc030d90ee10bfd16887ff8bb1c8" +checksum = "8f4b84ba6e838ceb47b41de5194a60244fac43d9fe03b71dbe8c5a201081d6d1" dependencies = [ "bytemuck", "byteorder", @@ -9063,9 +9078,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" +checksum = "a88d6d420651b496bdd98684116959239430022a115c1240e6c3993be0b15fba" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -9119,9 +9134,9 @@ checksum = "84e217e7fdc8466b5b35d30f8c0a30febd29173df4a3a0c2115d306b9c4117ad" [[package]] name = "rustls-webpki" -version = "0.102.4" +version = "0.102.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78" dependencies = [ "ring", "rustls-pki-types", @@ -9347,9 +9362,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.118" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "indexmap 2.2.6", "itoa", @@ -9391,9 +9406,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.8.1" +version = "3.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20" +checksum = "e73139bc5ec2d45e6c5fd85be5a46949c1c39a4c18e56915f5eb4c12f975e377" dependencies = [ "base64 0.22.1", "chrono", @@ -9409,9 +9424,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.8.1" +version = "3.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65569b702f41443e8bc8bbb1c5779bd0450bbe723b56198980e80ec45780bce2" +checksum = "b80d3d6b56b64335c0180e5ffde23b3c5e08c14c585b51a15bd0e95393f46703" dependencies = [ "darling", "proc-macro2", @@ -10930,7 +10945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ "windows-core 0.52.0", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -10940,7 +10955,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" dependencies = [ "windows-core 0.57.0", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -10949,7 +10964,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -10961,7 +10976,7 @@ dependencies = [ "windows-implement", "windows-interface", "windows-result", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -10992,7 +11007,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -11010,7 +11025,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -11030,18 +11045,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -11052,9 +11067,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -11064,9 +11079,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -11076,15 +11091,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -11094,9 +11109,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -11106,9 +11121,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -11118,9 +11133,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -11130,9 +11145,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" @@ -11247,18 +11262,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index ceb9c9532083..4604dc37ccbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "crates/cli/cli/", "crates/cli/commands/", "crates/cli/runner/", + "crates/cli/util/", "crates/config/", "crates/consensus/auto-seal/", "crates/consensus/beacon/", @@ -275,6 +276,7 @@ reth-chainspec = { path = "crates/chainspec" } reth-cli = { path = "crates/cli/cli" } reth-cli-commands = { path = "crates/cli/commands" } reth-cli-runner = { path = "crates/cli/runner" } +reth-cli-util = { path = "crates/cli/util" } reth-codecs = { path = "crates/storage/codecs" } reth-codecs-derive = { path = "crates/storage/codecs/derive" } reth-config = { path = "crates/config" } diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 6ea5c346a5e8..9f8e08b0cda7 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -31,6 +31,7 @@ reth-transaction-pool.workspace = true reth-beacon-consensus.workspace = true reth-cli-runner.workspace = true reth-cli-commands.workspace = true +reth-cli-util.workspace = true reth-consensus-common.workspace = true reth-blockchain-tree.workspace = true reth-rpc-builder.workspace = true diff --git a/bin/reth/src/commands/debug_cmd/execution.rs b/bin/reth/src/commands/debug_cmd/execution.rs index dc8e01e54f44..f645cd140f6f 100644 --- a/bin/reth/src/commands/debug_cmd/execution.rs +++ b/bin/reth/src/commands/debug_cmd/execution.rs @@ -1,15 +1,12 @@ //! Command for debugging execution. -use crate::{ - args::{get_secret_key, NetworkArgs}, - macros::block_executor, - utils::get_single_header, -}; +use crate::{args::NetworkArgs, macros::block_executor, utils::get_single_header}; use clap::Parser; use futures::{stream::select as stream_select, StreamExt}; use reth_beacon_consensus::EthBeaconConsensus; use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs}; use reth_cli_runner::CliContext; +use reth_cli_util::get_secret_key; use reth_config::Config; use reth_consensus::Consensus; use reth_db::DatabaseEnv; 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 7fcffffcdb0b..04288d6a8baa 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -1,7 +1,7 @@ //! Command for debugging in-memory merkle trie calculation. use crate::{ - args::{get_secret_key, NetworkArgs}, + args::NetworkArgs, macros::block_executor, utils::{get_single_body, get_single_header}, }; @@ -9,6 +9,7 @@ use backon::{ConstantBuilder, Retryable}; use clap::Parser; use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs}; use reth_cli_runner::CliContext; +use reth_cli_util::get_secret_key; use reth_config::Config; use reth_db::DatabaseEnv; use reth_errors::BlockValidationError; diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index 05befe374175..432e3b00b3c0 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -1,14 +1,11 @@ //! Command for debugging merkle trie calculation. -use crate::{ - args::{get_secret_key, NetworkArgs}, - macros::block_executor, - utils::get_single_header, -}; +use crate::{args::NetworkArgs, macros::block_executor, utils::get_single_header}; use backon::{ConstantBuilder, Retryable}; use clap::Parser; use reth_beacon_consensus::EthBeaconConsensus; use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs}; use reth_cli_runner::CliContext; +use reth_cli_util::get_secret_key; use reth_config::Config; use reth_consensus::Consensus; use reth_db::{tables, DatabaseEnv}; diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs index 02a7205a44d2..cc31c562f6ff 100644 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ b/bin/reth/src/commands/debug_cmd/replay_engine.rs @@ -1,7 +1,4 @@ -use crate::{ - args::{get_secret_key, NetworkArgs}, - macros::block_executor, -}; +use crate::{args::NetworkArgs, macros::block_executor}; use clap::Parser; use eyre::Context; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; @@ -11,6 +8,7 @@ use reth_blockchain_tree::{ }; use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs}; use reth_cli_runner::CliContext; +use reth_cli_util::get_secret_key; use reth_config::Config; use reth_consensus::Consensus; use reth_db::DatabaseEnv; diff --git a/bin/reth/src/commands/node/mod.rs b/bin/reth/src/commands/node/mod.rs index f4c355b1757f..ee3c6da74223 100644 --- a/bin/reth/src/commands/node/mod.rs +++ b/bin/reth/src/commands/node/mod.rs @@ -1,13 +1,14 @@ //! Main node command for launching a node use crate::args::{ - utils::{chain_help, chain_value_parser, parse_socket_address, SUPPORTED_CHAINS}, + utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS}, DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs, RpcServerArgs, TxPoolArgs, }; use clap::{value_parser, Args, Parser}; use reth_chainspec::ChainSpec; use reth_cli_runner::CliContext; +use reth_cli_util::parse_socket_address; use reth_db::{init_db, DatabaseEnv}; use reth_node_builder::{NodeBuilder, WithLaunchContext}; use reth_node_core::{node_config::NodeConfig, version}; diff --git a/bin/reth/src/commands/p2p.rs b/bin/reth/src/commands/p2p.rs index 73426441c4b6..b08f09ae6756 100644 --- a/bin/reth/src/commands/p2p.rs +++ b/bin/reth/src/commands/p2p.rs @@ -2,8 +2,7 @@ use crate::{ args::{ - get_secret_key, - utils::{chain_help, chain_value_parser, hash_or_num_value_parser, SUPPORTED_CHAINS}, + utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS}, DatabaseArgs, NetworkArgs, }, utils::get_single_header, @@ -11,6 +10,7 @@ use crate::{ use backon::{ConstantBuilder, Retryable}; use clap::{Parser, Subcommand}; use reth_chainspec::ChainSpec; +use reth_cli_util::{get_secret_key, hash_or_num_value_parser}; use reth_config::Config; use reth_network::NetworkConfigBuilder; use reth_network_p2p::bodies::client::BodiesClient; diff --git a/bin/reth/src/commands/stage/run.rs b/bin/reth/src/commands/stage/run.rs index 101b89e0277a..2ceb8fe852a8 100644 --- a/bin/reth/src/commands/stage/run.rs +++ b/bin/reth/src/commands/stage/run.rs @@ -2,7 +2,7 @@ //! //! Stage debugging tool use crate::{ - args::{get_secret_key, NetworkArgs, StageEnum}, + args::{NetworkArgs, StageEnum}, macros::block_executor, prometheus_exporter, }; @@ -10,6 +10,7 @@ use clap::Parser; use reth_beacon_consensus::EthBeaconConsensus; use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs}; use reth_cli_runner::CliContext; +use reth_cli_util::get_secret_key; use reth_config::config::{HashingConfig, SenderRecoveryConfig, TransactionLookupConfig}; use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder; use reth_exex::ExExManagerHandle; diff --git a/crates/cli/util/Cargo.toml b/crates/cli/util/Cargo.toml new file mode 100644 index 000000000000..f38421bc0954 --- /dev/null +++ b/crates/cli/util/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "reth-cli-util" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +exclude.workspace = true + +[dependencies] +reth-fs-util.workspace = true +reth-network.workspace = true +reth-primitives.workspace = true +secp256k1.workspace = true +thiserror.workspace = true +eyre.workspace = true + +[dev-dependencies] +proptest.workspace = true + +[lints] +workspace = true diff --git a/crates/cli/util/src/lib.rs b/crates/cli/util/src/lib.rs new file mode 100644 index 000000000000..39d7b7f98a51 --- /dev/null +++ b/crates/cli/util/src/lib.rs @@ -0,0 +1,17 @@ +//! This crate defines a set of commonly used cli utils. + +#![doc( + html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", + html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", + issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + +/// Helper function to load a secret key from a file. +pub mod load_secret_key; +pub use load_secret_key::get_secret_key; + +/// Cli parsers functions. +pub mod parsers; +pub use parsers::{hash_or_num_value_parser, parse_duration_from_secs, parse_socket_address}; diff --git a/crates/node/core/src/args/secret_key.rs b/crates/cli/util/src/load_secret_key.rs similarity index 100% rename from crates/node/core/src/args/secret_key.rs rename to crates/cli/util/src/load_secret_key.rs diff --git a/crates/cli/util/src/parsers.rs b/crates/cli/util/src/parsers.rs new file mode 100644 index 000000000000..5e7c8c785373 --- /dev/null +++ b/crates/cli/util/src/parsers.rs @@ -0,0 +1,96 @@ +use reth_primitives::{BlockHashOrNumber, B256}; +use std::{ + net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs}, + str::FromStr, + time::Duration, +}; + +/// Helper to parse a [Duration] from seconds +pub fn parse_duration_from_secs(arg: &str) -> eyre::Result { + let seconds = arg.parse()?; + Ok(Duration::from_secs(seconds)) +} + +/// Parse [`BlockHashOrNumber`] +pub fn hash_or_num_value_parser(value: &str) -> eyre::Result { + match B256::from_str(value) { + Ok(hash) => Ok(BlockHashOrNumber::Hash(hash)), + Err(_) => Ok(BlockHashOrNumber::Number(value.parse()?)), + } +} + +/// Error thrown while parsing a socket address. +#[derive(thiserror::Error, Debug)] +pub enum SocketAddressParsingError { + /// Failed to convert the string into a socket addr + #[error("could not parse socket address: {0}")] + Io(#[from] std::io::Error), + /// Input must not be empty + #[error("cannot parse socket address from empty string")] + Empty, + /// Failed to parse the address + #[error("could not parse socket address from {0}")] + Parse(String), + /// Failed to parse port + #[error("could not parse port: {0}")] + Port(#[from] std::num::ParseIntError), +} + +/// Parse a [`SocketAddr`] from a `str`. +/// +/// The following formats are checked: +/// +/// - If the value can be parsed as a `u16` or starts with `:` it is considered a port, and the +/// hostname is set to `localhost`. +/// - If the value contains `:` it is assumed to be the format `:` +/// - Otherwise it is assumed to be a hostname +/// +/// An error is returned if the value is empty. +pub fn parse_socket_address(value: &str) -> eyre::Result { + if value.is_empty() { + return Err(SocketAddressParsingError::Empty) + } + + if let Some(port) = value.strip_prefix(':').or_else(|| value.strip_prefix("localhost:")) { + let port: u16 = port.parse()?; + return Ok(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port)) + } + if let Ok(port) = value.parse::() { + return Ok(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port)) + } + value + .to_socket_addrs()? + .next() + .ok_or_else(|| SocketAddressParsingError::Parse(value.to_string())) +} + +#[cfg(test)] +mod tests { + use super::*; + use proptest::prelude::Rng; + use secp256k1::rand::thread_rng; + + #[test] + fn parse_socket_addresses() { + for value in ["localhost:9000", ":9000", "9000"] { + let socket_addr = parse_socket_address(value) + .unwrap_or_else(|_| panic!("could not parse socket address: {value}")); + + assert!(socket_addr.ip().is_loopback()); + assert_eq!(socket_addr.port(), 9000); + } + } + + #[test] + fn parse_socket_address_random() { + let port: u16 = thread_rng().gen(); + + for value in [format!("localhost:{port}"), format!(":{port}"), port.to_string()] { + let socket_addr = parse_socket_address(&value) + .unwrap_or_else(|_| panic!("could not parse socket address: {value}")); + + assert!(socket_addr.ip().is_loopback()); + assert_eq!(socket_addr.port(), port); + } + } +} diff --git a/crates/node/builder/Cargo.toml b/crates/node/builder/Cargo.toml index 351dbc3d8501..f15ec8774611 100644 --- a/crates/node/builder/Cargo.toml +++ b/crates/node/builder/Cargo.toml @@ -46,6 +46,7 @@ reth-consensus.workspace = true reth-consensus-debug-client.workspace = true reth-rpc-types.workspace = true reth-engine-util.workspace = true +reth-cli-util.workspace = true ## async futures.workspace = true diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index dbdef2291460..23a18ee309fe 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -11,6 +11,7 @@ use crate::{ }; use futures::Future; use reth_chainspec::ChainSpec; +use reth_cli_util::get_secret_key; use reth_db::{ test_utils::{create_test_rw_db_with_path, tempdir_path, TempDatabase}, DatabaseEnv, @@ -25,7 +26,7 @@ use reth_network::{ }; use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes}; use reth_node_core::{ - args::{get_secret_key, DatadirArgs}, + args::DatadirArgs, cli::config::{PayloadBuilderConfig, RethTransactionPoolConfig}, dirs::{ChainPath, DataDirPath, MaybePlatformPath}, node_config::NodeConfig, diff --git a/crates/node/core/Cargo.toml b/crates/node/core/Cargo.toml index db72a5e00ee7..5dc0ed8f5cf8 100644 --- a/crates/node/core/Cargo.toml +++ b/crates/node/core/Cargo.toml @@ -14,6 +14,7 @@ workspace = true # reth reth-chainspec.workspace = true reth-primitives.workspace = true +reth-cli-util.workspace = true reth-fs-util.workspace = true reth-db = { workspace = true, features = ["mdbx"] } reth-db-api.workspace = true @@ -57,7 +58,6 @@ metrics-util.workspace = true eyre.workspace = true clap = { workspace = true, features = ["derive"] } humantime.workspace = true -thiserror.workspace = true const_format.workspace = true rand.workspace = true derive_more.workspace = true diff --git a/crates/node/core/src/args/mod.rs b/crates/node/core/src/args/mod.rs index 469ff72ea159..7d1f61903ffb 100644 --- a/crates/node/core/src/args/mod.rs +++ b/crates/node/core/src/args/mod.rs @@ -24,9 +24,6 @@ pub use database::DatabaseArgs; mod log; pub use log::{ColorMode, LogArgs}; -mod secret_key; -pub use secret_key::{get_secret_key, SecretKeyError}; - /// `PayloadBuilderArgs` struct for configuring the payload builder mod payload_builder; pub use payload_builder::PayloadBuilderArgs; diff --git a/crates/node/core/src/args/payload_builder.rs b/crates/node/core/src/args/payload_builder.rs index b6a937156de5..7d3b5f851e86 100644 --- a/crates/node/core/src/args/payload_builder.rs +++ b/crates/node/core/src/args/payload_builder.rs @@ -1,11 +1,9 @@ -use crate::{ - args::utils::parse_duration_from_secs, cli::config::PayloadBuilderConfig, - version::default_extradata, -}; +use crate::{cli::config::PayloadBuilderConfig, version::default_extradata}; use clap::{ builder::{RangedU64ValueParser, TypedValueParser}, Arg, Args, Command, }; +use reth_cli_util::parse_duration_from_secs; use reth_primitives::constants::{ ETHEREUM_BLOCK_GAS_LIMIT, MAXIMUM_EXTRA_DATA_SIZE, SLOT_DURATION, }; diff --git a/crates/node/core/src/args/utils.rs b/crates/node/core/src/args/utils.rs index 8a54a8942e1c..c80626f884cf 100644 --- a/crates/node/core/src/args/utils.rs +++ b/crates/node/core/src/args/utils.rs @@ -3,14 +3,7 @@ use alloy_genesis::Genesis; use reth_chainspec::ChainSpec; use reth_fs_util as fs; -use reth_primitives::{BlockHashOrNumber, B256}; -use std::{ - net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs}, - path::PathBuf, - str::FromStr, - sync::Arc, - time::Duration, -}; +use std::{path::PathBuf, sync::Arc}; use reth_chainspec::DEV; @@ -27,12 +20,6 @@ pub const SUPPORTED_CHAINS: &[&str] = &["optimism", "optimism-sepolia", "base", /// Chains supported by reth. First value should be used as the default. pub const SUPPORTED_CHAINS: &[&str] = &["mainnet", "sepolia", "goerli", "holesky", "dev"]; -/// Helper to parse a [Duration] from seconds -pub fn parse_duration_from_secs(arg: &str) -> eyre::Result { - let seconds = arg.parse()?; - Ok(Duration::from_secs(seconds)) -} - /// The help info for the --chain flag pub fn chain_help() -> String { format!("The chain this node is running.\nPossible values are either a built-in chain or the path to a chain specification file.\n\nBuilt-in chains:\n {}", SUPPORTED_CHAINS.join(", ")) @@ -83,64 +70,9 @@ pub fn chain_value_parser(s: &str) -> eyre::Result, eyre::Error> }) } -/// Parse [`BlockHashOrNumber`] -pub fn hash_or_num_value_parser(value: &str) -> eyre::Result { - match B256::from_str(value) { - Ok(hash) => Ok(BlockHashOrNumber::Hash(hash)), - Err(_) => Ok(BlockHashOrNumber::Number(value.parse()?)), - } -} - -/// Error thrown while parsing a socket address. -#[derive(thiserror::Error, Debug)] -pub enum SocketAddressParsingError { - /// Failed to convert the string into a socket addr - #[error("could not parse socket address: {0}")] - Io(#[from] std::io::Error), - /// Input must not be empty - #[error("cannot parse socket address from empty string")] - Empty, - /// Failed to parse the address - #[error("could not parse socket address from {0}")] - Parse(String), - /// Failed to parse port - #[error("could not parse port: {0}")] - Port(#[from] std::num::ParseIntError), -} - -/// Parse a [`SocketAddr`] from a `str`. -/// -/// The following formats are checked: -/// -/// - If the value can be parsed as a `u16` or starts with `:` it is considered a port, and the -/// hostname is set to `localhost`. -/// - If the value contains `:` it is assumed to be the format `:` -/// - Otherwise it is assumed to be a hostname -/// -/// An error is returned if the value is empty. -pub fn parse_socket_address(value: &str) -> eyre::Result { - if value.is_empty() { - return Err(SocketAddressParsingError::Empty) - } - - if let Some(port) = value.strip_prefix(':').or_else(|| value.strip_prefix("localhost:")) { - let port: u16 = port.parse()?; - return Ok(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port)) - } - if let Ok(port) = value.parse::() { - return Ok(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port)) - } - value - .to_socket_addrs()? - .next() - .ok_or_else(|| SocketAddressParsingError::Parse(value.to_string())) -} - #[cfg(test)] mod tests { use super::*; - use proptest::prelude::Rng; - use secp256k1::rand::thread_rng; #[test] fn parse_known_chain_spec() { @@ -148,28 +80,4 @@ mod tests { chain_value_parser(chain).unwrap(); } } - - #[test] - fn parse_socket_addresses() { - for value in ["localhost:9000", ":9000", "9000"] { - let socket_addr = parse_socket_address(value) - .unwrap_or_else(|_| panic!("could not parse socket address: {value}")); - - assert!(socket_addr.ip().is_loopback()); - assert_eq!(socket_addr.port(), 9000); - } - } - - #[test] - fn parse_socket_address_random() { - let port: u16 = thread_rng().gen(); - - for value in [format!("localhost:{port}"), format!(":{port}"), port.to_string()] { - let socket_addr = parse_socket_address(&value) - .unwrap_or_else(|_| panic!("could not parse socket address: {value}")); - - assert!(socket_addr.ip().is_loopback()); - assert_eq!(socket_addr.port(), port); - } - } }