diff --git a/Cargo.lock b/Cargo.lock index 7a6726ec8f64..91e25d037e8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8405,16 +8405,13 @@ dependencies = [ "reth-cli", "reth-cli-commands", "reth-cli-runner", - "reth-config", "reth-consensus", "reth-db", "reth-db-api", "reth-db-common", "reth-downloaders", - "reth-errors", "reth-execution-types", "reth-fs-util", - "reth-network-p2p", "reth-node-builder", "reth-node-core", "reth-node-events", @@ -8427,7 +8424,6 @@ dependencies = [ "reth-provider", "reth-prune", "reth-stages", - "reth-stages-types", "reth-static-file", "reth-static-file-types", "reth-tracing", diff --git a/crates/optimism/cli/Cargo.toml b/crates/optimism/cli/Cargo.toml index 4e18b51160e5..5fab2b93d4f0 100644 --- a/crates/optimism/cli/Cargo.toml +++ b/crates/optimism/cli/Cargo.toml @@ -36,11 +36,7 @@ reth-optimism-primitives.workspace = true reth-optimism-chainspec.workspace = true reth-chainspec.workspace = true -reth-stages-types.workspace = true reth-node-events.workspace = true -reth-network-p2p.workspace = true -reth-errors.workspace = true -reth-config.workspace = true reth-optimism-evm.workspace = true reth-cli.workspace = true reth-cli-runner.workspace = true diff --git a/crates/optimism/cli/src/commands/build_pipeline.rs b/crates/optimism/cli/src/commands/build_pipeline.rs deleted file mode 100644 index 8ebefdcc0b40..000000000000 --- a/crates/optimism/cli/src/commands/build_pipeline.rs +++ /dev/null @@ -1,101 +0,0 @@ -use alloy_primitives::B256; -use futures_util::{Stream, StreamExt}; -use reth_cli_commands::common::CliNodeTypes; -use reth_config::Config; -use reth_consensus::Consensus; -use reth_downloaders::{ - bodies::bodies::BodiesDownloaderBuilder, file_client::FileClient, - headers::reverse_headers::ReverseHeadersDownloaderBuilder, -}; -use reth_errors::ProviderError; -use reth_network_p2p::{ - bodies::downloader::BodyDownloader, - headers::downloader::{HeaderDownloader, SyncTarget}, -}; -use reth_node_events::node::NodeEvent; -use reth_optimism_chainspec::OpChainSpec; -use reth_optimism_evm::OpExecutorProvider; -use reth_provider::{ - providers::ProviderNodeTypes, BlockNumReader, ChainSpecProvider, HeaderProvider, - ProviderFactory, -}; -use reth_prune::PruneModes; -use reth_stages::{sets::DefaultStages, Pipeline, StageSet}; -use reth_stages_types::StageId; -use reth_static_file::StaticFileProducer; -use std::sync::Arc; -use tokio::sync::watch; - -/// Builds import pipeline. -/// -/// If configured to execute, all stages will run. Otherwise, only stages that don't require state -/// will run. -pub(crate) async fn build_import_pipeline( - config: &Config, - provider_factory: ProviderFactory, - consensus: &Arc, - file_client: Arc, - static_file_producer: StaticFileProducer>, - disable_exec: bool, -) -> eyre::Result<(Pipeline, impl Stream)> -where - N: CliNodeTypes + ProviderNodeTypes, - C: Consensus + 'static, -{ - if !file_client.has_canonical_blocks() { - eyre::bail!("unable to import non canonical blocks"); - } - - // Retrieve latest header found in the database. - let last_block_number = provider_factory.last_block_number()?; - let local_head = provider_factory - .sealed_header(last_block_number)? - .ok_or_else(|| ProviderError::HeaderNotFound(last_block_number.into()))?; - - let mut header_downloader = ReverseHeadersDownloaderBuilder::new(config.stages.headers) - .build(file_client.clone(), consensus.clone()) - .into_task(); - // TODO: The pipeline should correctly configure the downloader on its own. - // Find the possibility to remove unnecessary pre-configuration. - header_downloader.update_local_head(local_head); - header_downloader.update_sync_target(SyncTarget::Tip(file_client.tip().unwrap())); - - let mut body_downloader = BodiesDownloaderBuilder::new(config.stages.bodies) - .build(file_client.clone(), consensus.clone(), provider_factory.clone()) - .into_task(); - // TODO: The pipeline should correctly configure the downloader on its own. - // Find the possibility to remove unnecessary pre-configuration. - body_downloader - .set_download_range(file_client.min_block().unwrap()..=file_client.max_block().unwrap()) - .expect("failed to set download range"); - - let (tip_tx, tip_rx) = watch::channel(B256::ZERO); - let executor = OpExecutorProvider::optimism(provider_factory.chain_spec()); - - let max_block = file_client.max_block().unwrap_or(0); - - let pipeline = Pipeline::::builder() - .with_tip_sender(tip_tx) - // we want to sync all blocks the file client provides or 0 if empty - .with_max_block(max_block) - .with_fail_on_unwind(true) - .add_stages( - DefaultStages::new( - provider_factory.clone(), - tip_rx, - consensus.clone(), - header_downloader, - body_downloader, - executor, - config.stages.clone(), - PruneModes::default(), - ) - .builder() - .disable_all_if(&StageId::STATE_REQUIRED, || disable_exec), - ) - .build(provider_factory, static_file_producer); - - let events = pipeline.events().map(Into::into); - - Ok((pipeline, events)) -} diff --git a/crates/optimism/cli/src/commands/import.rs b/crates/optimism/cli/src/commands/import.rs index 5e3de5a8671a..11ad9c27cc31 100644 --- a/crates/optimism/cli/src/commands/import.rs +++ b/crates/optimism/cli/src/commands/import.rs @@ -2,7 +2,10 @@ //! file. use clap::Parser; use reth_cli::chainspec::ChainSpecParser; -use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs}; +use reth_cli_commands::{ + common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs}, + import::build_import_pipeline, +}; use reth_consensus::noop::NoopConsensus; use reth_db::tables; use reth_db_api::transaction::DbTx; @@ -11,16 +14,15 @@ use reth_downloaders::file_client::{ }; use reth_node_core::version::SHORT_VERSION; use reth_optimism_chainspec::OpChainSpec; +use reth_optimism_evm::OpExecutorProvider; use reth_optimism_primitives::bedrock::is_dup_tx; -use reth_provider::StageCheckpointReader; +use reth_provider::{ChainSpecProvider, StageCheckpointReader}; use reth_prune::PruneModes; use reth_stages::StageId; use reth_static_file::StaticFileProducer; use std::{path::PathBuf, sync::Arc}; use tracing::{debug, error, info}; -use crate::commands::build_pipeline::build_import_pipeline; - /// Syncs RLP encoded blocks from a file. #[derive(Debug, Parser)] pub struct ImportOpCommand { @@ -94,8 +96,8 @@ impl> ImportOpCommand { Arc::new(file_client), StaticFileProducer::new(provider_factory.clone(), PruneModes::default()), true, - ) - .await?; + OpExecutorProvider::optimism(provider_factory.chain_spec()), + )?; // override the tip pipeline.set_tip(tip); diff --git a/crates/optimism/cli/src/commands/mod.rs b/crates/optimism/cli/src/commands/mod.rs index d51f89932965..643bf503d8c7 100644 --- a/crates/optimism/cli/src/commands/mod.rs +++ b/crates/optimism/cli/src/commands/mod.rs @@ -10,8 +10,6 @@ use reth_cli_commands::{ }; use std::fmt; -/// Helper function to build an import pipeline. -mod build_pipeline; pub mod import; pub mod import_receipts; pub mod init_state;