feat: add --engine.experimental flag to enable engine2 (#10051)

This commit is contained in:
nk_ysg
2024-08-07 03:20:38 +08:00
committed by GitHub
parent b0ded038ba
commit 6f4291d94e
4 changed files with 62 additions and 48 deletions

View File

@ -152,10 +152,6 @@ ethereum = []
name = "reth"
path = "src/main.rs"
[[bin]]
name = "engine2"
path = "src/engine2.rs"
[[bin]]
name = "op-reth"
path = "src/optimism.rs"

View File

@ -1,40 +0,0 @@
#![allow(missing_docs)]
#![allow(rustdoc::missing_crate_level_docs)]
// We use jemalloc for performance reasons.
#[cfg(all(feature = "jemalloc", unix))]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[cfg(not(feature = "optimism"))]
fn main() {
use reth::cli::Cli;
use reth_node_ethereum::{launch::EthNodeLauncher, node::EthereumAddOns, EthereumNode};
use reth_provider::providers::BlockchainProvider2;
reth_cli_util::sigsegv_handler::install();
// Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided.
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}
if let Err(err) = Cli::parse_args().run(|builder, _| async {
let handle = builder
.with_types_and_provider::<EthereumNode, BlockchainProvider2<_>>()
.with_components(EthereumNode::components())
.with_add_ons::<EthereumAddOns>()
.launch_with_fn(|builder| {
let launcher = EthNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
);
builder.launch_with(launcher)
})
.await?;
handle.node_exit_future.await
}) {
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}

View File

@ -8,10 +8,24 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[cfg(all(feature = "optimism", not(test)))]
compile_error!("Cannot build the `reth` binary with the `optimism` feature flag enabled. Did you mean to build `op-reth`?");
/// clap [Args] for Engine related arguments.
use clap::Args;
/// Parameters for configuring the engine
#[derive(Debug, Clone, Args, PartialEq, Eq, Default)]
#[command(next_help_heading = "Engine")]
pub struct EngineArgs {
/// Enable the engine2 experimental features on reth binary
#[arg(long = "engine.experimental", default_value = "false")]
pub experimental: bool,
}
#[cfg(not(feature = "optimism"))]
fn main() {
use clap::Parser;
use reth::cli::Cli;
use reth_node_ethereum::EthereumNode;
use reth_node_ethereum::{launch::EthNodeLauncher, node::EthereumAddOns, EthereumNode};
use reth_provider::providers::BlockchainProvider2;
reth_cli_util::sigsegv_handler::install();
@ -20,11 +34,51 @@ fn main() {
std::env::set_var("RUST_BACKTRACE", "1");
}
if let Err(err) = Cli::parse_args().run(|builder, _| async {
let handle = builder.launch_node(EthereumNode::default()).await?;
handle.node_exit_future.await
if let Err(err) = Cli::<EngineArgs>::parse().run(|builder, engine_args| async move {
let enable_engine2 = engine_args.experimental;
match enable_engine2 {
true => {
let handle = builder
.with_types_and_provider::<EthereumNode, BlockchainProvider2<_>>()
.with_components(EthereumNode::components())
.with_add_ons::<EthereumAddOns>()
.launch_with_fn(|builder| {
let launcher = EthNodeLauncher::new(
builder.task_executor().clone(),
builder.config().datadir(),
);
builder.launch_with(launcher)
})
.await?;
handle.node_exit_future.await
}
false => {
let handle = builder.launch_node(EthereumNode::default()).await?;
handle.node_exit_future.await
}
}
}) {
eprintln!("Error: {err:?}");
std::process::exit(1);
}
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
/// A helper type to parse Args more easily
#[derive(Parser)]
struct CommandParser<T: Args> {
#[command(flatten)]
args: T,
}
#[test]
fn test_parse_engine_args() {
let default_args = EngineArgs::default();
let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
assert_eq!(args, default_args);
}
}