Skip to content

fix: prevent invalid header response routing#439

Merged
xdustinface merged 1 commit intov0.42-devfrom
fix/consider-completed-segments
Feb 16, 2026
Merged

fix: prevent invalid header response routing#439
xdustinface merged 1 commit intov0.42-devfrom
fix/consider-completed-segments

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Feb 16, 2026

After a Segment reaches its checkpoint, its current_tip_hash equals the next segment's start_hash. Since segments are iterated in order, the completed segment matches first and consumes responses meant for the next segment, buffering headers past its target height. This advanced the storage tip beyond the next segment's start, causing a validation failure and the header sync getting stuck.

Skip completed non-tip segments when routing incoming headers, and reject headers in receive_headers() if the segment is already complete.

Summary by CodeRabbit

  • Improvements

    • Enhanced block header synchronization to prevent routing headers to already-completed segments, improving sync efficiency and preventing unnecessary buffering.
    • Improved tip segment recovery when headers are received in post-sync scenarios.
  • Tests

    • Added validation for correct header routing behavior to active segments.

After a `Segment` reaches its checkpoint, its `current_tip_hash` equals the
next segment's `start_hash`. Since segments are iterated in order, the
completed segment matches first and consumes responses meant for the next
segment, buffering headers past its target height. This advanced the
storage tip beyond the next segment's start, causing a validation failure
and the header sync getting stuck.

Skip completed non-tip segments when routing incoming headers, and reject
headers in `receive_headers()` if the segment is already complete.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

The changes add logic to prevent header routing to completed non-tip segments and reset tip segments in post-sync scenarios. A field visibility change allows parent module access to current_tip_hash. A new test verifies headers route to the correct next segment without buffering violations.

Changes

Cohort / File(s) Summary
Header Routing Logic
dash-spv/src/sync/block_headers/pipeline.rs
Added conditional logic to skip routing headers to completed non-tip segments; implemented tip segment reset on post-sync header receipt; added test verifying headers route to next non-complete segment (segment 1) rather than completed segment (segment 0), ensuring proper buffering behavior.
Field Visibility
dash-spv/src/sync/block_headers/segment_state.rs
Changed current_tip_hash field visibility from private to pub(super), expanding access to parent module scope.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Headers skip the finish line,
Where tips and segments once align,
To next they hop with careful grace,
No theft within this buffer space! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically addresses the main fix: preventing header responses from being routed to completed segments that should not receive them.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into v0.42-dev

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/consider-completed-segments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xdustinface xdustinface merged commit 64b8573 into v0.42-dev Feb 16, 2026
53 checks passed
@xdustinface xdustinface deleted the fix/consider-completed-segments branch February 16, 2026 15:36
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.

2 participants