Skip to content

fix(dash-spv)!: settle filter requests on network arrival - #1370

Merged
ZocoLini merged 2 commits into
devfrom
fix/cfilters-settle-on-arrival
Nov 21, 2026
Merged

ZocoLini merged 2 commits into
devfrom
fix/cfilters-settle-on-arrival

Conversation

@xdustinface

@xdustinface xdustinface commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

A CFilters or CfHeaders request stayed on the wire until its serial manager processed the reply, which could be a million messages later. A kicked peer then had its delivered batches sent again, and a busy manager looked like a stalled peer.

The network pump now settles a filter request as soon as its reply arrives, as it already did for blocks. CFilters requests are keyed by stop hash, so the last cfilter of a reply identifies its request without a scan. A settled request stays registered until its manager releases it, so every path that drops a delivered batch now releases it: a batch whose last filter arrived incomplete, a stop hash no stored header resolves, a rescan reset, and a cfheaders reply that matches nothing.

Closes #1234

PR Hygiene · 51a854b

  • Bots — coderabbitai skipped after its own rate limit
  • Self-review — post /self-reviewed
  • Build running
  • Approvals — you own every area touched; none needed

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.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 899ba3b and 51a854b.

Files selected for processing: 8

  • dash-spv/src/network/broker.rs
  • dash-spv/src/network/manager.rs
  • dash-spv/src/sync/filter_headers/manager.rs
  • dash-spv/src/sync/filter_headers/sync_manager.rs
  • dash-spv/src/sync/filters/manager.rs
  • dash-spv/src/sync/filters/pipeline.rs
  • dash-spv/src/sync/filters/sync_manager.rs
  • dash-spv/src/test_utils/network.rs
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • 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

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.49%. Comparing base (d7325ae) to head (51a854b).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1370      +/-   ##
==========================================
+ Coverage   86.38%   86.49%   +0.10%     
==========================================
  Files         270      270              
  Lines       70849    71053     +204     
==========================================
+ Hits        61204    61457     +253     
+ Misses       9645     9596      -49     
Flag Coverage Δ
core 82.99% <ø> (+0.08%) ⬆️
rpc 52.10% <ø> (ø)
spv 94.59% <100.00%> (+0.01%) ⬆️
wallet 85.24% <ø> (+0.21%) ⬆️
Files with missing lines Coverage Δ
dash-spv/src/network/broker.rs 97.84% <100.00%> (-0.46%) ⬇️
dash-spv/src/network/manager.rs 93.58% <100.00%> (+0.19%) ⬆️
dash-spv/src/sync/filter_headers/manager.rs 96.79% <100.00%> (+0.08%) ⬆️
dash-spv/src/sync/filter_headers/sync_manager.rs 100.00% <ø> (ø)
dash-spv/src/sync/filters/manager.rs 97.93% <100.00%> (+0.10%) ⬆️
dash-spv/src/sync/filters/pipeline.rs 98.54% <100.00%> (+0.02%) ⬆️
dash-spv/src/sync/filters/sync_manager.rs 100.00% <ø> (ø)

... and 6 files with indirect coverage changes

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Nov 9, 2026
@xdustinface
xdustinface force-pushed the fix/cfilters-settle-on-arrival branch from 3a69ba0 to 73f9869 Compare November 10, 2026 06:07
@github-actions github-actions Bot removed the merge-conflict The PR conflicts with the target branch. label Nov 10, 2026
@xdustinface
xdustinface force-pushed the fix/cfilters-settle-on-arrival branch 2 times, most recently from 60cb181 to 810e7de Compare November 10, 2026 06:11
@xdustinface
xdustinface force-pushed the fix/shared-stall-kicks branch from 80d80bf to ca66de7 Compare November 10, 2026 14:19
@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@xdustinface
xdustinface force-pushed the fix/cfilters-settle-on-arrival branch from 810e7de to 74f9283 Compare November 10, 2026 14:27
@github-actions github-actions Bot removed the merge-conflict The PR conflicts with the target branch. label Nov 10, 2026
@xdustinface
xdustinface force-pushed the fix/shared-stall-kicks branch from ca66de7 to e89874d Compare November 11, 2026 01:21
@xdustinface
xdustinface force-pushed the fix/cfilters-settle-on-arrival branch from 74f9283 to bb5a0d0 Compare November 11, 2026 01:21
@xdustinface
xdustinface force-pushed the fix/shared-stall-kicks branch from e89874d to 5cc69f8 Compare November 12, 2026 22:33
@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@xdustinface
xdustinface force-pushed the fix/shared-stall-kicks branch 3 times, most recently from 3b3971d to a37e9b9 Compare November 13, 2026 02:57
@xdustinface
xdustinface force-pushed the fix/shared-stall-kicks branch 6 times, most recently from 4d4641f to 46beb07 Compare November 13, 2026 11:52
Base automatically changed from fix/shared-stall-kicks to dev November 20, 2026 09:11
A `getcfilters` request was keyed by its start height, but no `cfilter` in the reply carries a height. Mapping a reply back to its request needed the filters pipeline, which resolves each block hash to a height through storage.

