diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index bc0a2018c..15b6fe0b3 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -153,6 +153,10 @@ ethereum = [] name = "reth" path = "src/main.rs" +[[bin]] +name = "engine2" +path = "src/engine2.rs" + [[bin]] name = "op-reth" path = "src/optimism.rs" diff --git a/bin/reth/src/engine2.rs b/bin/reth/src/engine2.rs new file mode 100644 index 000000000..94777307c --- /dev/null +++ b/bin/reth/src/engine2.rs @@ -0,0 +1,40 @@ +#![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::>() + .with_components(EthereumNode::components()) + .with_add_ons::() + .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); + } +} diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index cf6f9867a..9c146be08 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -40,7 +40,7 @@ use crate::{ components::NodeComponentsBuilder, node::FullNode, rpc::{EthApiBuilderProvider, RethRpcServerHandles, RpcContext}, - DefaultNodeLauncher, Node, NodeHandle, + DefaultNodeLauncher, LaunchNode, Node, NodeHandle, }; /// The adapter type for a reth node with the builtin provider type @@ -374,6 +374,11 @@ where AO: NodeAddOns>, AO::EthApi: FullEthApiServer + AddDevSigners, { + /// Returns a reference to the node builder's config. + pub const fn config(&self) -> &NodeConfig { + &self.builder.config + } + /// Sets the hook that is run once the node's components are initialized. pub fn on_component_initialized(self, hook: F) -> Self where @@ -435,6 +440,14 @@ where } } + /// Launches the node with the given launcher. + pub async fn launch_with(self, launcher: L) -> eyre::Result + where + L: LaunchNode>, + { + launcher.launch_node(self.builder).await + } + /// Launches the node with the given closure. pub fn launch_with_fn(self, launcher: L) -> R where