refactor(sync): converge duplicated gap-fetch arithmetic in head sync#981
Merged
tcoratger merged 1 commit intoJun 12, 2026
Conversation
The same start/floor/size computation for range-fetching a gap of blocks above the head was duplicated in head sync and backfill sync. Both computed the gap floor as head + 1, derived the gap size, and dispatched to a range fetch when positive. Factor that into a single method on the backfill syncer that returns whether a range fetch was issued. Route both sites through it: head sync falls back to parent-by-root recursion when the gap is empty, and backfill keeps its unconditional root recursion afterward. Behavior and bounds are preserved. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The same start/floor/size computation for range-fetching a contiguous gap of blocks above the chain head was duplicated in two places under
src/lean_spec/node/sync/:Both computed the gap floor as
head + 1, derived the gap size, logged, and dispatched to a range fetch when the size was positive.This change factors that logic into a single
fill_gap_above_headmethod on the backfill syncer that returns whether a range fetch was issued. Both call sites route through it:Behavior and bounds are preserved exactly. The now-unused
SlotandUint64imports were dropped from the head sync module.Testing
uv run pytest tests/node/sync/test_head_sync.py tests/node/sync/test_backfill_sync.py— all pass.just check— clean (lint, format, typecheck, spell, mdformat, lock).🤖 Generated with Claude Code