Skip to content

fix(dash-spv): preserve buffered block headers across disconnect#702

Open
xdustinface wants to merge 1 commit intov0.42-devfrom
fix/preserve-buffered-headers-on-disconnect
Open

fix(dash-spv): preserve buffered block headers across disconnect#702
xdustinface wants to merge 1 commit intov0.42-devfrom
fix/preserve-buffered-headers-on-disconnect

Conversation

@xdustinface
Copy link
Copy Markdown
Collaborator

@xdustinface xdustinface commented Apr 29, 2026

BlockHeadersManager::clear_in_flight_state rebuilt the entire HeadersPipeline on every disconnect, throwing away each segment's current_tip_hash, current_height, buffered_headers, and complete flags.

This PR splits it so that SegmentState::clear_in_flight and HeadersPipeline::clear_in_flight now reset only the DownloadCoordinator per segment. BlockHeadersManager::clear_in_flight_state calls the pipeline-level helper instead of constructing a new pipeline. start_sync skips pipeline.init when the pipeline is already initialized and calls reset_tip_segment so a previously synced tip is prepared to let send_pending re-fire GetHeaders.

Adds unit coverage for the new clear path at the segment, pipeline, and manager levels (mid-sync and post-sync disconnect/reconnect cycles), plus a header-progress monotonicity assertion in run_disconnect_loop so the dashd integration tests catch a future regression that drops validated chain state on disconnect.

Summary by CodeRabbit

  • Tests

    • Added peer disconnect/reconnect tests verifying chain state preservation and sync resumption.
  • Refactor

    • Improved disconnect/reconnect flow to preserve validated segment state across network interruptions, enabling faster resumption.
    • Enhanced test helpers with header height monotonicity assertions to detect chain state regressions.

`BlockHeadersManager::clear_in_flight_state` rebuilt the entire `HeadersPipeline` on every disconnect, throwing away each segment's `current_tip_hash`, `current_height`, `buffered_headers`, and `complete` flags.

This PR splits it so that `SegmentState::clear_in_flight` and `HeadersPipeline::clear_in_flight` now reset only the `DownloadCoordinator` per segment. `BlockHeadersManager::clear_in_flight_state` calls the pipeline-level helper instead of constructing a new pipeline. `start_sync` skips `pipeline.init` when the pipeline is already initialized and calls `reset_tip_segment` so a previously synced tip is prepared to let `send_pending` re-fire `GetHeaders`.

Adds unit coverage for the new clear path at the segment, pipeline, and manager levels (mid-sync and post-sync disconnect/reconnect cycles), plus a header-progress monotonicity assertion in `run_disconnect_loop` so the dashd integration tests catch a future regression that drops validated chain state on disconnect.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 25382f3f-3309-465b-a23a-90b5051615af

📥 Commits

Reviewing files that changed from the base of the PR and between 55cf3c7 and 6ae8662.

📒 Files selected for processing (5)
  • dash-spv/src/sync/block_headers/manager.rs
  • dash-spv/src/sync/block_headers/pipeline.rs
  • dash-spv/src/sync/block_headers/segment_state.rs
  • dash-spv/src/sync/block_headers/sync_manager.rs
  • dash-spv/tests/dashd_sync/helpers.rs

📝 Walkthrough

Walkthrough

This PR refactors the block header synchronization pipeline to preserve segment state and per-segment progress during peer disconnection/reconnection. It introduces a clear_in_flight method to reset only per-peer download tracking while maintaining chain validation progress, adds async tests for reconnection scenarios, and enhances integration tests with monotonicity assertions.

Changes

Cohort / File(s) Summary
Pipeline state preservation
dash-spv/src/sync/block_headers/pipeline.rs, dash-spv/src/sync/block_headers/segment_state.rs, dash-spv/src/sync/block_headers/sync_manager.rs
Removes checkpoint manager getter from HeadersPipeline; introduces clear_in_flight() method to reset per-peer download tracking (coordinator state) while preserving segment buffers and validated tip state; refactors start_sync to conditionally initialize pipeline and reset tip segment on resume instead of recreating pipeline from scratch.
Header sync tests
dash-spv/src/sync/block_headers/manager.rs
Adds two async tests: one simulating initial sync with pipeline disconnect/reconnect and header advancement, verifying locator hash preservation; another verifying resumed GetHeaders after reconnect with higher peer height targets the previously-synced tip.
Integration test enhancements
dash-spv/tests/dashd_sync/helpers.rs
Introduces helper to compute SPV headers manager effective height from progress watch channel; enhances run_disconnect_loop to snapshot and re-check header height across disconnect cycles, asserting monotonicity to detect regressions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Through disconnects and reconnects we hop,
State preserved, our progress won't drop,
In-flight cleared but chains stay true,
Headers synced, made fresh and new!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(dash-spv): preserve buffered block headers across disconnect' directly and precisely describes the main change—that buffered block headers are now preserved when peers disconnect, rather than being lost by pipeline reconstruction.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/preserve-buffered-headers-on-disconnect

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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 97.31544% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.64%. Comparing base (55cf3c7) to head (6ae8662).

Files with missing lines Patch % Lines
dash-spv/src/sync/block_headers/manager.rs 94.36% 4 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #702      +/-   ##
=============================================
+ Coverage      70.58%   70.64%   +0.06%     
=============================================
  Files            320      320              
  Lines          68028    68172     +144     
=============================================
+ Hits           48018    48162     +144     
  Misses         20010    20010              
Flag Coverage Δ
core 75.81% <ø> (ø)
ffi 43.53% <ø> (ø)
rpc 20.00% <ø> (ø)
spv 87.38% <97.31%> (+0.12%) ⬆️
wallet 69.49% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/sync/block_headers/pipeline.rs 94.21% <100.00%> (+0.88%) ⬆️
dash-spv/src/sync/block_headers/segment_state.rs 97.36% <100.00%> (+0.36%) ⬆️
dash-spv/src/sync/block_headers/sync_manager.rs 84.61% <100.00%> (-0.39%) ⬇️
dash-spv/src/sync/block_headers/manager.rs 90.03% <94.36%> (+0.41%) ⬆️

... and 4 files with indirect coverage changes

@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label Apr 29, 2026
@xdustinface xdustinface requested a review from ZocoLini April 29, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review CodeRabbit has approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant