diff --git a/CHANGELOG.sf.md b/CHANGELOG.sf.md index b7c0709c4aa..4a58be4860c 100644 --- a/CHANGELOG.sf.md +++ b/CHANGELOG.sf.md @@ -9,6 +9,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Added + +- Backport upstream reth #27329: add `--engine.backfill-threshold` (env `RETH_ENGINE_BACKFILL_THRESHOLD`), + the largest gap between the local head and the forkchoice head that is closed by downloading + blocks instead of starting a pipeline (backfill) run. The default stays 32; values are clamped to + 1024 and the block buffer grows to twice the threshold. Chains with short block times (Base, + 200ms) can raise it so a slow pipeline cycle no longer leaves a gap larger than the threshold, + which kept the node in back-to-back pipeline runs and the rollup in EL sync. + ### Fixed - Stop the staged-sync (pipeline) path from advertising every replayed block as final. It stamped diff --git a/crates/engine/primitives/src/config.rs b/crates/engine/primitives/src/config.rs index 0bec4746106..c12415010f0 100644 --- a/crates/engine/primitives/src/config.rs +++ b/crates/engine/primitives/src/config.rs @@ -16,6 +16,22 @@ pub const DEFAULT_PERSISTENCE_BACKPRESSURE_THRESHOLD: u64 = 16; /// How close to the canonical head we persist blocks. pub const DEFAULT_MEMORY_BLOCK_BUFFER_TARGET: u64 = 5; +/// The largest gap for which the tree will be used to sync individual blocks by downloading them. +/// +/// This is the default threshold, and represents the distance (gap) from the local head to a +/// new (canonical) block, e.g. the forkchoice head block. If the block distance from the local head +/// exceeds this threshold, the pipeline will be used to backfill the gap more efficiently. +/// +/// E.g.: Local head `block.number` is 100 and the forkchoice head `block.number` is 133 (more than +/// an epoch has slots), then this exceeds the threshold at which the pipeline should be used to +/// backfill this gap. +pub const DEFAULT_BACKFILL_RUN_THRESHOLD: u64 = EPOCH_SLOTS; + +/// Largest supported live-sync gap, matching the peer header response limit of 1024. +/// +/// The range downloader requires a complete response and cannot yet split larger requests. +pub const MAX_BACKFILL_RUN_THRESHOLD: u64 = 1024; + /// The size of proof targets chunk to spawn in one multiproof calculation. pub const DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE: usize = 5; @@ -116,6 +132,9 @@ pub struct TreeConfig { /// Number of pending blocks that cannot be executed due to missing parent and /// are kept in cache. block_buffer_limit: u32, + /// Largest gap between the local head and a new canonical block that is closed by downloading + /// the missing blocks. Larger gaps trigger a pipeline (backfill) run instead. + backfill_run_threshold: u64, /// Number of invalid headers to keep in cache. max_invalid_header_cache_length: u32, /// Number of cache hits before an invalid header entry is evicted and reprocessed. @@ -238,6 +257,7 @@ impl Default for TreeConfig { memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, persistence_backpressure_threshold: DEFAULT_PERSISTENCE_BACKPRESSURE_THRESHOLD, block_buffer_limit: DEFAULT_BLOCK_BUFFER_LIMIT, + backfill_run_threshold: DEFAULT_BACKFILL_RUN_THRESHOLD, max_invalid_header_cache_length: DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH, invalid_header_hit_eviction_threshold: DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD, max_execute_block_batch_size: DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE, @@ -274,6 +294,8 @@ impl Default for TreeConfig { impl TreeConfig { /// Create engine tree configuration. + /// + /// The backfill run threshold is clamped to [`MAX_BACKFILL_RUN_THRESHOLD`]. #[expect(clippy::too_many_arguments)] pub const fn new( persistence_threshold: u64, @@ -281,6 +303,7 @@ impl TreeConfig { memory_block_buffer_target: u64, persistence_backpressure_threshold: u64, block_buffer_limit: u32, + backfill_run_threshold: u64, max_invalid_header_cache_length: u32, invalid_header_hit_eviction_threshold: u8, max_execute_block_batch_size: usize, @@ -318,6 +341,7 @@ impl TreeConfig { memory_block_buffer_target, persistence_backpressure_threshold, block_buffer_limit, + backfill_run_threshold: clamp_backfill_run_threshold(backfill_run_threshold), max_invalid_header_cache_length, invalid_header_hit_eviction_threshold, max_execute_block_batch_size, @@ -376,6 +400,11 @@ impl TreeConfig { self.block_buffer_limit } + /// Return the backfill run threshold. + pub const fn backfill_run_threshold(&self) -> u64 { + self.backfill_run_threshold + } + /// Return the maximum invalid cache header length. pub const fn max_invalid_header_cache_length(&self) -> u32 { self.max_invalid_header_cache_length @@ -530,6 +559,20 @@ impl TreeConfig { self } + /// Setter for backfill run threshold. + /// + /// Clamps the threshold to [`MAX_BACKFILL_RUN_THRESHOLD`] and grows the block buffer to twice + /// the clamped threshold so it can retain disconnected blocks while downloading the gap, + /// with room for incoming payloads. + pub const fn with_backfill_run_threshold(mut self, backfill_run_threshold: u64) -> Self { + self.backfill_run_threshold = clamp_backfill_run_threshold(backfill_run_threshold); + let buffer_limit = self.backfill_run_threshold as u32 * 2; + if buffer_limit > self.block_buffer_limit { + self.block_buffer_limit = buffer_limit; + } + self + } + /// Setter for maximum invalid header cache length. pub const fn with_max_invalid_header_cache_length( mut self, @@ -812,9 +855,32 @@ impl TreeConfig { } } +/// Keep live-sync requests within a single peer header response until chunking is supported. +const fn clamp_backfill_run_threshold(threshold: u64) -> u64 { + if threshold > MAX_BACKFILL_RUN_THRESHOLD { + MAX_BACKFILL_RUN_THRESHOLD + } else { + threshold + } +} + #[cfg(test)] mod tests { - use super::{TreeConfig, DEFAULT_NUM_STATE_MASKING_BLOCKS}; + use super::*; + + #[test] + fn backfill_threshold_grows_block_buffer() { + let default = TreeConfig::default(); + for (threshold, expected, buffer_limit) in + [(0, 0, 64), (500, 500, 1000), (1024, 1024, 2048), (u64::MAX, 1024, 2048)] + { + let config = default.clone().with_backfill_run_threshold(threshold); + assert_eq!(config.backfill_run_threshold(), expected); + assert_eq!(config.block_buffer_limit(), buffer_limit); + } + let config = default.with_block_buffer_limit(2000).with_backfill_run_threshold(500); + assert_eq!(config.block_buffer_limit(), 2000); + } #[test] fn txpool_prewarming_is_disabled_by_default_and_can_be_enabled() { diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 4c4eb26b74b..b22d7c4cbb8 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -6,7 +6,7 @@ use crate::{ tree::{error::InsertPayloadError, payload_validator::TreeCtx}, }; use alloy_consensus::BlockHeader; -use alloy_eips::{eip1898::BlockWithParent, merge::EPOCH_SLOTS, BlockNumHash, NumHash}; +use alloy_eips::{eip1898::BlockWithParent, BlockNumHash, NumHash}; use alloy_primitives::{map::B256Map, B256}; use alloy_rpc_types_engine::{ ForkchoiceState, PayloadStatus, PayloadStatusEnum, PayloadValidationError, @@ -95,17 +95,6 @@ pub use types::{ExecutionEnv, ValidationOutcome, ValidationOutput}; pub mod state; -/// The largest gap for which the tree will be used to sync individual blocks by downloading them. -/// -/// This is the default threshold, and represents the distance (gap) from the local head to a -/// new (canonical) block, e.g. the forkchoice head block. If the block distance from the local head -/// exceeds this threshold, the pipeline will be used to backfill the gap more efficiently. -/// -/// E.g.: Local head `block.number` is 100 and the forkchoice head `block.number` is 133 (more than -/// an epoch has slots), then this exceeds the threshold at which the pipeline should be used to -/// backfill this gap. -pub(crate) const MIN_BLOCKS_FOR_PIPELINE_RUN: u64 = EPOCH_SLOTS; - /// The minimum number of blocks to retain in the changeset cache after eviction. /// /// This ensures that recent changesets are kept in memory for potential reorgs, @@ -2764,7 +2753,7 @@ where /// If the `local_tip` is greater than the `block`, then this will return false. #[inline] const fn exceeds_backfill_run_threshold(&self, local_tip: u64, block: u64) -> bool { - block > local_tip && block - local_tip > MIN_BLOCKS_FOR_PIPELINE_RUN + block > local_tip && block - local_tip > self.config.backfill_run_threshold() } /// Returns how far the local tip is from the given block. If the local tip is at the same diff --git a/crates/engine/tree/src/tree/tests.rs b/crates/engine/tree/src/tree/tests.rs index c2e517db218..ef63a65d008 100644 --- a/crates/engine/tree/src/tree/tests.rs +++ b/crates/engine/tree/src/tree/tests.rs @@ -22,7 +22,9 @@ use alloy_rpc_types_engine::{ use assert_matches::assert_matches; use reth_chain_state::{test_utils::TestBlockBuilder, BlockState}; use reth_chainspec::{ChainSpec, HOLESKY, MAINNET}; -use reth_engine_primitives::{EngineApiValidator, ForkchoiceStatus, NoopInvalidBlockHook}; +use reth_engine_primitives::{ + EngineApiValidator, ForkchoiceStatus, NoopInvalidBlockHook, DEFAULT_BACKFILL_RUN_THRESHOLD, +}; use reth_ethereum_consensus::EthBeaconConsensus; use reth_ethereum_engine_primitives::{EthEngineTypes, EthPayloadAttributes}; use reth_ethereum_primitives::{Block, EthPrimitives}; @@ -1511,7 +1513,7 @@ async fn test_engine_tree_live_sync_transition_required_blocks_requested() { // extend main chain with enough blocks to trigger pipeline run but don't insert them let main_chain = test_harness .block_builder - .create_fork(base_chain[0].recovered_block(), MIN_BLOCKS_FOR_PIPELINE_RUN + 10); + .create_fork(base_chain[0].recovered_block(), DEFAULT_BACKFILL_RUN_THRESHOLD + 10); let main_chain_last_hash = main_chain.last().unwrap().hash(); test_harness.send_fcu(main_chain_last_hash, ForkchoiceStatus::Syncing).await; @@ -1519,7 +1521,7 @@ async fn test_engine_tree_live_sync_transition_required_blocks_requested() { test_harness.check_fcu(main_chain_last_hash, ForkchoiceStatus::Syncing).await; // create event for backfill finished - let backfill_finished_block_number = MIN_BLOCKS_FOR_PIPELINE_RUN + 1; + let backfill_finished_block_number = DEFAULT_BACKFILL_RUN_THRESHOLD + 1; let backfill_finished = FromOrchestrator::BackfillSyncFinished(ControlFlow::Continue { block_number: backfill_finished_block_number, }); @@ -2980,11 +2982,24 @@ fn test_backfill_target_hash_opstack_returns_head() { assert_eq!(test_harness.tree.backfill_target_hash(state), head); } +#[test] +fn test_exceeds_backfill_run_threshold_uses_configured_value() { + let mut test_harness = TestHarness::new(MAINNET.clone()); + let default_threshold = DEFAULT_BACKFILL_RUN_THRESHOLD; + assert!(!test_harness.tree.exceeds_backfill_run_threshold(0, default_threshold)); + assert!(test_harness.tree.exceeds_backfill_run_threshold(0, default_threshold + 1)); + + test_harness.tree.config = TreeConfig::default().with_backfill_run_threshold(100); + assert!(!test_harness.tree.exceeds_backfill_run_threshold(10, 110)); + assert!(test_harness.tree.exceeds_backfill_run_threshold(10, 111)); + assert!(!test_harness.tree.exceeds_backfill_run_threshold(10, 9)); +} + #[test] fn test_backfill_sync_target_without_sync_state_returns_none() { let test_harness = TestHarness::new(MAINNET.clone()); assert_eq!( - test_harness.tree.backfill_sync_target(0, MIN_BLOCKS_FOR_PIPELINE_RUN + 100, None), + test_harness.tree.backfill_sync_target(0, DEFAULT_BACKFILL_RUN_THRESHOLD + 100, None), None ); } @@ -3009,9 +3024,9 @@ fn test_on_disconnected_downloaded_block_opstack_targets_head() { let canonical_head = BlockNumHash::new(0, B256::ZERO); let downloaded_block = - BlockNumHash::new(MIN_BLOCKS_FOR_PIPELINE_RUN + 100, B256::from([0xCC; 32])); + BlockNumHash::new(DEFAULT_BACKFILL_RUN_THRESHOLD + 100, B256::from([0xCC; 32])); let missing_parent = - BlockNumHash::new(MIN_BLOCKS_FOR_PIPELINE_RUN + 99, B256::from([0xDD; 32])); + BlockNumHash::new(DEFAULT_BACKFILL_RUN_THRESHOLD + 99, B256::from([0xDD; 32])); let event = test_harness.tree.on_disconnected_downloaded_block( downloaded_block, @@ -3050,9 +3065,9 @@ fn test_on_disconnected_downloaded_block_eth_targets_finalized() { let canonical_head = BlockNumHash::new(0, B256::ZERO); let downloaded_block = - BlockNumHash::new(MIN_BLOCKS_FOR_PIPELINE_RUN + 100, B256::from([0xCC; 32])); + BlockNumHash::new(DEFAULT_BACKFILL_RUN_THRESHOLD + 100, B256::from([0xCC; 32])); let missing_parent = - BlockNumHash::new(MIN_BLOCKS_FOR_PIPELINE_RUN + 99, B256::from([0xDD; 32])); + BlockNumHash::new(DEFAULT_BACKFILL_RUN_THRESHOLD + 99, B256::from([0xDD; 32])); let event = test_harness.tree.on_disconnected_downloaded_block( downloaded_block, @@ -3090,9 +3105,9 @@ fn test_on_disconnected_downloaded_block_eth_zero_finalized_targets_head() { let canonical_head = BlockNumHash::new(0, B256::ZERO); let downloaded_block = - BlockNumHash::new(MIN_BLOCKS_FOR_PIPELINE_RUN + 100, B256::from([0xCC; 32])); + BlockNumHash::new(DEFAULT_BACKFILL_RUN_THRESHOLD + 100, B256::from([0xCC; 32])); let missing_parent = - BlockNumHash::new(MIN_BLOCKS_FOR_PIPELINE_RUN + 99, B256::from([0xDD; 32])); + BlockNumHash::new(DEFAULT_BACKFILL_RUN_THRESHOLD + 99, B256::from([0xDD; 32])); let event = test_harness.tree.on_disconnected_downloaded_block( downloaded_block, @@ -3112,16 +3127,19 @@ fn test_on_disconnected_downloaded_block_eth_zero_finalized_targets_head() { } } -/// Verifies that the post-backfill recheck path in `on_backfill_sync_finished` retriggers a -/// new backfill targeting whichever block `backfill_target_hash` resolves to — head on OP -/// Stack, finalized on Ethereum — when that block is buffered far ahead of where the -/// just-finished pipeline landed. -async fn assert_post_backfill_recheck_retriggers_to_buffered_target(engine_kind: EngineApiKind) { +/// Verifies that the post-backfill recheck chooses between backfill and live sync using the +/// configured threshold and the buffered target (head on OP Stack, finalized on Ethereum). +async fn assert_post_backfill_recheck_uses_threshold( + engine_kind: EngineApiKind, + threshold: u64, + expect_backfill: bool, +) { reth_tracing::init_test_tracing(); let chain_spec = MAINNET.clone(); let mut test_harness = TestHarness::new(chain_spec.clone()); test_harness.tree.engine_kind = engine_kind; + test_harness.tree.config = TreeConfig::default().with_backfill_run_threshold(threshold); let base_chain: Vec<_> = test_harness.block_builder.get_executed_blocks(0..1).collect(); test_harness = test_harness.with_blocks(base_chain.clone()); @@ -3132,7 +3150,7 @@ async fn assert_post_backfill_recheck_retriggers_to_buffered_target(engine_kind: // Long unsynced chain. The last block is what the helper should resolve to. let main_chain = test_harness .block_builder - .create_fork(base_chain[0].recovered_block(), MIN_BLOCKS_FOR_PIPELINE_RUN + 50); + .create_fork(base_chain[0].recovered_block(), DEFAULT_BACKFILL_RUN_THRESHOLD + 50); let target_block = main_chain.last().unwrap().clone(); let target_hash = target_block.hash(); @@ -3153,8 +3171,8 @@ async fn assert_post_backfill_recheck_retriggers_to_buffered_target(engine_kind: ForkchoiceStatus::Syncing, ); - // Simulate backfill finishing far below the buffered target (gap > threshold). - let backfill_finished_block_number = MIN_BLOCKS_FOR_PIPELINE_RUN + 1; + // Simulate backfill finishing with a gap larger than the default threshold. + let backfill_finished_block_number = DEFAULT_BACKFILL_RUN_THRESHOLD + 1; let backfill_tip_block = main_chain[(backfill_finished_block_number - 1) as usize].clone(); test_harness.provider.add_block(backfill_tip_block.hash(), backfill_tip_block.into_block()); let backfill_finished = FromOrchestrator::BackfillSyncFinished(ControlFlow::Continue { @@ -3164,23 +3182,81 @@ async fn assert_post_backfill_recheck_retriggers_to_buffered_target(engine_kind: let event = test_harness.from_tree_rx.recv().await.unwrap(); match event { - EngineApiEvent::BackfillAction(BackfillAction::Start(emitted_target)) => { + EngineApiEvent::BackfillAction(BackfillAction::Start(emitted_target)) + if expect_backfill => + { assert_eq!( emitted_target.sync_target(), Some(target_hash), "post-backfill recheck should retrigger backfill to the buffered target" ); } - _ => panic!("Expected BackfillAction(Start), got: {event:#?}"), + EngineApiEvent::Download(_) if !expect_backfill => {} + _ => panic!("Unexpected post-backfill event: {event:#?}"), } } #[tokio::test] async fn test_on_backfill_sync_finished_opstack_retriggers_backfill_to_buffered_head() { - assert_post_backfill_recheck_retriggers_to_buffered_target(EngineApiKind::OpStack).await; + assert_post_backfill_recheck_uses_threshold( + EngineApiKind::OpStack, + DEFAULT_BACKFILL_RUN_THRESHOLD, + true, + ) + .await; } #[tokio::test] async fn test_on_backfill_sync_finished_eth_retriggers_backfill_to_buffered_finalized() { - assert_post_backfill_recheck_retriggers_to_buffered_target(EngineApiKind::Ethereum).await; + assert_post_backfill_recheck_uses_threshold( + EngineApiKind::Ethereum, + DEFAULT_BACKFILL_RUN_THRESHOLD, + true, + ) + .await; +} + +#[tokio::test] +async fn test_on_backfill_sync_finished_resumes_live_sync_with_higher_threshold() { + for engine_kind in [EngineApiKind::Ethereum, EngineApiKind::OpStack] { + assert_post_backfill_recheck_uses_threshold(engine_kind, 100, false).await; + } +} + +#[test] +fn test_backfill_threshold_above_header_limit_triggers_backfill() { + let mut test_harness = TestHarness::new(MAINNET.clone()); + let target_hash = B256::from([0xAA; 32]); + test_harness.tree.state.forkchoice_state_tracker.set_latest( + ForkchoiceState { + head_block_hash: target_hash, + safe_block_hash: B256::ZERO, + finalized_block_hash: target_hash, + }, + ForkchoiceStatus::Syncing, + ); + let local_tip = BlockNumHash::new(10, B256::ZERO); + let parent_hash = B256::from([0xBB; 32]); + test_harness.tree.config = TreeConfig::default().with_backfill_run_threshold(2048); + for gap in [1024, 1025] { + let missing_parent = BlockNumHash::new(local_tip.number + gap, parent_hash); + let downloaded = BlockNumHash::new(missing_parent.number + 1, B256::from([0xCC; 32])); + let event = test_harness.tree.on_disconnected_downloaded_block( + downloaded, + missing_parent, + local_tip, + ); + match gap { + 1024 => assert!(matches!( + event, + Some(TreeEvent::Download(DownloadRequest::BlockRange(hash, 1024))) + if hash == parent_hash + )), + _ => assert!(matches!( + event, + Some(TreeEvent::BackfillAction(BackfillAction::Start(target))) + if target.sync_target() == Some(target_hash) + )), + } + } } diff --git a/crates/node/core/src/args/engine.rs b/crates/node/core/src/args/engine.rs index 06df7745ece..55c6667677c 100644 --- a/crates/node/core/src/args/engine.rs +++ b/crates/node/core/src/args/engine.rs @@ -7,8 +7,9 @@ use clap::{ use eyre::ensure; use reth_cli_util::{parse_duration_from_secs_or_ms, parsers::format_duration_as_secs_or_ms}; use reth_engine_primitives::{ - TreeConfig, DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD, DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE, - DEFAULT_NUM_STATE_MASKING_BLOCKS, DEFAULT_PERSISTENCE_BACKPRESSURE_THRESHOLD, + TreeConfig, DEFAULT_BACKFILL_RUN_THRESHOLD, DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD, + DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE, DEFAULT_NUM_STATE_MASKING_BLOCKS, + DEFAULT_PERSISTENCE_BACKPRESSURE_THRESHOLD, }; use std::{sync::OnceLock, time::Duration}; @@ -29,6 +30,7 @@ pub struct DefaultEngineValues { persistence_backpressure_threshold: u64, num_state_masking_blocks: u64, memory_block_buffer_target: u64, + backfill_run_threshold: u64, invalid_header_hit_eviction_threshold: u8, state_cache_disabled: bool, prewarming_disabled: bool, @@ -93,6 +95,12 @@ impl DefaultEngineValues { self } + /// Set the default backfill run threshold + pub const fn with_backfill_run_threshold(mut self, v: u64) -> Self { + self.backfill_run_threshold = v; + self + } + /// Set the invalid header cache hit eviction threshold pub const fn with_invalid_header_hit_eviction_threshold(mut self, v: u8) -> Self { self.invalid_header_hit_eviction_threshold = v; @@ -266,6 +274,7 @@ impl Default for DefaultEngineValues { persistence_backpressure_threshold: DEFAULT_PERSISTENCE_BACKPRESSURE_THRESHOLD, num_state_masking_blocks: DEFAULT_NUM_STATE_MASKING_BLOCKS, memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, + backfill_run_threshold: DEFAULT_BACKFILL_RUN_THRESHOLD, invalid_header_hit_eviction_threshold: DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD, state_cache_disabled: false, prewarming_disabled: false, @@ -348,6 +357,20 @@ pub struct EngineArgs { #[arg(long = "engine.memory-block-buffer-target")] pub memory_block_buffer_target: Option, + /// Configure the largest gap, in blocks, between the local head and the forkchoice head that + /// is closed by downloading the missing blocks directly. Larger gaps trigger a full pipeline + /// (backfill) run instead. + /// + /// On chains with short block times a pipeline run may take longer than it takes the chain to + /// produce another gap of this size, in which case raising this value lets the node catch up + /// via live sync. Values above 1024 are clamped to the peer header response limit. + #[arg( + long = "engine.backfill-threshold", + env = "RETH_ENGINE_BACKFILL_THRESHOLD", + default_value_t = DefaultEngineValues::get_global().backfill_run_threshold + )] + pub backfill_run_threshold: u64, + /// Configure how many cache hits an invalid header can accumulate before it is evicted and /// reprocessed. /// @@ -588,6 +611,7 @@ impl Default for EngineArgs { persistence_backpressure_threshold: _, num_state_masking_blocks, memory_block_buffer_target: _, + backfill_run_threshold, invalid_header_hit_eviction_threshold, state_cache_disabled, prewarming_disabled, @@ -621,6 +645,7 @@ impl Default for EngineArgs { persistence_backpressure_threshold: None, num_state_masking_blocks, memory_block_buffer_target: None, + backfill_run_threshold, invalid_header_hit_eviction_threshold, state_root_task_compare_updates, legacy_state_root_task_enabled: false, @@ -727,6 +752,7 @@ impl EngineArgs { .with_persistence_threshold(self.persistence_threshold) .with_memory_block_buffer_target(self.memory_block_buffer_target()) .with_num_state_masking_blocks(self.num_state_masking_blocks) + .with_backfill_run_threshold(self.backfill_run_threshold) .with_invalid_header_hit_eviction_threshold(self.invalid_header_hit_eviction_threshold) .without_state_cache(self.state_cache_disabled) .without_prewarming(self.prewarming_disabled) @@ -882,6 +908,7 @@ mod tests { persistence_backpressure_threshold: Some(101), num_state_masking_blocks: DEFAULT_NUM_STATE_MASKING_BLOCKS, memory_block_buffer_target: Some(50), + backfill_run_threshold: 100, invalid_header_hit_eviction_threshold: 7, legacy_state_root_task_enabled: true, caching_and_prewarming_enabled: true, @@ -928,6 +955,8 @@ mod tests { "101", "--engine.memory-block-buffer-target", "50", + "--engine.backfill-threshold", + "100", "--engine.invalid-header-cache-hit-eviction-threshold", "7", "--engine.legacy-state-root", @@ -1020,6 +1049,23 @@ mod tests { .is_err()); } + #[test] + fn test_parse_backfill_threshold() { + let args = CommandParser::::parse_from(["reth"]).args; + let config = args.tree_config(); + assert_eq!(config.backfill_run_threshold(), DEFAULT_BACKFILL_RUN_THRESHOLD); + + for (threshold, expected) in [("500", 500), ("2048", 1024)] { + let args = CommandParser::::parse_from([ + "reth", + "--engine.backfill-threshold", + threshold, + ]) + .args; + assert_eq!(args.tree_config().backfill_run_threshold(), expected); + } + } + #[test] fn validate_rejects_state_masking_window_at_or_above_threshold() { let args = EngineArgs { diff --git a/docs/vocs/docs/pages/cli/reth/node.mdx b/docs/vocs/docs/pages/cli/reth/node.mdx index d3835ed45d4..4b61721e5d3 100644 --- a/docs/vocs/docs/pages/cli/reth/node.mdx +++ b/docs/vocs/docs/pages/cli/reth/node.mdx @@ -998,6 +998,14 @@ Engine: If omitted, this defaults to the lesser of `--engine.persistence-threshold` and the configured default memory block buffer target. + --engine.backfill-threshold + Configure the largest gap, in blocks, between the local head and the forkchoice head that is closed by downloading the missing blocks directly. Larger gaps trigger a full pipeline (backfill) run instead. + + On chains with short block times a pipeline run may take longer than it takes the chain to produce another gap of this size, in which case raising this value lets the node catch up via live sync. Values above 1024 are clamped to the peer header response limit. + + [env: RETH_ENGINE_BACKFILL_THRESHOLD=] + [default: 32] + --engine.invalid-header-cache-hit-eviction-threshold Configure how many cache hits an invalid header can accumulate before it is evicted and reprocessed.