The last `cfilter` of a reply is the one for the request's stop hash. Keying `RequestKey::CFilters` by that hash lets anything that sees the reply identify its request directly, without a scan or a storage lookup. The filters pipeline already records the stop hash of each batch it sends, so a completed batch now returns that hash for the release.
A `CFilters` or `CfHeaders` request stayed on the wire until its serial manager processed the reply, which could be a million messages later. A kicked peer then had its delivered batches sent again, and a busy manager looked like a stalled peer.

The network pump now settles a filter request as soon as its reply arrives, as it already did for blocks. `Broker::block_arrived` becomes `Broker::arrived`, which takes any request key. The last `cfilter` of a reply carries the stop hash that keys its `CFilters` request, and a `cfheaders` reply carries the stop hash of its `CfHeaders` request.

A settled key stays registered until its manager releases it, so every path that drops a delivered batch now releases it. The filter headers manager releases a `cfheaders` reply whatever comes of it. The filters manager releases a batch whose last filter arrived while earlier ones are missing, so the next tick requests it again, a reply whose stop hash no stored header resolves, and the wanted batches it drops in a rescan reset.
@xdustinface
xdustinface force-pushed the fix/cfilters-settle-on-arrival branch from bb5a0d0 to 51a854b Compare November 20, 2026 11:14
@github-actions github-actions Bot removed the merge-conflict The PR conflicts with the target branch. label Nov 20, 2026
@xdustinface
xdustinface marked this pull request as ready for review November 20, 2026 22:14
@manki-review

manki-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

✅ Review complete in 9m 35s

Planner (6s)
    fix · 317 lines · 2 agents
    judge effort: high

Review (behavior · full): 8 findings
    ✅ Claude Opus 5.5 · high: 1 finding (2m 41s)
    ✅ GPT 6.2 Sol · high: 7 findings (3m 20s)

Judge: 4 kept · 3 dropped (4m 33s)
    kept: 1 warning · 3 suggestions
    dropped: 2 blockers · 1 warning

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 3% (resets 2026-11-27 01:00 UTC)
  • ChatGPT subscription: weekly 2% (resets 2026-11-25 01:21 UTC)

Judge decisions:

  • Kept: "No dashd integration test for the change to filter request handling during sync" (suggestion): "note. dash-spv/AGENTS.md requires a dashd test under tests/dashd_sync/ or tests/dashd_masternode/ for any change to sync, restart or disconnect handling. This PR changes when filter requests settle on arrival and are released (manager.rs:1329-1341, filter_headers/sync_manager.rs:52, filters/manager.rs:261). It also changes what a kicked peer's requeue re-sends. The changed-files list holds no file under tests/, so the rule is broken. The missing test does no harm at run time, so the row is improvement."
  • Kept: "An unverified filter reply can cancel a live request" (warning): "warning at most until confirmed. Peer input decides what happens in two places.

Incomplete reply. The pump settles a CFilters request from the stop-hash cfilter alone (manager.rs:1332). The new branch in filters/pipeline.rs:230-240 then returns the stop hash for an incomplete batch whose last filter arrived, and filters/sync_manager.rs:149 releases the key. tick re-declares the batch as Queued(0) (broker.rs:116). So a peer that sends only the last filter avoids the stall timeout that used to kick it, and the attempt count restarts.

Release from any peer. filter_headers/sync_manager.rs:52 now releases CfHeaders(stop_hash) for any cfheaders from any peer before matching, even an empty one that match_response rejects (filter_headers/pipeline.rs:245). The filters path releases on a last-height cfilter from any peer in the same way. Either one releases an OnWire request that is still assigned to another peer (broker.rs:127), which causes a duplicate request.

Whether this stalls sync, and not only wastes requests, depends on routing picking the same peer again. I could not follow that in the code shown, so it is listed as a doubt.
Refutation unsettled: The pump marks a CFilters key as arrived when the cfilter for the stop hash comes from the request's own peer. The pipeline then returns the stop hash for an incomplete batch once its last filter arrives, and the manager releases the key. The next declaration re-registers it as Queued(0), so the stall timer and attempt count start over. Separately, the filter-headers manager releases CfHeaders(stop_hash) for any cfheaders from any peer before matching it. release removes an OnWire ... Rule checked: A broker that keys a request only by its stop hash, and lets a manager release that key without checking which peer replied or whether the reply was complete, re-registers the request as new (Queued(0)) after any reply that carries the key.

  • Premise "After a peer answers its own getcfilters with only the cfilter for the stop hash, the router in dash-spv/src/network/broker.rs sends the re-declared request back to that same peer, so the peer is never kicked for stalling and the batch never completes" unsettled. When the request is sent again, choose_peer picks a CFilters request by the lowest ratio of in-flight bytes to cap and does not remember who carried it before. The peer that answered with one filter has just had its in-flight bytes released, so it is a likely pick and the only pick when it is the sole peer. Still, the code does not always send the request back to that peer: an honest, less loaded peer can get it and finish the batch."
  • Dropped: "Settled or cancelled requests can still be sent by the router" (ignore): "ignore. The race is real, but the broker handles it on purpose: the router skips registering a request whose key is already Arrived (broker.rs:344-345), and the comment there names this case. The outcome is one duplicate getcfilters whose reply is dropped, because the tracker is gone or the key is settled. No data is lost and sync does not stall. The claim that a popped request gets registered under a newly declared key rests on a timing no line shows."
  • Kept: "The public filter request key changes type and conflates different ranges" (suggestion): "note. Keying CFilters by stop hash is the point of the PR, so this is an intended change.

