Skip to content

Conversation

@AshinGau
Copy link
Contributor

@AshinGau AshinGau commented Dec 3, 2025

Description

Problem

The incremental merkle update loop uses range.step_by(incremental_threshold) combined with inclusive range start_block..=chunk_to, which causes boundary blocks to be processed twice.
Before (log / overlapping):

2025-12-03T03:48:20.240579Z  DEBUG Processing chunk current=50000 target=90000 incremental_threshold=7000 chunk_range=50001..=57001
2025-12-03T03:48:20.270721Z  DEBUG Processing chunk current=50000 target=90000 incremental_threshold=7000 chunk_range=57001..=64001
2025-12-03T03:48:20.290994Z  DEBUG Processing chunk current=50000 target=90000 incremental_threshold=7000 chunk_range=64001..=71001
2025-12-03T03:48:20.331801Z  DEBUG Processing chunk current=50000 target=90000 incremental_threshold=7000 chunk_range=71001..=78001
...

Solution

Replace step_by iterator with a while loop that advances start_block to chunk_to + 1, ensuring non-overlapping ranges.
After (log / non-overlapping):

2025-12-03T03:51:54.325227Z  DEBUG Processing chunk current=90000 target=150000 incremental_threshold=7000 chunk_range=90001..=97001
2025-12-03T03:51:54.356900Z  DEBUG Processing chunk current=90000 target=150000 incremental_threshold=7000 chunk_range=97002..=104002
2025-12-03T03:51:54.384736Z  DEBUG Processing chunk current=90000 target=150000 incremental_threshold=7000 chunk_range=104003..=111003
2025-12-03T03:51:54.414019Z  DEBUG Processing chunk current=90000 target=150000 incremental_threshold=7000 chunk_range=111004..=118004
...

Note

The current merkle algorithm is idempotent, so correctness is unaffected. This fix eliminates redundant computation and ensures correctness if the implementation ever becomes non-idempotent.

Copy link
Collaborator

@mediocregopher mediocregopher left a comment

Choose a reason for hiding this comment

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

This looks right to me, will wait for @shekhirin

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants