diff --git a/Cargo.lock b/Cargo.lock index f3e9db5577ce..fcf98a08d1ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6618,6 +6618,7 @@ dependencies = [ "crossterm", "eyre", "fdlimit", + "futures", "human_bytes", "itertools 0.13.0", "metrics-process", @@ -6642,6 +6643,7 @@ dependencies = [ "reth-network-p2p", "reth-node-builder", "reth-node-core", + "reth-node-events", "reth-primitives", "reth-provider", "reth-prune", diff --git a/bin/reth/src/cli/mod.rs b/bin/reth/src/cli/mod.rs index 095f2081503f..d6fc7d3c4df4 100644 --- a/bin/reth/src/cli/mod.rs +++ b/bin/reth/src/cli/mod.rs @@ -5,14 +5,14 @@ use crate::{ utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS}, LogArgs, }, - commands::{debug_cmd, import}, + commands::debug_cmd, macros::block_executor, version::{LONG_VERSION, SHORT_VERSION}, }; use clap::{value_parser, Parser, Subcommand}; use reth_chainspec::ChainSpec; use reth_cli_commands::{ - config_cmd, db, dump_genesis, init_cmd, init_state, + config_cmd, db, dump_genesis, import, init_cmd, init_state, node::{self, NoArgs}, p2p, prune, recover, stage, }; @@ -151,7 +151,9 @@ impl Cli { } Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()), Commands::InitState(command) => runner.run_blocking_until_ctrl_c(command.execute()), - Commands::Import(command) => runner.run_blocking_until_ctrl_c(command.execute()), + Commands::Import(command) => runner.run_blocking_until_ctrl_c( + command.execute(|chain_spec| block_executor!(chain_spec)), + ), #[cfg(feature = "optimism")] Commands::ImportOp(command) => runner.run_blocking_until_ctrl_c(command.execute()), #[cfg(feature = "optimism")] diff --git a/bin/reth/src/commands/mod.rs b/bin/reth/src/commands/mod.rs index cd6cdfd76b30..7d4a3d2c4273 100644 --- a/bin/reth/src/commands/mod.rs +++ b/bin/reth/src/commands/mod.rs @@ -1,4 +1,3 @@ //! This contains all of the `reth` commands pub mod debug_cmd; -pub mod import; diff --git a/crates/cli/commands/Cargo.toml b/crates/cli/commands/Cargo.toml index ce41198c957f..35ed25eda66d 100644 --- a/crates/cli/commands/Cargo.toml +++ b/crates/cli/commands/Cargo.toml @@ -27,6 +27,7 @@ reth-network = { workspace = true, features = ["serde"] } reth-network-p2p.workspace = true reth-node-builder.workspace = true reth-node-core.workspace = true +reth-node-events.workspace = true reth-primitives.workspace = true reth-provider.workspace = true reth-prune.workspace = true @@ -35,8 +36,9 @@ reth-static-file-types.workspace = true reth-static-file.workspace = true reth-trie = { workspace = true, features = ["metrics"] } -tokio.workspace = true itertools.workspace = true +futures.workspace = true +tokio.workspace = true # misc ahash = "0.8" diff --git a/bin/reth/src/commands/import.rs b/crates/cli/commands/src/import.rs similarity index 93% rename from bin/reth/src/commands/import.rs rename to crates/cli/commands/src/import.rs index f4810f05148b..b7695379b0cb 100644 --- a/bin/reth/src/commands/import.rs +++ b/crates/cli/commands/src/import.rs @@ -1,9 +1,9 @@ //! Command that initializes the node by importing a chain from a file. -use crate::{macros::block_executor, version::SHORT_VERSION}; +use crate::common::{AccessRights, Environment, EnvironmentArgs}; use clap::Parser; use futures::{Stream, StreamExt}; use reth_beacon_consensus::EthBeaconConsensus; -use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs}; +use reth_chainspec::ChainSpec; use reth_config::Config; use reth_consensus::Consensus; use reth_db::tables; @@ -13,10 +13,12 @@ use reth_downloaders::{ file_client::{ChunkedFileReader, FileClient, DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE}, headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; +use reth_evm::execute::BlockExecutorProvider; use reth_network_p2p::{ bodies::downloader::BodyDownloader, headers::downloader::{HeaderDownloader, SyncTarget}, }; +use reth_node_core::version::SHORT_VERSION; use reth_node_events::node::NodeEvent; use reth_primitives::B256; use reth_provider::{ @@ -54,7 +56,11 @@ pub struct ImportCommand { impl ImportCommand { /// Execute `import` command - pub async fn execute(self) -> eyre::Result<()> { + pub async fn execute(self, executor: F) -> eyre::Result<()> + where + E: BlockExecutorProvider, + F: FnOnce(Arc) -> E, + { info!(target: "reth::cli", "reth {} starting", SHORT_VERSION); if self.no_state { @@ -68,6 +74,7 @@ impl ImportCommand { let Environment { provider_factory, config, .. } = self.env.init(AccessRights::RW)?; + let executor = executor(provider_factory.chain_spec()); let consensus = Arc::new(EthBeaconConsensus::new(self.env.chain.clone())); info!(target: "reth::cli", "Consensus engine initialized"); @@ -96,6 +103,7 @@ impl ImportCommand { Arc::new(file_client), StaticFileProducer::new(provider_factory.clone(), PruneModes::default()), self.no_state, + executor.clone(), )?; // override the tip @@ -152,17 +160,19 @@ impl ImportCommand { /// /// If configured to execute, all stages will run. Otherwise, only stages that don't require state /// will run. -pub fn build_import_pipeline( +pub fn build_import_pipeline( config: &Config, provider_factory: ProviderFactory, consensus: &Arc, file_client: Arc, static_file_producer: StaticFileProducer, disable_exec: bool, + executor: E, ) -> eyre::Result<(Pipeline, impl Stream)> where DB: Database + Clone + Unpin + 'static, C: Consensus + 'static, + E: BlockExecutorProvider, { if !file_client.has_canonical_blocks() { eyre::bail!("unable to import non canonical blocks"); @@ -192,7 +202,6 @@ where .expect("failed to set download range"); let (tip_tx, tip_rx) = watch::channel(B256::ZERO); - let executor = block_executor!(provider_factory.chain_spec()); let max_block = file_client.max_block().unwrap_or(0); diff --git a/crates/cli/commands/src/lib.rs b/crates/cli/commands/src/lib.rs index 8f0b796ef8d3..843268a84bb1 100644 --- a/crates/cli/commands/src/lib.rs +++ b/crates/cli/commands/src/lib.rs @@ -12,6 +12,7 @@ pub mod common; pub mod config_cmd; pub mod db; pub mod dump_genesis; +pub mod import; pub mod init_cmd; pub mod init_state; pub mod node;