mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 23:38:10 -05:00
fix: op-reth chain arg (#15457)
This commit is contained in:
@@ -268,7 +268,7 @@ pub enum Commands<C: ChainSpecParser, Ext: clap::Args + fmt::Debug> {
|
||||
|
||||
impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Commands<C, Ext> {
|
||||
/// Returns the underlying chain being used for commands
|
||||
fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
match self {
|
||||
Self::Node(cmd) => cmd.chain_spec(),
|
||||
Self::Init(cmd) => cmd.chain_spec(),
|
||||
@@ -280,7 +280,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>, Ext: clap::Args + fmt::Debug> Co
|
||||
Self::P2P(cmd) => cmd.chain_spec(),
|
||||
#[cfg(feature = "dev")]
|
||||
Self::TestVectors(cmd) => cmd.chain_spec(),
|
||||
Self::Config(cmd) => cmd.chain_spec(),
|
||||
Self::Config(_) => None,
|
||||
Self::Debug(cmd) => cmd.chain_spec(),
|
||||
Self::Recover(cmd) => cmd.chain_spec(),
|
||||
Self::Prune(cmd) => cmd.chain_spec(),
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
use clap::Parser;
|
||||
use eyre::{bail, WrapErr};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_config::Config;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use std::path::PathBuf;
|
||||
/// `reth config` command
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Command {
|
||||
@@ -35,8 +34,4 @@ impl Command {
|
||||
println!("{}", toml::to_string_pretty(&config)?);
|
||||
Ok(())
|
||||
}
|
||||
/// Returns the underlying chain being used to run this command
|
||||
pub fn chain_spec(&self) -> Option<&Arc<ChainSpec>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,9 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitStateC
|
||||
info!(target: "reth::cli", hash = ?hash, "Genesis block written");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser> InitStateCommand<C> {
|
||||
/// Returns the underlying chain being used to run this command
|
||||
pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
Some(&self.env.chain)
|
||||
|
||||
@@ -33,6 +33,9 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
|
||||
Subcommands::StorageTries(command) => command.execute::<N>(ctx).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser> Command<C> {
|
||||
/// Returns the underlying chain being used to run this command
|
||||
pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
match &self.command {
|
||||
|
||||
@@ -66,6 +66,9 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser> Command<C> {
|
||||
/// Returns the underlying chain being used to run this command
|
||||
pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
Some(&self.env.chain)
|
||||
|
||||
@@ -157,3 +157,10 @@ impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportOpCommand<C> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser> ImportOpCommand<C> {
|
||||
/// Returns the underlying chain being used to run this command
|
||||
pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
Some(&self.env.chain)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//! Command that imports OP mainnet receipts from Bedrock datadir, exported via
|
||||
//! <https://github.com/testinprod-io/op-geth/pull/1>.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::receipt_file_codec::OpGethReceiptFileCodec;
|
||||
use clap::Parser;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs};
|
||||
@@ -24,10 +23,12 @@ use reth_provider::{
|
||||
};
|
||||
use reth_stages::{StageCheckpoint, StageId};
|
||||
use reth_static_file_types::StaticFileSegment;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use tracing::{debug, info, trace, warn};
|
||||
|
||||
use crate::receipt_file_codec::OpGethReceiptFileCodec;
|
||||
|
||||
/// Initializes the database with the genesis block.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ImportReceiptsOpCommand<C: ChainSpecParser> {
|
||||
@@ -80,6 +81,13 @@ impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportReceiptsOpCommand<C> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser> ImportReceiptsOpCommand<C> {
|
||||
/// Returns the underlying chain being used to run this command
|
||||
pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
Some(&self.env.chain)
|
||||
}
|
||||
}
|
||||
|
||||
/// Imports receipts to static files from file in chunks. See [`import_receipts_from_reader`].
|
||||
pub async fn import_receipts_from_file<N, P, F>(
|
||||
provider_factory: ProviderFactory<N>,
|
||||
|
||||
@@ -14,7 +14,7 @@ use reth_provider::{
|
||||
BlockNumReader, ChainSpecProvider, DatabaseProviderFactory, StaticFileProviderFactory,
|
||||
StaticFileWriter,
|
||||
};
|
||||
use std::io::BufReader;
|
||||
use std::{io::BufReader, sync::Arc};
|
||||
use tracing::info;
|
||||
|
||||
/// Initializes the database with the genesis block.
|
||||
@@ -84,3 +84,10 @@ impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> InitStateCommandOp<C> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: ChainSpecParser> InitStateCommandOp<C> {
|
||||
/// Returns the underlying chain being used to run this command
|
||||
pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
self.init_state.chain_spec()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ use crate::chainspec::OpChainSpecParser;
|
||||
use clap::Subcommand;
|
||||
use import::ImportOpCommand;
|
||||
use import_receipts::ImportReceiptsOpCommand;
|
||||
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_commands::{
|
||||
config_cmd, db, dump_genesis, init_cmd,
|
||||
node::{self, NoArgs},
|
||||
p2p, prune, recover, stage,
|
||||
};
|
||||
use std::fmt;
|
||||
use std::{fmt, sync::Arc};
|
||||
|
||||
pub mod import;
|
||||
pub mod import_receipts;
|
||||
@@ -62,3 +63,29 @@ pub enum Commands<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + f
|
||||
#[command(name = "test-vectors")]
|
||||
TestVectors(test_vectors::Command),
|
||||
}
|
||||
|
||||
impl<
|
||||
C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>,
|
||||
Ext: clap::Args + fmt::Debug,
|
||||
> Commands<C, Ext>
|
||||
{
|
||||
/// Returns the underlying chain being used for commands
|
||||
pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
|
||||
match self {
|
||||
Self::Node(cmd) => cmd.chain_spec(),
|
||||
Self::Init(cmd) => cmd.chain_spec(),
|
||||
Self::InitState(cmd) => cmd.chain_spec(),
|
||||
Self::DumpGenesis(cmd) => cmd.chain_spec(),
|
||||
Self::Db(cmd) => cmd.chain_spec(),
|
||||
Self::Stage(cmd) => cmd.chain_spec(),
|
||||
Self::P2P(cmd) => cmd.chain_spec(),
|
||||
Self::Config(_) => None,
|
||||
Self::Recover(cmd) => cmd.chain_spec(),
|
||||
Self::Prune(cmd) => cmd.chain_spec(),
|
||||
Self::ImportOp(cmd) => cmd.chain_spec(),
|
||||
Self::ImportReceiptsOp(cmd) => cmd.chain_spec(),
|
||||
#[cfg(feature = "dev")]
|
||||
Self::TestVectors(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ use chainspec::OpChainSpecParser;
|
||||
use clap::{command, value_parser, Parser};
|
||||
use commands::Commands;
|
||||
use futures_util::Future;
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_runner::CliRunner;
|
||||
use reth_db::DatabaseEnv;
|
||||
@@ -70,19 +69,6 @@ pub struct Cli<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt:
|
||||
#[command(subcommand)]
|
||||
pub command: Commands<Spec, Ext>,
|
||||
|
||||
/// The chain this node is running.
|
||||
///
|
||||
/// Possible values are either a built-in chain or the path to a chain specification file.
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "CHAIN_OR_PATH",
|
||||
long_help = Spec::help_message(),
|
||||
default_value = Spec::SUPPORTED_CHAINS[0],
|
||||
value_parser = Spec::parser(),
|
||||
global = true,
|
||||
)]
|
||||
pub chain: Arc<Spec::ChainSpec>,
|
||||
|
||||
/// Add a new instance of a node.
|
||||
///
|
||||
/// Configures the ports of the node to avoid conflicts with the defaults.
|
||||
@@ -144,9 +130,11 @@ where
|
||||
Fut: Future<Output = eyre::Result<()>>,
|
||||
{
|
||||
// add network name to logs dir
|
||||
self.logs.log_file_directory =
|
||||
self.logs.log_file_directory.join(self.chain.chain().to_string());
|
||||
|
||||
// Add network name if available to the logs dir
|
||||
if let Some(chain_spec) = self.command.chain_spec() {
|
||||
self.logs.log_file_directory =
|
||||
self.logs.log_file_directory.join(chain_spec.chain.to_string());
|
||||
}
|
||||
let _guard = self.init_tracing()?;
|
||||
info!(target: "reth::cli", "Initialized tracing, debug log directory: {}", self.logs.log_file_directory);
|
||||
|
||||
@@ -201,10 +189,11 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::chainspec::OpChainSpecParser;
|
||||
use crate::{chainspec::OpChainSpecParser, commands::Commands, Cli};
|
||||
use clap::Parser;
|
||||
use reth_cli_commands::{node::NoArgs, NodeCommand};
|
||||
use reth_optimism_chainspec::OP_DEV;
|
||||
use reth_optimism_chainspec::{BASE_MAINNET, OP_DEV};
|
||||
use reth_optimism_node::args::RollupArgs;
|
||||
|
||||
#[test]
|
||||
fn parse_dev() {
|
||||
@@ -223,4 +212,49 @@ mod test {
|
||||
|
||||
assert!(cmd.dev.dev);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_node() {
|
||||
let cmd = Cli::<OpChainSpecParser, RollupArgs>::parse_from([
|
||||
"op-reth",
|
||||
"node",
|
||||
"--chain",
|
||||
"base",
|
||||
"--datadir",
|
||||
"/mnt/datadirs/base",
|
||||
"--instance",
|
||||
"2",
|
||||
"--http",
|
||||
"--http.addr",
|
||||
"0.0.0.0",
|
||||
"--ws",
|
||||
"--ws.addr",
|
||||
"0.0.0.0",
|
||||
"--http.api",
|
||||
"admin,debug,eth,net,trace,txpool,web3,rpc,reth,ots",
|
||||
"--rollup.sequencer-http",
|
||||
"https://mainnet-sequencer.base.org",
|
||||
"--rpc-max-tracing-requests",
|
||||
"1000000",
|
||||
"--rpc.gascap",
|
||||
"18446744073709551615",
|
||||
"--rpc.max-connections",
|
||||
"429496729",
|
||||
"--rpc.max-logs-per-response",
|
||||
"0",
|
||||
"--rpc.max-subscriptions-per-connection",
|
||||
"10000",
|
||||
"--metrics",
|
||||
"9003",
|
||||
"--log.file.max-size",
|
||||
"100",
|
||||
]);
|
||||
|
||||
match cmd.command {
|
||||
Commands::Node(command) => {
|
||||
assert_eq!(command.chain.as_ref(), BASE_MAINNET.as_ref());
|
||||
}
|
||||
_ => panic!("unexpected command"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user