Skip to content

fix(dash-spv): reject CFHeaders batches that don't connect to stored filter headers - #1166

Merged
xdustinface merged 1 commit into
dashpay:devfrom
PastaPastaPasta:fix/spv-cfheaders-anchor
Oct 14, 2026
Merged

xdustinface merged 1 commit into
dashpay:devfrom
PastaPastaPasta:fix/spv-cfheaders-anchor

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

A CFHeaders response was stored as long as its stop hash matched an in-flight
request. Its previous_filter_header was not compared with the filter header
already stored at start_height - 1, and the number of filter hashes was not
compared with the requested range. A batch that doesn't connect to the stored
chain was stored and only failed later at filter verification.

Now process_cfheaders checks both before storing:

  • the batch has exactly one filter hash per block in start_height..=height(stop_hash);
  • except for the first batch of a fresh checkpoint sync (or a batch at genesis),
    previous_filter_header equals the stored header at start_height - 1.

A batch that fails either check is not stored. It is requested again together
with any buffered batches above it, and the pipeline does not move forward.
The in-order and buffered paths in handle_message now share one loop, so
both handle the rejection the same way.

Tests cover a non-connecting batch (in order and buffered), a short batch,
the first checkpoint batch, and resuming from stored filter headers.

Notes:

Related to #1118.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Filter-header batches are checked for chain consistency and complete height coverage before being saved. Invalid batches are retried, and affected buffered batches are requested again in order, helping downloads continue without storing inconsistent data.
    • Resumed downloads and initial checkpoint batches are handled correctly during validation.

PR Hygiene · 8608c52

  • Bots — coderabbitai ✓
  • Self-review — post /self-reviewed
  • Build green
  • Approvals
    • dash-spv (dash-spv/src/sync/filter_headers/manager.rs, dash-spv/src/sync/filter_headers/pipeline.rs, dash-spv/src/sync/filter_headers/sync_manager.rs) — QuantumExplorer or ZocoLini or xdustinface

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

…filter headers

A CFHeaders response was stored as long as its stop hash matched an
in-flight request. Its `previous_filter_header` was not compared with the
filter header already stored at `start_height - 1`, and the number of
filter hashes was not compared with the requested range. A batch that did
not connect to the stored chain was stored and only failed later at
filter verification.

Now each batch must contain exactly one filter hash per block in
`start_height..=height(stop_hash)`, and every batch except the first one
of a fresh checkpoint sync (or one starting at genesis) must chain from
the stored header. A batch that fails either check is not stored and is
requested again, together with any buffered batches above it, without
moving the pipeline forward.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: dashpay/rust-dashcore/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 848c7690-a513-4b8b-8a3a-30d146e2e603
📥 Commits

Reviewing files that changed from the base of the PR and between a6cdc20 and 8608c52.

📒 Files selected for processing: 3
  • dash-spv/src/sync/filter_headers/manager.rs
  • dash-spv/src/sync/filter_headers/pipeline.rs
  • dash-spv/src/sync/filter_headers/sync_manager.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

CFHeaders processing now validates batch heights, hash counts, and previous filter headers before storage. Rejected batches and higher buffered batches are requeued. Successful batches advance the pipeline and update sync progress.

Changes: CFHeaders sync

Layer / File(s) Summary
Validate CFHeaders batches
dash-spv/src/sync/filter_headers/manager.rs
Processing checks the stop height, hash count, and previous filter header before storage. Tests cover mismatches, checkpoint batches, and resumed syncs.
Requeue rejected batches
dash-spv/src/sync/filter_headers/pipeline.rs
The pipeline requeues the rejected batch and buffered batches above its start height. The test checks request order and confirms next_expected remains unchanged.
Process and retry ready batches
dash-spv/src/sync/filter_headers/sync_manager.rs
The handler processes ready batches in a loop. It requeues validation failures and stops processing; other errors propagate. Successful batches update progress and emit storage events.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant CFHeadersResponse
  participant FilterHeadersManager
  participant FilterHeadersPipeline
  CFHeadersResponse->>FilterHeadersManager: deliver batch
  FilterHeadersManager->>FilterHeadersManager: validate and process ready batch
  FilterHeadersManager->>FilterHeadersPipeline: requeue rejected batch and higher buffered batches
  FilterHeadersPipeline-->>FilterHeadersManager: enqueue retry requests
Loading

Suggested reviewers: xdustinface

Merge Risk: ⚪ Minimal · up to 8608c

No merge-blocking issue was identified in the CFHeaders validation and retry flow; the change is ready for normal merge checks.

Pre-merge checks: Passed 5
Passed 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 clearly and concisely describes the main change: rejecting CFHeaders batches that do not connect to stored filter headers.
Docstring Coverage Passed Docstring coverage is 85.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 3 files.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-self-review Waiting for the author to post /self-reviewed label Oct 14, 2026
@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.13115% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.82%. Comparing base (a6cdc20) to head (8608c52).

Files with missing lines Patch % Lines
dash-spv/src/sync/filter_headers/manager.rs 96.50% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1166      +/-   ##
==========================================
+ Coverage   78.76%   78.82%   +0.05%     
==========================================
  Files         302      302              
  Lines       80644    80874     +230     
==========================================
+ Hits        63518    63746     +228     
- Misses      17126    17128       +2     
Flag Coverage Δ
core 77.25% <ø> (ø)
ffi 52.12% <ø> (+0.16%) ⬆️
rpc 49.36% <ø> (ø)
spv 92.66% <97.13%> (-0.01%) ⬇️
wallet 82.12% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/sync/filter_headers/pipeline.rs 97.58% <100.00%> (+0.37%) ⬆️
dash-spv/src/sync/filter_headers/sync_manager.rs 100.00% <ø> (ø)
dash-spv/src/sync/filter_headers/manager.rs 95.96% <96.50%> (+4.38%) ⬆️

... and 22 files with indirect coverage changes

@xdustinface
xdustinface merged commit 6a7a2a6 into dashpay:dev Oct 14, 2026
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants