Skip to content

refactor(sync): converge duplicated gap-fetch arithmetic in head sync#981

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:audit/arch-10-converge-gap-fetch-arithmetic
Jun 12, 2026
Merged

refactor(sync): converge duplicated gap-fetch arithmetic in head sync#981
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:audit/arch-10-converge-gap-fetch-arithmetic

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

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/:

  • Head sync, when caching an orphan gossip block whose parent is missing.
  • Backfill sync, when received blocks still have a missing parent far above the highest known slot.

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_head method on the backfill syncer that returns whether a range fetch was issued. Both call sites route through it:

  • Head sync falls back to parent-by-root recursion when the gap is empty (single-slot gap above head, or alt-fork gossip at or below head).
  • Backfill keeps its unconditional root recursion afterward.

Behavior and bounds are preserved exactly. The now-unused Slot and Uint64 imports 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

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>
@tcoratger tcoratger merged commit b3007c1 into leanEthereum:main Jun 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant