From 02492daac9bea3a31b21712e406e392160baf8a4 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Fri, 30 Jun 2023 21:26:14 +0300 Subject: [PATCH] fix(cli): consistent max block across pipeline and engine (#3510) Co-authored-by: Matthias Seitz --- bin/reth/src/node/mod.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index d8c3cbf5a..7a67b006e 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -36,7 +36,9 @@ use reth_interfaces::{ }; use reth_network::{error::NetworkError, NetworkConfig, NetworkHandle, NetworkManager}; use reth_network_api::NetworkInfo; -use reth_primitives::{stage::StageId, BlockHashOrNumber, ChainSpec, Head, SealedHeader, H256}; +use reth_primitives::{ + stage::StageId, BlockHashOrNumber, BlockNumber, ChainSpec, Head, SealedHeader, H256, +}; use reth_provider::{ BlockHashReader, BlockReader, CanonStateSubscriptions, HeaderProvider, ProviderFactory, StageCheckpointReader, @@ -281,6 +283,14 @@ impl Command { let metrics_listener = MetricsListener::new(metrics_rx); ctx.task_executor.spawn_critical("metrics listener task", metrics_listener); + let max_block = if let Some(block) = self.debug.max_block { + Some(block) + } else if let Some(tip) = self.debug.tip { + Some(self.lookup_or_fetch_tip(&db, &network_client, tip).await?) + } else { + None + }; + // Configure the pipeline let (mut pipeline, client) = if self.auto_mine { let (_, client, mut task) = AutoSealBuilder::new( @@ -300,6 +310,7 @@ impl Command { db.clone(), &ctx.task_executor, metrics_tx, + max_block, ) .await?; @@ -318,6 +329,7 @@ impl Command { db.clone(), &ctx.task_executor, metrics_tx, + max_block, ) .await?; @@ -346,7 +358,7 @@ impl Command { blockchain_db.clone(), Box::new(ctx.task_executor.clone()), Box::new(network.clone()), - self.debug.max_block, + max_block, self.debug.continuous, payload_builder.clone(), initial_target, @@ -422,6 +434,7 @@ impl Command { } /// Constructs a [Pipeline] that's wired to the network + #[allow(clippy::too_many_arguments)] async fn build_networked_pipeline( &self, config: &mut Config, @@ -430,19 +443,12 @@ impl Command { db: DB, task_executor: &TaskExecutor, metrics_tx: MetricEventsSender, + max_block: Option, ) -> eyre::Result> where DB: Database + Unpin + Clone + 'static, Client: HeadersClient + BodiesClient + Clone + 'static, { - let max_block = if let Some(block) = self.debug.max_block { - Some(block) - } else if let Some(tip) = self.debug.tip { - Some(self.lookup_or_fetch_tip(&db, &client, tip).await?) - } else { - None - }; - // building network downloaders using the fetch client let header_downloader = ReverseHeadersDownloaderBuilder::from(config.stages.headers) .build(client.clone(), Arc::clone(&consensus))