Repository navigation
fix(dash-spv): settle the requests a peer skipped - #1563
Conversation
Dash Core sends nothing for a `getcfheaders` or `getcfilters` whose range its filter index lacks, nor for a block it does not have. The byte charge of such a request stayed on the peer's ledger for the life of the connection, which shrank the room the router saw for that peer. A skipped `getcfilters` was worse: every later `cfilter` added its bytes to the skipped batch and no later batch of that peer ever settled, so its charges piled up until the peer looked full. Peers answer in request order, so a filter header, filter or block reply now settles the charge of every earlier request of those kinds the peer still owes, and a `cfilter` settles the batch whose stop hash it carries. The bytes a skipped batch collected count toward the batch that was actually served.
|
This pull request is a draft, so Manki does not review it automatically. Marking it ready for review starts automatic reviews. Until then, someone with write access to this repository can tick a box below: Review this draft reviews the current commit once, Deeper review does so with more effort, and Review every push reviews it now and again after each push. |
|
Warning Review limit reachedYou'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 15 minutes. View limit details
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. |
|
CI does not run on this PR while it is a draft. Someone with write access can start it here:
Marking the PR ready for review also starts CI. CI started for d510056: Continuous integration, Pre-commit Checks, Sanitizer. |
|
✅ Review complete in 11m 0s Planner (6s) Review (behavior · full): 8 findings Judge (4m 24s) Posted: 2 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1563 +/- ##
=======================================
Coverage 87.79% 87.79%
=======================================
Files 270 270
Lines 72494 72513 +19
=======================================
+ Hits 63645 63662 +17
- Misses 8849 8851 +2
|
There was a problem hiding this comment.
Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.
✅ Approved. 2 suggestions, none of which block.
- Check approval
What this does: When a peer silently skips a block or compact-filter request, the client kept counting those bytes as still owed forever. A reply to a later request of these kinds now clears the earlier unanswered ones, so the peer's in-flight byte budget stays accurate.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Run the dash-spv unit tests and a regtest sync against dashd with just dash-spv::test.
- Run
cargo test -p dash-spv --lib a_reply_settles_the_requests_its_peer_skipped. Expect the filter headers, filters and blocks cases to pass. - Run
cargo test -p dash-spv --lib network::costs. Expect the existing header and silence tests to still pass. - Sync a fresh wallet against regtest
dashd. Expect filter and block sync to complete with no stalled peer. - Restart the client mid filter sync. Expect it to resume and finish.
- Edge case: request a block the node does not have, followed by another block. Expect the second block's arrival to clear the first request from the peer's in-flight bytes, and an outstanding header request to stay counted.
Checked and left out: 3 findings (2 unproven, 1 rare)
Not proven, so not listed · 2 warnings
- A
cfilterfrom an older overlapping batch settles a newer batch and releases the one still streaming ·dash-spv/src/network/costs.rs:246
A check of the code could not confirm it. - The peer test for charging in write order passes even when the charge order is wrong ·
dash-spv/src/network/costs.rs:266
A check of the code could not confirm it.
Rare trigger, so not listed · 1 warning
- Unverified filter traffic can inflate the block estimate for every peer ·
dash-spv/src/network/costs.rs:271
Trigger 3 of 10, below the cut-off of 4.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
d510056, round 1 - 101 changed lines read in 11m 0s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 3.6M in (2.8M from cache) · 94k out · about $5.10 at API prices
- Runner: self-hosted · started after 14s · peak memory 3.5 GiB of 30.0 GiB
- How Manki reviews
The ledger test for skipped requests only checked the settled byte charges, so dropping the transfer of a skipped filter batch's bytes to the served batch broke no test. It now also checks that the served reply sizes the `CFilters` estimate exactly as it would with nothing skipped.
|
✅ Review complete in 7m 30s Planner (4s) Review (behavior · full): 6 findings Judge (4m 18s) Posted: 2 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
Create an issue for this to track it for later. The PR is also a draft, so mark it ready for review too. If no approval follows, comment /manki check.
Checked and left out: 2 findings (1 rare, 1 not finished)
Rare trigger, so not listed · 1 warning
- Unmatched filter traffic can inflate block response costs for every peer ·
dash-spv/src/network/costs.rs:271
Trigger 2 of 10, below the cut-off of 4.
Not finished checking · 1 possible problem
- A
cfilterinside one batch can settle a later batch whose stop hash it carries ·dash-spv/src/network/costs.rs:246
No check in this round settled it.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
e259c58, round 2 - 106 changed lines read in 7m 30s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 3.2M in (2.5M from cache) · 74k out · about $4.10 at API prices
- Runner: self-hosted · started after 7s · peak memory 4.4 GiB of 30.0 GiB
- How Manki reviews
The broker, network manager, mock network and blocks manager tests each built the same `getcfilters`, `getcfheaders` and block `getdata` requests in their own private helpers. They now share `get_cfilters`, `get_cfheaders` and `get_block` from `test_utils`. `get_block` takes the block hash, so callers keep their own hash source.
The ledger tests for skipped requests kept their own copies of the `getcfheaders`, `getcfilters` and block `getdata` builders. They now use the ones in `test_utils`.
The ledger test for skipped requests only paired requests of the same kind. A block reply also settles a filter batch the peer skipped before it, since peers answer filter, filter header and block requests in one order. A case now pins that.
|
✅ Review complete in 11m 23s Planner (6s) Review (behavior · full): 5 findings Judge (4m 21s) Posted: 2 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
Create an issue for this to track it for later. The PR is also a draft, so mark it ready for review too. If no approval follows, comment /manki check.
Still open from earlier reviews:
dash-spv/src/network/costs.rs:246: An intermediate compact filter can settle two requests that are still pending (view thread)
1 suggestion · not blocking
✨ A getmnlistd or getqrinfo that Dash Core drops still stays charged for the life of the connection
Suggestion, not blocking · Pre-existing · Correctness · Moderate · dash-spv/src/network/costs.rs:81
The same problem remains here. This PR fixes it at dash-spv/src/network/costs.rs:263 but not on this path.
Already broken before this PR. Two checks found the same problem on dev at dash-spv/src/network/costs.rs:71, so it doesn't block this PR.
Why: in_order covers only CfHeaders, CFilters and Block. Dash Core also skips a getmnlistd or getqrinfo without replying: when its per-peer token bucket rate-limits the request, when it cannot build the diff (for example a block it does not know yet), or when its history is pruned. Each skipped request keeps its charge on the peer's ledger with no reply to clear it: 64 KB for a getmnlistd, 1 MB for a getqrinfo. This is the leak the PR fixes for the other three kinds. Both replies meet the condition in the in_order doc: Core sends mnlistdiff and qrinfo only when asked, and it penalises a peer that sends an mnlistdiff unasked. Reply::QrInfo also carries no key. So a later qrinfo settles the first, skipped entry instead of its own, and one 1 MB charge stays on the ledger in either case.
How to fix it
Add Reply::MnListDiff(_) to in_order. Key Reply::QrInfo by the requested tip hash so a reply matches its own request, then add it to in_order too. Add a test_case for each kind to a_reply_settles_the_requests_its_peer_skipped. Caveat: this assumes the qrinfo tip diff carries block_request_hash as its block_hash, which still needs to be checked against BuildQuorumRotationInfo.
- Create an issue for this
Checked and left out: 2 findings
Disproved by a check of the code · 2 findings
- An in-order filter stream can settle two overlapping requests early ·
dash-spv/src/network/costs.rs:246
The only producer ofGetCFiltersin the crate is FiltersPipeline::send_pending, which sends back-to-back batches that never overlap. A pipeline is rebuilt only when it is idle, and it resumes after the stored filter tip, so no in-flight batch's range ever contains another batch's stop hash. - A compact-block fallback may be mistaken for a later full-block reply ·
dash-spv/src/network/costs.rs:81
dash-spv never asks a peer for a compact block. All four places that build a 'getdata' use full-block, InstantSend-lock, chain-lock or transaction items.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
1335e48, round 3 - 206 changed lines read in 11m 23s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 6.2M in (5.1M from cache) · 109k out · about $7.21 at API prices
- Runner: self-hosted · started after 13s · peak memory 4.1 GiB of 30.0 GiB
- How Manki reviews
A skipped filter batch holds the bytes of filters streamed after it. When a block or filter header reply settled that batch, those bytes were added to the reply's size sample, so filter traffic inflated the block estimate that every peer is budgeted with. They now count only toward a reply that ends a filter batch, and are dropped otherwise, since a filter batch still pending was sent after the reply and has not started streaming.
|
✅ Review complete in 7m 53s Planner (5s) Review (behavior · full): 5 findings Judge (3m 2s) Posted: 1 finding Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.
✅ Approved. 1 suggestion, which doesn't block.
- Check approval
What this does: A peer that silently skips a filter-header, filter or block request used to keep it charged against its byte budget forever. A later reply of those kinds now clears the skipped charges, so the peer gets work again and response sizes stay accurate.
📌 1 follow-up agreed for later
Agreed in their threads as later work. None of them blocks.
dash-spv/src/network/costs.rs:246: An intermediate compact filter can settle two requests that are still pending (view thread)
Related work: open PRs and issues this PR may duplicate or fix. None of them blocks.
- This PR may fix #1232 dash-spv:
Ledgercharges leak on retries without a kick and starve healthy peers. AddCloses #1232to the description if it does.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Run the dash-spv unit tests and a filter sync against peers, with peer_speed debug logging on.
- Run
cargo test -p dash-spv --lib a_reply_settles_the_requests_its_peer_skipped. Expect all four cases to pass. - Run
cargo test -p dash-spv --lib network::. Expect the broker and manager tests to pass with the sharedget_cfilters,get_cfheadersandget_blockhelpers. - Sync filters on testnet with
cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir>. Expect each peer'sin_flightin thepeer_speedlines to drop back toward zero between bursts instead of creeping up. - Watch the
resp KBarray in the bandwidth line. Expect the filter and block sizes to stay plausible and not jump after a skipped request. - Edge case: request a block that a peer does not serve, so it does not answer, then let it serve a later block. Expect that peer's in-flight bytes to drop by the skipped block's charge.
Checked and left out: 1 finding
Disproved by a check of the code · 1 finding
- A reply can clear requests the peer has not served yet ·
dash-spv/src/network/costs.rs:246
dash-spv only ever puts four kinds of item in agetdata:Inventory::Block,Transaction,InstantSendLockandChainLock. There is noCompactBlock/CmpctBlockanywhere in dash-spv/src, and none in the consumer repos dash-evo-tool or platform.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
3f84bb5, round 4 - 211 changed lines read in 7m 53s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 3.5M in (2.8M from cache) · 71k out · about $4.60 at API prices
- Runner: self-hosted · started after 12s · peak memory 3.7 GiB of 30.0 GiB
- How Manki reviews
The shared `get_cfilters` builder only asks for the filter of one block, so no test could stream a filter from inside a batch. `get_cfilter_range` takes the stop height too, and `get_cfilters` builds on it, so its callers keep their values.
The skipped-request test fed every case a filter from outside the served batch, so the filters case counted an unrelated filter toward the batch instead of showing that a filter from inside it carries over. The served filter batch now spans two blocks and its first filter streams before the stop filter. The block case keeps a filter that ends no batch, which must not change the block estimate.
|
✅ Review complete in 14m 29s Planner (7s) Review (behavior · full): 4 findings Judge (10m 30s) Posted: 0 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
Last reviewed
|
There was a problem hiding this comment.
Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.
✅ Approved.
- Check approval
What this does: A peer that silently ignored a filter or block request kept it counted as owed, which shrank how much work the client sent that peer. Now, when a later filter or block reply arrives, every earlier request the peer skipped is released.
📌 1 follow-up agreed for later
Agreed in their threads as later work. None of them blocks.
dash-spv/src/network/costs.rs:246: An intermediate compact filter can settle two requests that are still pending (view thread)
Related work: open PRs and issues this PR may duplicate or fix. None of them blocks.
- This PR may fix #1232 dash-spv:
Ledgercharges leak on retries without a kick and starve healthy peers. AddCloses #1232to the description if it does.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: A dash-spv checkout with the test-utils feature, and optionally a testnet data directory for a manual sync.
- Run
cargo test -p dash-spv --lib a_reply_settles_the_requests_its_peer_skipped. Expect all four cases to pass. - Run
cargo test -p dash-spv --lib network::. Expect the broker, manager and costs tests to pass with the shared helpers. - Run
cargo test -p dash-spv --lib sync::blocks. Expect the block manager tests that useget_blockto pass. - Sync testnet with
cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir>andRUST_LOG=peer_speed=debug. Expectin_flightper peer to fall back toward zero between bursts instead of creeping up. - Run the same sync with blocks requested from a peer that cannot serve them. Expect that peer's
in_flightto drop once it sends a later block or filter reply. - Run
just dash-spv::test. Expect the dashd integration tests to complete syncs and reconnects as before.
Checked and left out: 2 findings (1 disproved, 1 not finished)
Disproved by a check of the code · 1 finding
- A block sent in place of a compact block may retire unrelated requests ·
dash-spv/src/network/costs.rs:264
Nothing in dash-spv builds a compact-block inventory item. Every getdata it sends uses only Block, Transaction, InstantSendLock or ChainLock items, so the fallback 'block' never arrives and the drain at line 264 is never reached that way.
Not finished checking · 1 possible problem
- Silently dropped masternode list requests can still leave permanent charges ·
dash-spv/src/network/costs.rs:81
Dash Core’s only MNLISTDIFF producer sends the reply directly from the request handler and sends nothing when the required history is unavailable.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
66e7693, round 5 - 219 changed lines read in 14m 29s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 3.3M in (2.5M from cache) · 74k out · about $4.69 at API prices
- Runner: self-hosted · started after 14s · peak memory 4.0 GiB of 30.0 GiB
- How Manki reviews
|
/self-reviewed |
|
Bots are done — your move: post |
|
Policy satisfied — this can merge. |
…run 46954746748)
Dash Core sends nothing for a
getcfheadersorgetcfilterswhose range its filter index lacks, nor for a block it does not have. The byte charge of such a request stayed on the peer's ledger for the life of the connection, so the router saw less room at that peer than it had. A skippedgetcfilterswas worse: every latercfilteradded its bytes to the skipped batch, no later batch of that peer ever settled, and its charges piled up until the peer looked full.Peers answer in request order, so a filter header, filter or block reply now settles the charge of every earlier request of those kinds the peer still owes, and a
cfiltersettles the batch whose stop hash it carries. The bytes a skipped batch collected count toward the batch that was actually served.Split out of #1374, which keeps the retry of a refused request at another peer.
PR Hygiene ·
66e7693When every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.