From 0caf0518697ad27f16516c4fa536ce604dbd5290 Mon Sep 17 00:00:00 2001 From: byyou Date: Fri, 26 May 2023 13:56:28 +0000 Subject: [PATCH] feat: reth-config crate (#2825) --- Cargo.lock | 16 +++++++++++ Cargo.toml | 1 + bin/reth/Cargo.toml | 3 +- bin/reth/src/args/network_args.rs | 2 +- bin/reth/src/chain/import.rs | 10 +++---- bin/reth/src/config.rs | 2 +- bin/reth/src/debug_cmd/execution.rs | 10 +++---- bin/reth/src/node/mod.rs | 12 ++++---- bin/reth/src/p2p/mod.rs | 6 ++-- bin/reth/src/stage/run.rs | 6 ++-- crates/config/Cargo.toml | 30 ++++++++++++++++++++ crates/{staged-sync => config}/src/config.rs | 0 crates/config/src/lib.rs | 11 +++++++ crates/staged-sync/Cargo.toml | 2 +- crates/staged-sync/src/lib.rs | 4 --- 15 files changed, 80 insertions(+), 35 deletions(-) create mode 100644 crates/config/Cargo.toml rename crates/{staged-sync => config}/src/config.rs (100%) create mode 100644 crates/config/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 23060933fb..422a537f65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4595,6 +4595,7 @@ dependencies = [ "reth-basic-payload-builder", "reth-beacon-consensus", "reth-blockchain-tree", + "reth-config", "reth-db", "reth-discv4", "reth-downloaders", @@ -4723,6 +4724,21 @@ dependencies = [ "test-fuzz", ] +[[package]] +name = "reth-config" +version = "0.1.0" +dependencies = [ + "confy", + "reth-discv4", + "reth-downloaders", + "reth-net-nat", + "reth-network", + "secp256k1", + "serde", + "serde_json", + "tempfile", +] + [[package]] name = "reth-consensus-common" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index e05b0b95eb..cc1dd0d97d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "bin/reth", + "crates/config", "crates/consensus/auto-seal", "crates/consensus/beacon", "crates/consensus/common", diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 3783dd3e9c..315df9d16f 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -9,6 +9,7 @@ build = "build.rs" [dependencies] # reth +reth-config = { path = "../../crates/config" } reth-primitives = { path = "../../crates/primitives", features = ["arbitrary"] } reth-db = { path = "../../crates/storage/db", features = ["mdbx", "test-utils"] } # TODO: Temporary use of the test-utils feature @@ -92,4 +93,4 @@ jemalloc = ["dep:jemallocator"] only-info-logs = ["tracing/release_max_level_info"] [build-dependencies] -vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl"] } \ No newline at end of file +vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl"] } diff --git a/bin/reth/src/args/network_args.rs b/bin/reth/src/args/network_args.rs index cdf0d483f4..8027c3022c 100644 --- a/bin/reth/src/args/network_args.rs +++ b/bin/reth/src/args/network_args.rs @@ -2,10 +2,10 @@ use crate::version::P2P_CLIENT_VERSION; use clap::Args; +use reth_config::Config; use reth_net_nat::NatResolver; use reth_network::{HelloMessage, NetworkConfigBuilder}; use reth_primitives::{mainnet_nodes, ChainSpec, NodeRecord}; -use reth_staged_sync::Config; use secp256k1::SecretKey; use std::{path::PathBuf, sync::Arc}; diff --git a/bin/reth/src/chain/import.rs b/bin/reth/src/chain/import.rs index 420feb8727..5f3f9ea642 100644 --- a/bin/reth/src/chain/import.rs +++ b/bin/reth/src/chain/import.rs @@ -8,6 +8,7 @@ use eyre::Context; use futures::{Stream, StreamExt}; use reth_beacon_consensus::BeaconConsensus; +use reth_config::Config; use reth_db::database::Database; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, @@ -15,12 +16,9 @@ use reth_downloaders::{ }; use reth_interfaces::consensus::Consensus; use reth_primitives::{ChainSpec, H256}; -use reth_staged_sync::{ - utils::{ - chainspec::genesis_value_parser, - init::{init_db, init_genesis}, - }, - Config, +use reth_staged_sync::utils::{ + chainspec::genesis_value_parser, + init::{init_db, init_genesis}, }; use reth_stages::{ prelude::*, diff --git a/bin/reth/src/config.rs b/bin/reth/src/config.rs index ef8527bafa..f46860559a 100644 --- a/bin/reth/src/config.rs +++ b/bin/reth/src/config.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use clap::Parser; use eyre::{bail, WrapErr}; -use reth_staged_sync::Config; +use reth_config::Config; /// `reth config` command #[derive(Debug, Parser)] diff --git a/bin/reth/src/debug_cmd/execution.rs b/bin/reth/src/debug_cmd/execution.rs index e2a7de034f..ecaff0885c 100644 --- a/bin/reth/src/debug_cmd/execution.rs +++ b/bin/reth/src/debug_cmd/execution.rs @@ -9,6 +9,7 @@ use crate::{ use clap::Parser; use futures::{stream::select as stream_select, StreamExt}; use reth_beacon_consensus::BeaconConsensus; +use reth_config::Config; use reth_db::{ database::Database, mdbx::{Env, WriteMap}, @@ -26,12 +27,9 @@ use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; use reth_primitives::{BlockHashOrNumber, BlockNumber, ChainSpec, H256}; use reth_provider::{ShareableDatabase, Transaction}; -use reth_staged_sync::{ - utils::{ - chainspec::genesis_value_parser, - init::{init_db, init_genesis}, - }, - Config, +use reth_staged_sync::utils::{ + chainspec::genesis_value_parser, + init::{init_db, init_genesis}, }; use reth_stages::{ sets::DefaultStages, diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index 699e16b995..dbb0dc66eb 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -19,6 +19,7 @@ use reth_beacon_consensus::{BeaconConsensus, BeaconConsensusEngine}; use reth_blockchain_tree::{ config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, ShareableBlockchainTree, }; +use reth_config::Config; use reth_db::{ database::Database, mdbx::{Env, WriteMap}, @@ -45,13 +46,10 @@ use reth_provider::{BlockProvider, CanonStateSubscriptions, HeaderProvider, Shar use reth_revm::Factory; use reth_revm_inspectors::stack::Hook; use reth_rpc_engine_api::EngineApi; -use reth_staged_sync::{ - utils::{ - chainspec::genesis_value_parser, - init::{init_db, init_genesis}, - parse_socket_address, - }, - Config, +use reth_staged_sync::utils::{ + chainspec::genesis_value_parser, + init::{init_db, init_genesis}, + parse_socket_address, }; use reth_stages::{ prelude::*, diff --git a/bin/reth/src/p2p/mod.rs b/bin/reth/src/p2p/mod.rs index c6a4851294..8c8811d0b5 100644 --- a/bin/reth/src/p2p/mod.rs +++ b/bin/reth/src/p2p/mod.rs @@ -6,15 +6,13 @@ use crate::{ }; use backon::{ConstantBuilder, Retryable}; use clap::{Parser, Subcommand}; +use reth_config::Config; use reth_db::mdbx::{Env, EnvKind, WriteMap}; use reth_discv4::NatResolver; use reth_interfaces::p2p::bodies::client::BodiesClient; use reth_primitives::{BlockHashOrNumber, ChainSpec, NodeRecord}; use reth_provider::ShareableDatabase; -use reth_staged_sync::{ - utils::{chainspec::chain_spec_value_parser, hash_or_num_value_parser}, - Config, -}; +use reth_staged_sync::utils::{chainspec::chain_spec_value_parser, hash_or_num_value_parser}; use std::{path::PathBuf, sync::Arc}; /// `reth p2p` command diff --git a/bin/reth/src/stage/run.rs b/bin/reth/src/stage/run.rs index 5f8c56827c..fe05679ae1 100644 --- a/bin/reth/src/stage/run.rs +++ b/bin/reth/src/stage/run.rs @@ -9,13 +9,11 @@ use crate::{ }; use clap::Parser; use reth_beacon_consensus::BeaconConsensus; +use reth_config::Config; use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder; use reth_primitives::{ChainSpec, StageCheckpoint}; use reth_provider::{ShareableDatabase, Transaction}; -use reth_staged_sync::{ - utils::{chainspec::chain_spec_value_parser, init::init_db}, - Config, -}; +use reth_staged_sync::utils::{chainspec::chain_spec_value_parser, init::init_db}; use reth_stages::{ stages::{ BodyStage, ExecutionStage, ExecutionStageThresholds, MerkleStage, SenderRecoveryStage, diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml new file mode 100644 index 0000000000..91fd7164f3 --- /dev/null +++ b/crates/config/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "reth-config" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/paradigmxyz/reth" +readme = "README.md" + +[dependencies] +# reth +reth-network = { path = "../net/network" } +reth-net-nat = { path = "../../crates/net/nat" } +reth-discv4 = { path = "../../crates/net/discv4" } +reth-downloaders = { path = "../../crates/net/downloaders" } + +# io +serde = "1.0" +serde_json = "1.0.91" + +#crypto +secp256k1 = { version = "0.27.0", features = [ + "global-context", + "rand-std", + "recovery", +] } + +confy = "0.5" + +tempfile = "3.4" + diff --git a/crates/staged-sync/src/config.rs b/crates/config/src/config.rs similarity index 100% rename from crates/staged-sync/src/config.rs rename to crates/config/src/config.rs diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs new file mode 100644 index 0000000000..b08290513e --- /dev/null +++ b/crates/config/src/lib.rs @@ -0,0 +1,11 @@ +#![warn(missing_docs, unreachable_pub)] +#![deny(unused_must_use, rust_2018_idioms)] +#![doc(test( + no_crate_inject, + attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) +))] + +//! Standalone crate for Reth config types + +pub mod config; +pub use config::Config; diff --git a/crates/staged-sync/Cargo.toml b/crates/staged-sync/Cargo.toml index a694f47ae3..6c03e946ea 100644 --- a/crates/staged-sync/Cargo.toml +++ b/crates/staged-sync/Cargo.toml @@ -95,4 +95,4 @@ test-utils = [ "dep:ethers-middleware", "dep:async-trait" ] -geth-tests = [] \ No newline at end of file +geth-tests = [] diff --git a/crates/staged-sync/src/lib.rs b/crates/staged-sync/src/lib.rs index 7a8890dc75..b32db26cbb 100644 --- a/crates/staged-sync/src/lib.rs +++ b/crates/staged-sync/src/lib.rs @@ -11,10 +11,6 @@ //! //! - `test-utils`: Various utilities helpful for writing tests //! - `geth-tests`: Runs tests that require Geth to be installed locally. - -pub mod config; -pub use config::Config; - pub mod utils; #[cfg(any(test, feature = "test-utils"))]