No consumer repo references RequestKey::CFilters: the RequestKey in dash-evo-tool is its own struct. The ranges the pipeline builds have distinct stop heights, so the code produces no two live ranges that share a stop hash. The old start-height key conflated ranges in the same way, just by start instead of stop.

The open question is whether a public enum change should carry ! in the PR title, which AGENTS.md asks for on breaking changes."

  • Dropped: "A rejected filter batch leaves a permanent gap in wallet sync" (ignore): "ignore. Removing the tracker on completion and validating later in store_and_match_batches (manager.rs:536, 572) is unchanged by this PR. Line 249 only captures the stop hash it already removed, and the release before validation existed in the base under the start-height key. The PR neither causes nor changes this path."

  • Dropped: "Peer messages can exhaust memory while a sync manager drains its backlog" (ignore): "ignore. The unbounded channels and the forwarding at manager.rs:1428-1449 are untouched by this PR. The new arrived call does not change what is forwarded or how much, so the PR neither causes nor affects this."

  • Kept: "Filter regression tests seed the internal state they are meant to exercise" (suggestion): "note. The root AGENTS.md forbids setting internal fields or states by hand in tests. Two added tests do so:

  • test_receive_batch_completion_returns_the_stop_hash writes pipeline.batch_stops.insert(0, stop_hash) directly (pipeline.rs:420).

  • a_kick_requeues_no_delivered_filter_batch puts requests on the wire with mark_on_wire instead of routing them (manager.rs:2069).

Both tests still run the changed code, so they can fail when it breaks. That keeps this on the improvement row."

Timing:

  • Parse: 6.3s
  • Review agents: 296.4s
  • Judge: 272.6s
  • Total: 575.3s

Last reviewed 51a854b · head 51a854b · up to date

  • Pause automatic reviews
  • Review again
  • Deeper review

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Nov 20, 2026

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 1 warning to address. Fix it, reply in its thread with a reason Manki accepts, or tick Create an issue for this to track it for later. Manki approves once every warning is handled.


Related work: open PRs and issues this PR may duplicate or fix. None of them blocks.

About this review
  • Reviewed 51a854b, round 1
  • 317 changed lines read in 9m 35s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 3.5M in (2.7M from cache) · 75k out · about $5.92 at API prices, partly priced
  • Runner: self-hosted · started after 12s · peak memory 3.1 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/manager.rs Resolved
Comment thread dash-spv/src/network/manager.rs Resolved
Comment thread dash-spv/src/network/manager.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
@xdustinface xdustinface changed the title fix(dash-spv): settle filter requests on network arrival fix(dash-spv)!: settle filter requests on network arrival Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Manki did not run: Could not get a token from the Manki token service (no OIDC token, so the workflow needs id-token: write). Retry the run.

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved. All blocking threads are resolved, and no warning thread holds the approval.

What this does: Filter and filter-header requests were only cleared once the sync manager processed them, so a long backlog looked like a stalled peer. The broker now marks them done when the reply arrives.

What to test

The review model wrote these steps. Check what a step runs before you follow it.

Setup: Run the SPV client against testnet or a regtest dashd with filters enabled, with debug logging for dash_spv::network.

  1. Do a fresh filter sync from genesis or a checkpoint. Expect filters to download to the tip and committed_height to reach the tip without repeated request timeout: kicked lines caused by the filter backlog.
  2. Run just dash-spv::test. Expect the dashd sync and restart tests to pass.
  3. Disconnect the network mid filter sync, then reconnect. Expect filter sync to resume and complete without re-requesting already completed batches.
  4. Add a wallet with a low birth height after the client is synced, which triggers a rescan. Expect the old batches to be dropped, new getcfilters requests to go out, and the sync to finish.
  5. Restart a client that is already synced and wait for a new block. Expect the new block's filter header and filter to be fetched and committed.
  6. Edge case: kill or firewall a peer while it is answering a getcfilters. Expect the request to be re-sent to another peer and the batch to complete.
  7. Edge case: watch logs for ended incomplete ... requesting it again. When it appears, expect the same batch to be requested again on the next tick and to complete.

@ZocoLini
ZocoLini merged commit 2f35e08 into dev Nov 21, 2026
64 of 69 checks passed
@ZocoLini
ZocoLini deleted the fix/cfilters-settle-on-arrival branch November 21, 2026 11:56
manki-review Bot added a commit to manki-review/review-memory that referenced this pull request Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dash-spv: a peer whose filter replies wait in our own backlog is kicked as stalled

2 participants