mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: Remove duplicate EthereumChainSpecParser in favor of existing EthChainSpecParser (#11412)
Co-authored-by: garwah <garwah@garwah> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -6243,6 +6243,7 @@ dependencies = [
|
|||||||
"reth-downloaders",
|
"reth-downloaders",
|
||||||
"reth-engine-util",
|
"reth-engine-util",
|
||||||
"reth-errors",
|
"reth-errors",
|
||||||
|
"reth-ethereum-cli",
|
||||||
"reth-ethereum-payload-builder",
|
"reth-ethereum-payload-builder",
|
||||||
"reth-evm",
|
"reth-evm",
|
||||||
"reth-execution-types",
|
"reth-execution-types",
|
||||||
@ -6526,9 +6527,12 @@ dependencies = [
|
|||||||
name = "reth-cli"
|
name = "reth-cli"
|
||||||
version = "1.0.8"
|
version = "1.0.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"alloy-genesis",
|
||||||
"clap",
|
"clap",
|
||||||
"eyre",
|
"eyre",
|
||||||
"reth-cli-runner",
|
"reth-cli-runner",
|
||||||
|
"serde_json",
|
||||||
|
"shellexpand",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -6565,6 +6569,7 @@ dependencies = [
|
|||||||
"reth-downloaders",
|
"reth-downloaders",
|
||||||
"reth-ecies",
|
"reth-ecies",
|
||||||
"reth-eth-wire",
|
"reth-eth-wire",
|
||||||
|
"reth-ethereum-cli",
|
||||||
"reth-evm",
|
"reth-evm",
|
||||||
"reth-exex",
|
"reth-exex",
|
||||||
"reth-fs-util",
|
"reth-fs-util",
|
||||||
@ -7229,14 +7234,11 @@ dependencies = [
|
|||||||
name = "reth-ethereum-cli"
|
name = "reth-ethereum-cli"
|
||||||
version = "1.0.8"
|
version = "1.0.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy-genesis",
|
|
||||||
"clap",
|
"clap",
|
||||||
"eyre",
|
"eyre",
|
||||||
"reth-chainspec",
|
"reth-chainspec",
|
||||||
"reth-cli",
|
"reth-cli",
|
||||||
"reth-cli-commands",
|
"reth-cli-commands",
|
||||||
"serde_json",
|
|
||||||
"shellexpand",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -7843,7 +7845,6 @@ dependencies = [
|
|||||||
name = "reth-node-core"
|
name = "reth-node-core"
|
||||||
version = "1.0.8"
|
version = "1.0.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy-genesis",
|
|
||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"alloy-rpc-types-engine",
|
"alloy-rpc-types-engine",
|
||||||
"clap",
|
"clap",
|
||||||
@ -7856,19 +7857,16 @@ dependencies = [
|
|||||||
"proptest",
|
"proptest",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"reth-chainspec",
|
"reth-chainspec",
|
||||||
"reth-cli",
|
|
||||||
"reth-cli-util",
|
"reth-cli-util",
|
||||||
"reth-config",
|
"reth-config",
|
||||||
"reth-consensus-common",
|
"reth-consensus-common",
|
||||||
"reth-db",
|
"reth-db",
|
||||||
"reth-discv4",
|
"reth-discv4",
|
||||||
"reth-discv5",
|
"reth-discv5",
|
||||||
"reth-fs-util",
|
|
||||||
"reth-net-nat",
|
"reth-net-nat",
|
||||||
"reth-network",
|
"reth-network",
|
||||||
"reth-network-p2p",
|
"reth-network-p2p",
|
||||||
"reth-network-peers",
|
"reth-network-peers",
|
||||||
"reth-optimism-chainspec",
|
|
||||||
"reth-primitives",
|
"reth-primitives",
|
||||||
"reth-prune-types",
|
"reth-prune-types",
|
||||||
"reth-rpc-api",
|
"reth-rpc-api",
|
||||||
@ -7883,7 +7881,6 @@ dependencies = [
|
|||||||
"reth-transaction-pool",
|
"reth-transaction-pool",
|
||||||
"secp256k1",
|
"secp256k1",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
|
||||||
"shellexpand",
|
"shellexpand",
|
||||||
"strum",
|
"strum",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
|||||||
@ -15,6 +15,7 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
# reth
|
# reth
|
||||||
reth-cli.workspace = true
|
reth-cli.workspace = true
|
||||||
|
reth-ethereum-cli.workspace = true
|
||||||
reth-chainspec.workspace = true
|
reth-chainspec.workspace = true
|
||||||
reth-config.workspace = true
|
reth-config.workspace = true
|
||||||
reth-primitives.workspace = true
|
reth-primitives.workspace = true
|
||||||
|
|||||||
@ -15,8 +15,8 @@ use reth_cli_commands::{
|
|||||||
};
|
};
|
||||||
use reth_cli_runner::CliRunner;
|
use reth_cli_runner::CliRunner;
|
||||||
use reth_db::DatabaseEnv;
|
use reth_db::DatabaseEnv;
|
||||||
|
use reth_ethereum_cli::chainspec::EthereumChainSpecParser;
|
||||||
use reth_node_builder::{NodeBuilder, WithLaunchContext};
|
use reth_node_builder::{NodeBuilder, WithLaunchContext};
|
||||||
use reth_node_core::args::utils::EthereumChainSpecParser;
|
|
||||||
use reth_node_ethereum::{EthExecutorProvider, EthereumNode};
|
use reth_node_ethereum::{EthExecutorProvider, EthereumNode};
|
||||||
use reth_tracing::FileWorkerGuard;
|
use reth_tracing::FileWorkerGuard;
|
||||||
use std::{ffi::OsString, fmt, future::Future, sync::Arc};
|
use std::{ffi::OsString, fmt, future::Future, sync::Arc};
|
||||||
@ -117,7 +117,8 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Cl
|
|||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use clap::Parser;
|
/// use clap::Parser;
|
||||||
/// use reth::{args::utils::EthereumChainSpecParser, cli::Cli};
|
/// use reth::cli::Cli;
|
||||||
|
/// use reth_ethereum_cli::chainspec::EthereumChainSpecParser;
|
||||||
///
|
///
|
||||||
/// #[derive(Debug, Parser)]
|
/// #[derive(Debug, Parser)]
|
||||||
/// pub struct MyArgs {
|
/// pub struct MyArgs {
|
||||||
@ -238,7 +239,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::args::ColorMode;
|
use crate::args::ColorMode;
|
||||||
use clap::CommandFactory;
|
use clap::CommandFactory;
|
||||||
use reth_node_core::args::utils::SUPPORTED_CHAINS;
|
use reth_ethereum_cli::chainspec::SUPPORTED_CHAINS;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_color_mode() {
|
fn parse_color_mode() {
|
||||||
|
|||||||
@ -90,6 +90,7 @@ pub mod dirs {
|
|||||||
/// Re-exported from `reth_chainspec`
|
/// Re-exported from `reth_chainspec`
|
||||||
pub mod chainspec {
|
pub mod chainspec {
|
||||||
pub use reth_chainspec::*;
|
pub use reth_chainspec::*;
|
||||||
|
pub use reth_ethereum_cli::chainspec::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Re-exported from `reth_provider`.
|
/// Re-exported from `reth_provider`.
|
||||||
|
|||||||
@ -4,7 +4,8 @@
|
|||||||
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();
|
static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::new_allocator();
|
||||||
|
|
||||||
use clap::{Args, Parser};
|
use clap::{Args, Parser};
|
||||||
use reth::{args::utils::EthereumChainSpecParser, cli::Cli};
|
use reth::cli::Cli;
|
||||||
|
use reth_ethereum_cli::chainspec::EthereumChainSpecParser;
|
||||||
use reth_node_builder::{
|
use reth_node_builder::{
|
||||||
engine_tree_config::{
|
engine_tree_config::{
|
||||||
TreeConfig, DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD,
|
TreeConfig, DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD,
|
||||||
|
|||||||
@ -15,9 +15,13 @@ workspace = true
|
|||||||
# reth
|
# reth
|
||||||
reth-cli-runner.workspace = true
|
reth-cli-runner.workspace = true
|
||||||
|
|
||||||
|
alloy-genesis.workspace = true
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
clap.workspace = true
|
clap.workspace = true
|
||||||
|
shellexpand.workspace = true
|
||||||
eyre.workspace = true
|
eyre.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use std::sync::Arc;
|
use std::{fs, path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use clap::builder::TypedValueParser;
|
use clap::builder::TypedValueParser;
|
||||||
|
|
||||||
@ -61,3 +61,21 @@ pub trait ChainSpecParser: Clone + Send + Sync + 'static {
|
|||||||
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 {}", Self::SUPPORTED_CHAINS.join(", "))
|
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 {}", Self::SUPPORTED_CHAINS.join(", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A helper to parse a [`Genesis`](alloy_genesis::Genesis) as argument or from disk.
|
||||||
|
pub fn parse_genesis(s: &str) -> eyre::Result<alloy_genesis::Genesis> {
|
||||||
|
// try to read json from path first
|
||||||
|
let raw = match fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned())) {
|
||||||
|
Ok(raw) => raw,
|
||||||
|
Err(io_err) => {
|
||||||
|
// valid json may start with "\n", but must contain "{"
|
||||||
|
if s.contains('{') {
|
||||||
|
s.to_string()
|
||||||
|
} else {
|
||||||
|
return Err(io_err.into()) // assume invalid path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(serde_json::from_str(&raw)?)
|
||||||
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ repository.workspace = true
|
|||||||
reth-beacon-consensus.workspace = true
|
reth-beacon-consensus.workspace = true
|
||||||
reth-chainspec.workspace = true
|
reth-chainspec.workspace = true
|
||||||
reth-cli.workspace = true
|
reth-cli.workspace = true
|
||||||
|
reth-ethereum-cli.workspace = true
|
||||||
reth-cli-runner.workspace = true
|
reth-cli-runner.workspace = true
|
||||||
reth-cli-util.workspace = true
|
reth-cli-util.workspace = true
|
||||||
reth-config.workspace = true
|
reth-config.workspace = true
|
||||||
|
|||||||
@ -160,7 +160,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use reth_node_core::args::utils::{EthereumChainSpecParser, SUPPORTED_CHAINS};
|
use reth_ethereum_cli::chainspec::{EthereumChainSpecParser, SUPPORTED_CHAINS};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@ -32,7 +32,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec>> DumpGenesisCommand<C> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use reth_node_core::args::utils::{EthereumChainSpecParser, SUPPORTED_CHAINS};
|
use reth_ethereum_cli::chainspec::{EthereumChainSpecParser, SUPPORTED_CHAINS};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dump_genesis_command_chain_args() {
|
fn parse_dump_genesis_command_chain_args() {
|
||||||
|
|||||||
@ -231,7 +231,7 @@ where
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use reth_node_core::args::utils::{EthereumChainSpecParser, SUPPORTED_CHAINS};
|
use reth_ethereum_cli::chainspec::{EthereumChainSpecParser, SUPPORTED_CHAINS};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_common_import_command_chain_args() {
|
fn parse_common_import_command_chain_args() {
|
||||||
|
|||||||
@ -6,11 +6,12 @@ use reth_cli::chainspec::ChainSpecParser;
|
|||||||
use reth_cli_runner::CliContext;
|
use reth_cli_runner::CliContext;
|
||||||
use reth_cli_util::parse_socket_address;
|
use reth_cli_util::parse_socket_address;
|
||||||
use reth_db::{init_db, DatabaseEnv};
|
use reth_db::{init_db, DatabaseEnv};
|
||||||
|
use reth_ethereum_cli::chainspec::EthereumChainSpecParser;
|
||||||
use reth_node_builder::{NodeBuilder, WithLaunchContext};
|
use reth_node_builder::{NodeBuilder, WithLaunchContext};
|
||||||
use reth_node_core::{
|
use reth_node_core::{
|
||||||
args::{
|
args::{
|
||||||
utils::EthereumChainSpecParser, DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs,
|
DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs,
|
||||||
PayloadBuilderArgs, PruningArgs, RpcServerArgs, TxPoolArgs,
|
PruningArgs, RpcServerArgs, TxPoolArgs,
|
||||||
},
|
},
|
||||||
node_config::NodeConfig,
|
node_config::NodeConfig,
|
||||||
version,
|
version,
|
||||||
@ -210,7 +211,7 @@ pub struct NoArgs;
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use reth_discv4::DEFAULT_DISCOVERY_PORT;
|
use reth_discv4::DEFAULT_DISCOVERY_PORT;
|
||||||
use reth_node_core::args::utils::SUPPORTED_CHAINS;
|
use reth_ethereum_cli::chainspec::SUPPORTED_CHAINS;
|
||||||
use std::{
|
use std::{
|
||||||
net::{IpAddr, Ipv4Addr},
|
net::{IpAddr, Ipv4Addr},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
|||||||
@ -213,7 +213,7 @@ impl Subcommands {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use reth_node_core::args::utils::EthereumChainSpecParser;
|
use reth_ethereum_cli::chainspec::EthereumChainSpecParser;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|||||||
@ -15,13 +15,6 @@ workspace = true
|
|||||||
reth-cli.workspace = true
|
reth-cli.workspace = true
|
||||||
reth-chainspec.workspace = true
|
reth-chainspec.workspace = true
|
||||||
|
|
||||||
# ethereum
|
|
||||||
alloy-genesis.workspace = true
|
|
||||||
|
|
||||||
# io
|
|
||||||
shellexpand.workspace = true
|
|
||||||
serde_json.workspace = true
|
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
eyre.workspace = true
|
eyre.workspace = true
|
||||||
|
|
||||||
|
|||||||
@ -1,48 +1,33 @@
|
|||||||
use alloy_genesis::Genesis;
|
|
||||||
use reth_chainspec::{ChainSpec, DEV, HOLESKY, MAINNET, SEPOLIA};
|
use reth_chainspec::{ChainSpec, DEV, HOLESKY, MAINNET, SEPOLIA};
|
||||||
use reth_cli::chainspec::ChainSpecParser;
|
use reth_cli::chainspec::{parse_genesis, ChainSpecParser};
|
||||||
use std::{fs, path::PathBuf, sync::Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
/// Chains supported by reth. First value should be used as the default.
|
||||||
|
pub const SUPPORTED_CHAINS: &[&str] = &["mainnet", "sepolia", "holesky", "dev"];
|
||||||
|
|
||||||
/// Clap value parser for [`ChainSpec`]s.
|
/// Clap value parser for [`ChainSpec`]s.
|
||||||
///
|
///
|
||||||
/// The value parser matches either a known chain, the path
|
/// The value parser matches either a known chain, the path
|
||||||
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
|
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
|
||||||
fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
|
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
|
||||||
Ok(match s {
|
Ok(match s {
|
||||||
"mainnet" => MAINNET.clone(),
|
"mainnet" => MAINNET.clone(),
|
||||||
"sepolia" => SEPOLIA.clone(),
|
"sepolia" => SEPOLIA.clone(),
|
||||||
"holesky" => HOLESKY.clone(),
|
"holesky" => HOLESKY.clone(),
|
||||||
"dev" => DEV.clone(),
|
"dev" => DEV.clone(),
|
||||||
_ => {
|
_ => Arc::new(parse_genesis(s)?.into()),
|
||||||
// try to read json from path first
|
|
||||||
let raw = match fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned())) {
|
|
||||||
Ok(raw) => raw,
|
|
||||||
Err(io_err) => {
|
|
||||||
// valid json may start with "\n", but must contain "{"
|
|
||||||
if s.contains('{') {
|
|
||||||
s.to_string()
|
|
||||||
} else {
|
|
||||||
return Err(io_err.into()) // assume invalid path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// both serialized Genesis and ChainSpec structs supported
|
|
||||||
let genesis: Genesis = serde_json::from_str(&raw)?;
|
|
||||||
|
|
||||||
Arc::new(genesis.into())
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ethereum chain specification parser.
|
/// Ethereum chain specification parser.
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct EthChainSpecParser;
|
#[non_exhaustive]
|
||||||
|
pub struct EthereumChainSpecParser;
|
||||||
|
|
||||||
impl ChainSpecParser for EthChainSpecParser {
|
impl ChainSpecParser for EthereumChainSpecParser {
|
||||||
type ChainSpec = ChainSpec;
|
type ChainSpec = ChainSpec;
|
||||||
|
|
||||||
const SUPPORTED_CHAINS: &'static [&'static str] = &["mainnet", "sepolia", "holesky", "dev"];
|
const SUPPORTED_CHAINS: &'static [&'static str] = SUPPORTED_CHAINS;
|
||||||
|
|
||||||
fn parse(s: &str) -> eyre::Result<Arc<ChainSpec>> {
|
fn parse(s: &str) -> eyre::Result<Arc<ChainSpec>> {
|
||||||
chain_value_parser(s)
|
chain_value_parser(s)
|
||||||
@ -56,8 +41,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_known_chain_spec() {
|
fn parse_known_chain_spec() {
|
||||||
for &chain in EthChainSpecParser::SUPPORTED_CHAINS {
|
for &chain in EthereumChainSpecParser::SUPPORTED_CHAINS {
|
||||||
assert!(<EthChainSpecParser as ChainSpecParser>::parse(chain).is_ok());
|
assert!(<EthereumChainSpecParser as ChainSpecParser>::parse(chain).is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +93,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
let spec = <EthChainSpecParser as ChainSpecParser>::parse(s).unwrap();
|
let spec = <EthereumChainSpecParser as ChainSpecParser>::parse(s).unwrap();
|
||||||
assert!(spec.is_shanghai_active_at_timestamp(0));
|
assert!(spec.is_shanghai_active_at_timestamp(0));
|
||||||
assert!(spec.is_cancun_active_at_timestamp(0));
|
assert!(spec.is_cancun_active_at_timestamp(0));
|
||||||
assert!(spec.is_prague_active_at_timestamp(0));
|
assert!(spec.is_prague_active_at_timestamp(0));
|
||||||
|
|||||||
@ -14,9 +14,7 @@ workspace = true
|
|||||||
# reth
|
# reth
|
||||||
reth-chainspec.workspace = true
|
reth-chainspec.workspace = true
|
||||||
reth-primitives.workspace = true
|
reth-primitives.workspace = true
|
||||||
reth-cli.workspace = true
|
|
||||||
reth-cli-util.workspace = true
|
reth-cli-util.workspace = true
|
||||||
reth-fs-util.workspace = true
|
|
||||||
reth-db = { workspace = true, features = ["mdbx"] }
|
reth-db = { workspace = true, features = ["mdbx"] }
|
||||||
reth-storage-errors.workspace = true
|
reth-storage-errors.workspace = true
|
||||||
reth-storage-api.workspace = true
|
reth-storage-api.workspace = true
|
||||||
@ -37,10 +35,8 @@ reth-network-peers.workspace = true
|
|||||||
reth-consensus-common.workspace = true
|
reth-consensus-common.workspace = true
|
||||||
reth-prune-types.workspace = true
|
reth-prune-types.workspace = true
|
||||||
reth-stages-types.workspace = true
|
reth-stages-types.workspace = true
|
||||||
reth-optimism-chainspec = { workspace = true, optional = true }
|
|
||||||
|
|
||||||
# ethereum
|
# ethereum
|
||||||
alloy-genesis.workspace = true
|
|
||||||
alloy-primitives.workspace = true
|
alloy-primitives.workspace = true
|
||||||
alloy-rpc-types-engine = { workspace = true, features = ["jwt"] }
|
alloy-rpc-types-engine = { workspace = true, features = ["jwt"] }
|
||||||
|
|
||||||
@ -59,7 +55,6 @@ thiserror.workspace = true
|
|||||||
# io
|
# io
|
||||||
dirs-next = "2.0.0"
|
dirs-next = "2.0.0"
|
||||||
shellexpand.workspace = true
|
shellexpand.workspace = true
|
||||||
serde_json.workspace = true
|
|
||||||
|
|
||||||
# tracing
|
# tracing
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
@ -85,7 +80,6 @@ optimism = [
|
|||||||
"reth-primitives/optimism",
|
"reth-primitives/optimism",
|
||||||
"reth-rpc-types-compat/optimism",
|
"reth-rpc-types-compat/optimism",
|
||||||
"reth-rpc-eth-api/optimism",
|
"reth-rpc-eth-api/optimism",
|
||||||
"dep:reth-optimism-chainspec",
|
|
||||||
]
|
]
|
||||||
# Features for vergen to generate correct env vars
|
# Features for vergen to generate correct env vars
|
||||||
jemalloc = []
|
jemalloc = []
|
||||||
|
|||||||
@ -56,7 +56,5 @@ pub use datadir_args::DatadirArgs;
|
|||||||
mod benchmark_args;
|
mod benchmark_args;
|
||||||
pub use benchmark_args::BenchmarkArgs;
|
pub use benchmark_args::BenchmarkArgs;
|
||||||
|
|
||||||
pub mod utils;
|
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|||||||
@ -1,99 +0,0 @@
|
|||||||
//! Clap parser utilities
|
|
||||||
|
|
||||||
use std::{path::PathBuf, sync::Arc};
|
|
||||||
|
|
||||||
use alloy_genesis::Genesis;
|
|
||||||
use reth_chainspec::ChainSpec;
|
|
||||||
#[cfg(not(feature = "optimism"))]
|
|
||||||
use reth_chainspec::{DEV, HOLESKY, MAINNET, SEPOLIA};
|
|
||||||
use reth_cli::chainspec::ChainSpecParser;
|
|
||||||
use reth_fs_util as fs;
|
|
||||||
#[cfg(feature = "optimism")]
|
|
||||||
use reth_optimism_chainspec::{BASE_MAINNET, BASE_SEPOLIA, OP_DEV, OP_MAINNET, OP_SEPOLIA};
|
|
||||||
|
|
||||||
#[cfg(feature = "optimism")]
|
|
||||||
/// Chains supported by op-reth. First value should be used as the default.
|
|
||||||
pub const SUPPORTED_CHAINS: &[&str] =
|
|
||||||
&["optimism", "optimism-sepolia", "base", "base-sepolia", "dev"];
|
|
||||||
#[cfg(not(feature = "optimism"))]
|
|
||||||
/// Chains supported by reth. First value should be used as the default.
|
|
||||||
pub const SUPPORTED_CHAINS: &[&str] = &["mainnet", "sepolia", "holesky", "dev"];
|
|
||||||
|
|
||||||
/// Clap value parser for [`ChainSpec`]s.
|
|
||||||
///
|
|
||||||
/// The value parser matches either a known chain, the path
|
|
||||||
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
|
|
||||||
#[cfg(not(feature = "optimism"))]
|
|
||||||
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
|
|
||||||
Ok(match s {
|
|
||||||
"mainnet" => MAINNET.clone(),
|
|
||||||
"sepolia" => SEPOLIA.clone(),
|
|
||||||
"holesky" => HOLESKY.clone(),
|
|
||||||
"dev" => DEV.clone(),
|
|
||||||
_ => Arc::new(parse_custom_chain_spec(s)?),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clap value parser for [`OpChainSpec`](reth_optimism_chainspec::OpChainSpec)s.
|
|
||||||
///
|
|
||||||
/// The value parser matches either a known chain, the path
|
|
||||||
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
|
|
||||||
#[cfg(feature = "optimism")]
|
|
||||||
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>, eyre::Error> {
|
|
||||||
Ok(Arc::new(match s {
|
|
||||||
"optimism" => OP_MAINNET.inner.clone(),
|
|
||||||
"optimism_sepolia" | "optimism-sepolia" => OP_SEPOLIA.inner.clone(),
|
|
||||||
"base" => BASE_MAINNET.inner.clone(),
|
|
||||||
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.inner.clone(),
|
|
||||||
"dev" => OP_DEV.inner.clone(),
|
|
||||||
_ => parse_custom_chain_spec(s)?,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses a custom [`ChainSpec`].
|
|
||||||
pub fn parse_custom_chain_spec(s: &str) -> eyre::Result<ChainSpec, eyre::Error> {
|
|
||||||
// try to read json from path first
|
|
||||||
let raw = match fs::read_to_string(PathBuf::from(shellexpand::full(s)?.into_owned())) {
|
|
||||||
Ok(raw) => raw,
|
|
||||||
Err(io_err) => {
|
|
||||||
// valid json may start with "\n", but must contain "{"
|
|
||||||
if s.contains('{') {
|
|
||||||
s.to_string()
|
|
||||||
} else {
|
|
||||||
return Err(io_err.into()) // assume invalid path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// both serialized Genesis and ChainSpec structs supported
|
|
||||||
let genesis: Genesis = serde_json::from_str(&raw)?;
|
|
||||||
|
|
||||||
Ok(genesis.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A chain specification parser for ethereum chains.
|
|
||||||
#[derive(Debug, Copy, Clone, Default)]
|
|
||||||
#[non_exhaustive]
|
|
||||||
pub struct EthereumChainSpecParser;
|
|
||||||
|
|
||||||
impl ChainSpecParser for EthereumChainSpecParser {
|
|
||||||
type ChainSpec = ChainSpec;
|
|
||||||
|
|
||||||
const SUPPORTED_CHAINS: &'static [&'static str] = SUPPORTED_CHAINS;
|
|
||||||
|
|
||||||
fn parse(s: &str) -> eyre::Result<Arc<ChainSpec>> {
|
|
||||||
chain_value_parser(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn parse_known_chain_spec() {
|
|
||||||
for chain in SUPPORTED_CHAINS {
|
|
||||||
chain_value_parser(chain).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +1,12 @@
|
|||||||
use std::sync::Arc;
|
use reth_cli::chainspec::{parse_genesis, ChainSpecParser};
|
||||||
|
|
||||||
use reth_cli::chainspec::ChainSpecParser;
|
|
||||||
use reth_node_core::args::utils::parse_custom_chain_spec;
|
|
||||||
use reth_optimism_chainspec::{
|
use reth_optimism_chainspec::{
|
||||||
OpChainSpec, BASE_MAINNET, BASE_SEPOLIA, OP_DEV, OP_MAINNET, OP_SEPOLIA,
|
OpChainSpec, BASE_MAINNET, BASE_SEPOLIA, OP_DEV, OP_MAINNET, OP_SEPOLIA,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
/// Clap value parser for [`OpChainSpec`]s.
|
|
||||||
///
|
|
||||||
/// The value parser matches either a known chain, the path
|
|
||||||
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
|
|
||||||
fn chain_value_parser(s: &str) -> eyre::Result<Arc<OpChainSpec>, eyre::Error> {
|
|
||||||
Ok(match s {
|
|
||||||
"dev" => OP_DEV.clone(),
|
|
||||||
"optimism" => OP_MAINNET.clone(),
|
|
||||||
"optimism_sepolia" | "optimism-sepolia" => OP_SEPOLIA.clone(),
|
|
||||||
"base" => BASE_MAINNET.clone(),
|
|
||||||
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
|
|
||||||
_ => Arc::new(OpChainSpec { inner: parse_custom_chain_spec(s)? }),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Optimism chain specification parser.
|
/// Optimism chain specification parser.
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct OpChainSpecParser;
|
pub struct OpChainSpecParser;
|
||||||
|
|
||||||
impl ChainSpecParser for OpChainSpecParser {
|
impl ChainSpecParser for OpChainSpecParser {
|
||||||
@ -43,6 +27,21 @@ impl ChainSpecParser for OpChainSpecParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clap value parser for [`OpChainSpec`]s.
|
||||||
|
///
|
||||||
|
/// The value parser matches either a known chain, the path
|
||||||
|
/// to a json file, or a json formatted string in-memory. The json needs to be a Genesis struct.
|
||||||
|
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<OpChainSpec>, eyre::Error> {
|
||||||
|
Ok(match s {
|
||||||
|
"dev" => OP_DEV.clone(),
|
||||||
|
"optimism" => OP_MAINNET.clone(),
|
||||||
|
"optimism_sepolia" | "optimism-sepolia" => OP_SEPOLIA.clone(),
|
||||||
|
"base" => BASE_MAINNET.clone(),
|
||||||
|
"base_sepolia" | "base-sepolia" => BASE_SEPOLIA.clone(),
|
||||||
|
_ => Arc::new(parse_genesis(s)?.into()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@ -176,13 +176,14 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use crate::chainspec::OpChainSpecParser;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use reth_cli_commands::NodeCommand;
|
use reth_cli_commands::{node::NoArgs, NodeCommand};
|
||||||
use reth_optimism_chainspec::OP_DEV;
|
use reth_optimism_chainspec::OP_DEV;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dev() {
|
fn parse_dev() {
|
||||||
let cmd: NodeCommand = NodeCommand::parse_from(["op-reth", "--dev"]);
|
let cmd = NodeCommand::<OpChainSpecParser, NoArgs>::parse_from(["op-reth", "--dev"]);
|
||||||
let chain = OP_DEV.clone();
|
let chain = OP_DEV.clone();
|
||||||
assert_eq!(cmd.chain.chain, chain.chain);
|
assert_eq!(cmd.chain.chain, chain.chain);
|
||||||
assert_eq!(cmd.chain.genesis_hash, chain.genesis_hash);
|
assert_eq!(cmd.chain.genesis_hash, chain.genesis_hash);
|
||||||
|
|||||||
@ -23,7 +23,7 @@ use clap::Parser;
|
|||||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
use futures_util::{stream::FuturesUnordered, StreamExt};
|
||||||
use mined_sidecar::MinedSidecarStream;
|
use mined_sidecar::MinedSidecarStream;
|
||||||
use reth::{
|
use reth::{
|
||||||
args::utils::EthereumChainSpecParser, builder::NodeHandle, cli::Cli,
|
builder::NodeHandle, chainspec::EthereumChainSpecParser, cli::Cli,
|
||||||
providers::CanonStateSubscriptions,
|
providers::CanonStateSubscriptions,
|
||||||
};
|
};
|
||||||
use reth_node_ethereum::EthereumNode;
|
use reth_node_ethereum::EthereumNode;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ use alloy_rpc_types_beacon::events::PayloadAttributesEvent;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures_util::stream::StreamExt;
|
use futures_util::stream::StreamExt;
|
||||||
use mev_share_sse::{client::EventStream, EventClient};
|
use mev_share_sse::{client::EventStream, EventClient};
|
||||||
use reth::{args::utils::EthereumChainSpecParser, cli::Cli};
|
use reth::{chainspec::EthereumChainSpecParser, cli::Cli};
|
||||||
use reth_node_ethereum::EthereumNode;
|
use reth_node_ethereum::EthereumNode;
|
||||||
use std::net::{IpAddr, Ipv4Addr};
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|||||||
@ -15,8 +15,8 @@ use alloy_rpc_types::state::EvmOverrides;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use reth::{
|
use reth::{
|
||||||
args::utils::EthereumChainSpecParser,
|
|
||||||
builder::NodeHandle,
|
builder::NodeHandle,
|
||||||
|
chainspec::EthereumChainSpecParser,
|
||||||
cli::Cli,
|
cli::Cli,
|
||||||
primitives::BlockNumberOrTag,
|
primitives::BlockNumberOrTag,
|
||||||
revm::{
|
revm::{
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
|
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
|
||||||
use reth::{args::utils::EthereumChainSpecParser, cli::Cli};
|
use reth::{chainspec::EthereumChainSpecParser, cli::Cli};
|
||||||
use reth_node_ethereum::EthereumNode;
|
use reth_node_ethereum::EthereumNode;
|
||||||
use reth_transaction_pool::TransactionPool;
|
use reth_transaction_pool::TransactionPool;
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ use alloy_rpc_types_trace::{parity::TraceType, tracerequest::TraceCallRequest};
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use reth::{
|
use reth::{
|
||||||
args::utils::EthereumChainSpecParser, builder::NodeHandle, cli::Cli,
|
builder::NodeHandle, chainspec::EthereumChainSpecParser, cli::Cli,
|
||||||
rpc::compat::transaction::transaction_to_call_request, transaction_pool::TransactionPool,
|
rpc::compat::transaction::transaction_to_call_request, transaction_pool::TransactionPool,
|
||||||
};
|
};
|
||||||
use reth_node_ethereum::node::EthereumNode;
|
use reth_node_ethereum::node::EthereumNode;
|
||||||
|
|||||||
Reference in New Issue
Block a user