mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: support custom chainspec parser for op (#10804)
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
use clap::Parser;
|
||||
use reth_node_builder::EngineNodeLauncher;
|
||||
use reth_node_optimism::{args::RollupArgs, node::OptimismAddOns, OptimismNode};
|
||||
use reth_optimism_cli::Cli;
|
||||
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
|
||||
use reth_optimism_rpc::eth::rpc::SequencerClient;
|
||||
use reth_provider::providers::BlockchainProvider2;
|
||||
|
||||
@ -23,56 +23,58 @@ fn main() {
|
||||
std::env::set_var("RUST_BACKTRACE", "1");
|
||||
}
|
||||
|
||||
if let Err(err) = Cli::<RollupArgs>::parse().run(|builder, rollup_args| async move {
|
||||
let enable_engine2 = rollup_args.experimental;
|
||||
let sequencer_http_arg = rollup_args.sequencer_http.clone();
|
||||
match enable_engine2 {
|
||||
true => {
|
||||
let handle = builder
|
||||
.with_types_and_provider::<OptimismNode, BlockchainProvider2<_>>()
|
||||
.with_components(OptimismNode::components(rollup_args))
|
||||
.with_add_ons::<OptimismAddOns>()
|
||||
.extend_rpc_modules(move |ctx| {
|
||||
// register sequencer tx forwarder
|
||||
if let Some(sequencer_http) = sequencer_http_arg {
|
||||
ctx.registry
|
||||
.eth_api()
|
||||
.set_sequencer_client(SequencerClient::new(sequencer_http));
|
||||
}
|
||||
if let Err(err) =
|
||||
Cli::<OpChainSpecParser, RollupArgs>::parse().run(|builder, rollup_args| async move {
|
||||
let enable_engine2 = rollup_args.experimental;
|
||||
let sequencer_http_arg = rollup_args.sequencer_http.clone();
|
||||
match enable_engine2 {
|
||||
true => {
|
||||
let handle = builder
|
||||
.with_types_and_provider::<OptimismNode, BlockchainProvider2<_>>()
|
||||
.with_components(OptimismNode::components(rollup_args))
|
||||
.with_add_ons::<OptimismAddOns>()
|
||||
.extend_rpc_modules(move |ctx| {
|
||||
// register sequencer tx forwarder
|
||||
if let Some(sequencer_http) = sequencer_http_arg {
|
||||
ctx.registry
|
||||
.eth_api()
|
||||
.set_sequencer_client(SequencerClient::new(sequencer_http));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.launch_with_fn(|builder| {
|
||||
let launcher = EngineNodeLauncher::new(
|
||||
builder.task_executor().clone(),
|
||||
builder.config().datadir(),
|
||||
);
|
||||
builder.launch_with(launcher)
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
})
|
||||
.launch_with_fn(|builder| {
|
||||
let launcher = EngineNodeLauncher::new(
|
||||
builder.task_executor().clone(),
|
||||
builder.config().datadir(),
|
||||
);
|
||||
builder.launch_with(launcher)
|
||||
})
|
||||
.await?;
|
||||
|
||||
handle.node_exit_future.await
|
||||
handle.node_exit_future.await
|
||||
}
|
||||
false => {
|
||||
let handle = builder
|
||||
.node(OptimismNode::new(rollup_args.clone()))
|
||||
.extend_rpc_modules(move |ctx| {
|
||||
// register sequencer tx forwarder
|
||||
if let Some(sequencer_http) = sequencer_http_arg {
|
||||
ctx.registry
|
||||
.eth_api()
|
||||
.set_sequencer_client(SequencerClient::new(sequencer_http));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.launch()
|
||||
.await?;
|
||||
|
||||
handle.node_exit_future.await
|
||||
}
|
||||
}
|
||||
false => {
|
||||
let handle = builder
|
||||
.node(OptimismNode::new(rollup_args.clone()))
|
||||
.extend_rpc_modules(move |ctx| {
|
||||
// register sequencer tx forwarder
|
||||
if let Some(sequencer_http) = sequencer_http_arg {
|
||||
ctx.registry
|
||||
.eth_api()
|
||||
.set_sequencer_client(SequencerClient::new(sequencer_http));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.launch()
|
||||
.await?;
|
||||
|
||||
handle.node_exit_future.await
|
||||
}
|
||||
}
|
||||
}) {
|
||||
})
|
||||
{
|
||||
eprintln!("Error: {err:?}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
@ -55,7 +55,10 @@ use tracing::info;
|
||||
/// This is the entrypoint to the executable.
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)]
|
||||
pub struct Cli<Ext: clap::Args + fmt::Debug = NoArgs> {
|
||||
pub struct Cli<
|
||||
Spec: ChainSpecParser<ChainSpec = ChainSpec> = OpChainSpecParser,
|
||||
Ext: clap::Args + fmt::Debug = NoArgs,
|
||||
> {
|
||||
/// The command to run
|
||||
#[command(subcommand)]
|
||||
command: Commands<Ext>,
|
||||
@ -66,12 +69,12 @@ pub struct Cli<Ext: clap::Args + fmt::Debug = NoArgs> {
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "CHAIN_OR_PATH",
|
||||
long_help = OpChainSpecParser::help_messge(),
|
||||
default_value = OpChainSpecParser::SUPPORTED_CHAINS[0],
|
||||
value_parser = OpChainSpecParser::parser(),
|
||||
long_help = Spec::help_messge(),
|
||||
default_value = Spec::SUPPORTED_CHAINS[0],
|
||||
value_parser = Spec::parser(),
|
||||
global = true,
|
||||
)]
|
||||
chain: Arc<ChainSpec>,
|
||||
chain: Arc<Spec::ChainSpec>,
|
||||
|
||||
/// Add a new instance of a node.
|
||||
///
|
||||
@ -109,7 +112,11 @@ impl Cli {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ext: clap::Args + fmt::Debug> Cli<Ext> {
|
||||
impl<Spec, Ext> Cli<Spec, Ext>
|
||||
where
|
||||
Spec: ChainSpecParser<ChainSpec = ChainSpec>,
|
||||
Ext: clap::Args + fmt::Debug,
|
||||
{
|
||||
/// Execute the configured cli command.
|
||||
///
|
||||
/// This accepts a closure that is used to launch the node via the
|
||||
|
||||
Reference in New Issue
Block a user