Skip to content

refactor(stages): extract IncrementalSettings struct from MerkleStage#20698

Closed
meetrick wants to merge 2 commits intoparadigmxyz:mainfrom
meetrick:refactor/merkle-incremental-settings
Closed

refactor(stages): extract IncrementalSettings struct from MerkleStage#20698
meetrick wants to merge 2 commits intoparadigmxyz:mainfrom
meetrick:refactor/merkle-incremental-settings

Conversation

@meetrick
Copy link
Contributor

@meetrick meetrick commented Jan 2, 2026

refactor(stages): extract IncrementalSettings struct from MerkleStage

Problem

The MerkleStage enum duplicated the rebuild_threshold and incremental_threshold fields across both the Execution and Both variants. This required making the same changes in multiple places when modifying threshold-related behavior, increasing maintenance overhead and the risk of inconsistencies.

Analysis

Both variants use these thresholds in exactly the same way inside execute(): they determine when to rebuild the trie versus apply incremental updates, and they control the chunk size in incremental mode. The unwind() path does not reference these values at all. The only behavioral difference between the variants is that Execution skips unwind, while Both supports both execution and unwind. No behavioral changes are introduced by this refactor, making it safe to consolidate the duplicated fields.

Solution

Introduce a new IncrementalSettings struct that encapsulates both threshold fields and provides a Default implementation. The relevant MerkleStage variants now store this struct instead of duplicating the fields. This refactor is purely structural and does not change stage semantics or public behavior.

Changes

  • crates/stages/stages/src/stages/merkle.rs: added IncrementalSettings, updated enum variants, and adjusted match patterns
  • crates/cli/commands/src/stage/dump/merkle.rs: updated MerkleStage::Execution construction
  • crates/stages/stages/benches/criterion.rs: updated MerkleStage::Both construction

Code paths using new_execution() or default_unwind() required no changes.

Verification

  • All 104 tests in reth-stages passed
  • Full workspace build succeeded
  • Clippy passed with no warnings

Extract `rebuild_threshold` and `incremental_threshold` fields into
a shared `IncrementalSettings` struct to reduce duplication between
`Execution` and `Both` variants.

Signed-off-by: Hwangjae Lee <meetrick@gmail.com>
@meetrick meetrick force-pushed the refactor/merkle-incremental-settings branch from 61385d2 to 271d724 Compare January 2, 2026 04:22
Signed-off-by: Hwangjae Lee <meetrick@gmail.com>
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure if we really need this @Rjected

@github-actions github-actions bot added the S-stale This issue/PR is stale and will close with no further activity label Feb 1, 2026
@github-actions github-actions bot closed this Feb 9, 2026
@github-project-automation github-project-automation bot moved this from Backlog to Done in Reth Tracker Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-stale This issue/PR is stale and will close with no further activity

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants