diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index 99e9b2936..3e8f92e70 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -806,6 +806,15 @@ where Ok(initial_target) } + /// Returns true if the node should terminate after the initial backfill run. + /// + /// This is the case if any of these configs are set: + /// `--debug.max-block` + /// `--debug.terminate` + pub const fn terminate_after_initial_backfill(&self) -> bool { + self.node_config().debug.terminate || self.node_config().debug.max_block.is_some() + } + /// Check if the pipeline is consistent (all stages have the checkpoint block numbers no less /// than the checkpoint of the first stage). /// diff --git a/crates/node/builder/src/launch/engine.rs b/crates/node/builder/src/launch/engine.rs index 46ffacbf7..782cc7bbb 100644 --- a/crates/node/builder/src/launch/engine.rs +++ b/crates/node/builder/src/launch/engine.rs @@ -334,6 +334,8 @@ where .fuse(); let chainspec = ctx.chain_spec(); let (exit, rx) = oneshot::channel(); + let terminate_after_backfill = ctx.terminate_after_initial_backfill(); + info!(target: "reth::cli", "Starting consensus engine"); ctx.task_executor().spawn_critical("consensus engine", async move { if let Some(initial_target) = initial_target { @@ -357,6 +359,11 @@ where debug!(target: "reth::cli", "Event: {event}"); match event { ChainEvent::BackfillSyncFinished => { + if terminate_after_backfill { + debug!(target: "reth::cli", "Terminating after initial backfill"); + break + } + network_handle.update_sync_state(SyncState::Idle); } ChainEvent::BackfillSyncStarted => {