Skip to content

fix(dash-spv): retry a refused request at another peer - #1374

Open
xdustinface wants to merge 12 commits into
devfrom
fix/retry-refused-requests
Open

xdustinface wants to merge 12 commits into
devfrom
fix/retry-refused-requests

Conversation

@xdustinface

@xdustinface xdustinface commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Dash Core sends nothing for a getcfheaders or getcfilters whose range its filter index lacks, nor for a block it does not have. The broker put such a request back in the queue with nothing that kept it from the peer that refused it, so the router could send it straight back there. A skipped request also never expired at a busy peer, since every answer from that peer counted as progress on it. A testnet run sent three filter header batches to such peers 45 to 47 times each over 9 minutes.

Peers answer in request order, and since #1563 the connection's ledger settles the requests a reply proves skipped. Ledger::settle now also returns their keys, unless the peer still owes a later copy of the same request. The peer reader passes them to the broker, which retries them at once, like a block the peer sent notfound for.

A skipped request, a block not found and a request that expired after its kicking attempts are not routed or hedged to that peer's address for REFUSAL_HELD. While every peer with room refuses a request, the router sends the rest of the queue and keeps that request without waking itself, and the hedger still hedges overdue blocks. The refusal lapses, so a node whose index was only catching up, or a lone configured peer, is asked again.

PR Hygiene · c3a7d97

  • Bots — coderabbitai 1 thread unresolved — resolve it
  • Self-review — address ZocoLini requested changes, then post /self-reviewed
  • Build green
  • 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.

Summary by CodeRabbit

  • Bug Fixes
    • Improved request handling when peers skip requests, report data as unavailable, or disconnect. Requests can remain queued for other eligible peers or be retried without treating a lost connection as a refusal.
    • Reduced repeated requests to peers that recently declined or lacked the requested data, with refusals expiring after a short period.
    • Improved routing so requests that cannot currently be served do not block later eligible requests or use up routing capacity.
    • Improved block and filter request hedging when queued work is temporarily unavailable to connected peers.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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 32 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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 224c4390-d195-40da-85c8-e55816152f15
Commits

Reviewing files that changed from the base of the PR and between ed38985 and c3a7d97.

Files selected for processing: 2

  • dash-spv/src/network/broker.rs
  • dash-spv/src/network/costs.rs

No actionable comments were generated in the recent review.

Walkthrough

The broker now tracks recent peer-address refusals alongside retry attempts. The ledger reports skipped request keys, and the peer and manager pass skipped or not-found requests to the broker. Routing and hedging account for recent refusals.

Changes: Request retry and refusal routing

Layer / File(s) Summary
Report skipped request keys
dash-spv/src/network/costs.rs
Ledger::settle returns keys for requests skipped by an in-order reply, except when a later copy of the same reply is still owed. Tests cover reported and repeated block requests.
Forward skipped and not-found requests
dash-spv/src/network/peer.rs, dash-spv/src/network/manager.rs, dash-spv/src/network/broker.rs
The peer reader emits skipped request keys. The manager sends skipped and not-found keys to the broker as refusals.
Track refusal and retry state
dash-spv/src/network/broker.rs
The broker preserves retry state across requeues and records refusals for non-lost requeues. Refusals are associated with peer addresses and expire after 10 seconds.
Route and hedge around refusals
dash-spv/src/network/broker.rs, dash-spv/src/network/manager.rs
Routing and hedging avoid recent refusers. Requests refused by every available peer stay queued without consuming routing budget. The manager checks whether queued work is routable before attempting a block hedge. Tests cover refusal, retry, and failed-write cases.

Estimated code review effort: 4 (Complex) | ~35 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Ledger
  participant PeerReader
  participant Manager
  participant Broker
  PeerReader->>Ledger: settle(reply)
  Ledger-->>PeerReader: skipped RequestKeys
  PeerReader->>Manager: PeerEvent::Skipped
  Manager->>Broker: refused(peer, keys)
  Broker->>Broker: requeue with Refused reason
Loading

Possibly related issues

  • dashpay/rust-dashcore#1233 — The PR routes refused requests away from the refusing peer, but does not add the issue’s attempt limit or withdraw(RequestKey) API.
  • dashpay/rust-dashcore#1230 — The PR reports skipped requests and retries them, but does not add per-request deadlines.
  • dashpay/rust-dashcore#1515 — The PR records requests on-wire before sending and handles failed-write attempt rollback, which relates to the race described in the issue.
  • dashpay/rust-dashcore#1573 — The PR preserves retry history and tracks peer-address refusals across requeues, related to the issue’s request-copy tracking objective.

Possibly related PRs

  • dashpay/rust-dashcore#902 — It introduced request keys and centralized requeueing, which this PR extends with retry and refusal handling.
  • dashpay/rust-dashcore#1343 — It changes settlement and hedge behavior; this PR also changes skipped-request reporting and hedge eligibility.
  • dashpay/rust-dashcore#1387 — It changes broker requeue and route behavior, which this PR also modifies for refused requests.

Suggested reviewers: romchornyi

Merge Risk: Low · previous review ed389

This change stops refused SPV requests from being resent repeatedly to the same peer and keeps refused requests away from that peer for a short hold. One narrow gap remains: when a peer refuses a hedge copy, other peers are not offered a hedge until the primary request expires. This only delays hedging and is already tracked as follow-up work, so the PR is mergeable.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a refused request is retried at another peer. The changeset adds refusal tracking in the broker, a settlement path that reports skipped requests, and rerouting of refu…
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.
Full details: Title check

Explanation

The title names the main change: a refused request is retried at another peer. The changeset adds refusal tracking in the broker, a settlement path that reports skipped requests, and rerouting of refused blocks and filter batches to other peers. The title is specific and matches the PR objective of keeping refused requests away from the peer that refused them. The title uses the fix() prefix, which is a conventional commit style and is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c796c286-4586-4772-bf2c-d481d27e2bc7
Commits

Reviewing files that changed from the base of the PR and between d915da9 and ed38985.

Files selected for processing: 1

  • dash-spv/src/network/broker.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.

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.54902% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.21%. Comparing base (9329b3e) to head (c3a7d97).
⚠️ Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
dash-spv/src/network/broker.rs 97.23% 8 Missing ⚠️
dash-spv/src/network/costs.rs 96.42% 1 Missing ⚠️
dash-spv/src/network/peer.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1374      +/-   ##
==========================================
+ Coverage   88.16%   88.21%   +0.04%     
==========================================
  Files         270      270              
  Lines       72623    73003     +380     
==========================================
+ Hits        64031    64397     +366     
- Misses       8592     8606      +14     
Flag Coverage Δ
core 83.85% <ø> (-0.02%) ⬇️
rpc 83.85% <ø> (-0.02%) ⬇️
spv 95.48% <97.54%> (+0.03%) ⬆️
wallet 83.85% <ø> (-0.02%) ⬇️
Files with missing lines Coverage Δ
dash-spv/src/network/manager.rs 97.65% <100.00%> (+0.10%) ⬆️
dash-spv/src/network/costs.rs 97.13% <96.42%> (-0.17%) ⬇️
dash-spv/src/network/peer.rs 93.47% <80.00%> (-0.82%) ⬇️
dash-spv/src/network/broker.rs 99.09% <97.23%> (-0.20%) ⬇️

... and 8 files with indirect coverage changes

@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/retry-refused-requests branch from b58028c to 983e28b Compare November 10, 2026 06:26
@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/retry-refused-requests branch from 983e28b to 467c455 Compare November 10, 2026 14:27
@xdustinface
xdustinface force-pushed the fix/retry-refused-requests branch from 467c455 to 2bda02a Compare November 11, 2026 01:21
@xdustinface
xdustinface force-pushed the fix/retry-refused-requests branch from 2bda02a to 3ff2dc4 Compare December 1, 2026 12:31
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

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.

@xdustinface
xdustinface changed the base branch from fix/peer-exploration to dev December 1, 2026 12:32
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 23m 6s

Planner (5s)
    feat · 250 lines · 2 agents
    judge effort: high

Review (behavior · full): 18 findings
    ✅ Claude Opus 5.5 · high: 2 findings (2m 59s)
    ✅ GPT 6.2 Sol · high: 10 findings (5m 28s)
    ✅ Related checks, claim checks, pattern checks and fix checks: 17 of 17 done, 5 findings (2m 17s)
    ✅ Second reads: 1 of 1 done, 1 finding (2m 56s)

Judge (12m 52s)
    graded 18 findings: 12 kept · 2 dropped · 4 merged
    dropped, as the finders filed them: 2 blockers
    refuter: 4 checked · 2 confirmed · 1 disproved · 1 unsettled
    origin checks: 5 checked · 1 older than this PR
    verdict reader: read the diff (1m 57s)

Posted: 5 findings
    2 warnings · 3 suggestions
    not posted: 1 older than this PR · 4 over the review.notes limit · 1 no realistic trigger · 1 no proof

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 10% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 10% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Kept: "A reply to an older copy held by the same peer is taken as proof that the peer skipped later requests" (warning): "warning. hedge_to (broker.rs:138) records only the hedge peer's id and no send order. requeue drops hedges when it destructures OnWire (broker.rs:235-241). A carrier kicked through requeue_from (manager.rs:1313) or expired by expire (broker.rs:386) puts the request back in the queue. route can then pick the hedge peer P and gives the request a new, higher order (broker.rs:470). P answers in receive order, so it answers the old hedge copy first. arrived then takes the o.peer == peer branch and marks every request on P with a lower order as skipped (broker.rs:292-296). That includes requests P simply has not reached yet. They are requeued with P refused (broker.rs:319). The result is duplicate downloads and P kept away from them for REFUSAL_HELD. The data still arrives, so this is a cost, not a wrong result.
    Refutation confirmed: A hedge copy gets no order (broker.rs:138). requeue drops hedges (broker.rs:235-241). route then gives the resend a fresh, higher order, even when the peer it picks already holds the hedge copy (broker.rs:470, 480-490). When that peer answers the old hedge copy, arrived takes the o.peer == peer branch and marks every on-wire request with a lower order as skipped (broker.rs:292-296). That includes requests sent after the hedge that the peer has simply not reached yet. They are req... Rule checked: A peer answers its requests in the order it receives them, so its reply to a copy sent earlier says nothing about requests sent to it after that copy. Yet arrived compares only against the order of the request's current copy, and that copy was resent later.
  • Premise "This trigger happens in realistic use: When a slow peer holding a hedged block or filter batch is kicked or its request expires, and the router resends that request to the peer that already holds the hedge copy" confirmed. The timeout monitor kicks a silent carrier and requeues its requests with the hedge list dropped. route excludes only peers that refused the request, so it can pick the hedge peer, and with few peers it is the only choice. Because filter hedges go to a peer even at its cap, that peer can still hold the old copy when the resend reaches it.
    Pair refutation confirmed: The hedge records only the peer ID, and requeueing drops that record. Once the resend has a fresh order, an old reply from that peer takes the carrier branch and makes intervening requests look skipped; the queued-reply safeguard no longer applies. Rule checked: A reply identified only by peer and request key cannot prove that the peer reached the latest send of that key if the same connection still holds an older copy.
  • Premise "This trigger happens in realistic use: When a slow peer holding a hedged block or filter batch is kicked or its request expires, and the router resends that request to the peer that already holds the hedge copy" confirmed. The production hedger can send a copy before the timeout monitor removes the carrier, and the router can then resend to the remaining hedge peer because it checks room and refusals, not prior hedge ownership."
  • Kept: "Dash Core never sends notfound for a block, so the block notfound refusal path is never triggered" (suggestion): "note. The cited Core code confirms the claim. ProcessGetData stops its notfound loop at the first block item (dashpay/dash:src/net_processing.cpp:3034-3035), and ProcessGetBlockData returns without a reply for a missing block (net_processing.cpp:2863, 2891). The PR description's claim and the Refusal::NotFound case therefore describe a reply Core never sends. The code itself does no harm: it still handles other node implementations. This only misleads readers."
  • Dropped: "Retried requests leave byte charges on peers that never answered" (ignore): "ignore. The leaked charge lives in the peer ledger (costs.rs:219-257), which this PR does not change. Before this PR, a skipped request stayed OnWire at the same peer and was never settled there either. The base requeue for expired requests released no ledger charge. Moving the broker state to Queued changes nothing about that peer's ledger, so this PR neither causes nor worsens the leak.
    Refutation disproved: The charge is real: it is added at send (peer.rs:346) and released only when that peer answers (peer.rs:780, costs.rs:219-262). But no broker code touches the ledger, on the base branch or the head. A skipped request was already left charged on the base branch, and the head only moves the broker entry to Queued. This PR does not cause the leak, and I did not measure how much routing capacity it actually costs. Rule checked: A peer's byte charge in Ledger is released only by Ledger::settle when that same peer sends a matching reply or notfound, so anything the broker does with its own request state leaves that peer's charge where it is.
  • Premise "On the base branch a skipped or expired request also stays charged in its peer's PeerLedger, since costs.rs settle is not changed by this PR and nothing in the base requeue released ledger charges" confirmed. Ledger::charge, settle and release are the same at base and head (costs.rs:205-268), and only peer.rs calls them, at send and on receive. The base requeue only swapped OnWire for Queued(o.attempts) and pushed the message back to the front of the queue. On the base branch a skipped request stayed OnWire at the same peer, and nothing ever settled it in that peer's ledger, so its charge stayed exactly as it does on the head.
    Pair refutation unsettled: The head requeues skipped and silently expired requests without releasing the original peer's charge. The same charge already persisted on the base branch, so this confirms the defect but not a PR regression. Rule checked: Changing a request's broker state does not release a charge held in a separate per-connection ledger.
  • Premise "On the base branch a skipped or expired request also stays charged in its peer's PeerLedger, since costs.rs settle is not changed by this PR and nothing in the base requeue released ledger charges" confirmed. Base arrival leaves the earlier skipped request on wire, and base silent expiry only requeues it; neither path releases its charge, and the unchanged ledger still requires a matching response to settle it."
  • Kept: "Refused requests can use up the routing budget without sending anything" (warning): "warning. pop_guaranteed charges every popped message's cost against budget (broker.rs:820-836) before refusers is computed from the popped messages (broker.rs:417-430). Refused messages go back to the front through restore with no wake (broker.rs:464), so each later pass pops them first again. When their cost fills the budget, nothing else leaves the queue. route returns 0 and the router waits for a wake or STALL_CHECK (manager.rs:453), until the refusal lapses after 10 s. Every result is still right, but sync stalls in a way users would notice.
    Refutation confirmed: The code works as the finding says: refused messages are popped first, fill the budget, are put back with no wake, and the router waits. But the full stall needs the refused messages to cost at least the peer's whole cap. Below that, the peer only gets a shallower pipeline as replies drain. Either way, every refusal ends after REFUSAL_HELD (10 s), and a bounded delay counts as unsettled under the rules, not as a confirmed failure. Rule checked: pop_guaranteed charges every popped message against the shared byte budget before route works out which peers refused it, so refused messages put back at the front of the queue use up the same budget again on every pass.
  • Premise "This trigger happens in realistic use: When the requests every open peer refused cost as much as the remaining byte budget, such as a few refused blocks or filter batches on a single peer" confirmed. On the code side, the trigger is reachable. Passing --peer clears the default peers and connects only the configured ones, so with one --peer the peer that refused is every open peer. Refusals come from outside input: a peer's notfound, a reply that skips earlier filter, filter-header or block requests, or a request left unanswered after KICKING_ATTEMPTS (2) tries. DRAIN_PRIORITY pops up to 4 guaranteed CFilters before CfHeaders and Headers. The starting cost estimate per filter batch is 256 KiB...
    Pair refutation confirmed: The broker spends the byte budget before checking refusals and only skips within the entries it already popped. It then restores the refused entries at their original heights, so the next pass can hit the same limit. Rule checked: When a bounded queue scan charges entries before checking whether they can be sent, ineligible entries can exhaust the scan budget and hide eligible work.
  • Premise "This trigger happens in realistic use: When the requests every open peer refused cost as much as the remaining byte budget, such as a few refused blocks or filter batches on a single peer" confirmed. A supported single-peer setup can reach this budget state through ordinary queued sync work and a NotFound response for two outstanding blocks; the response frees their in-flight bytes but puts both blocks back at the front as refused."
  • Not listed, over the review.notes limit: "Expired refusal records accumulate for as long as a request is pending" (suggestion): "note. refuse keeps expired entries for other addresses (broker.rs:108), so the list grows by at most one entry per send attempt that refused the request. Attempts are paced by timeouts and the 10 s hold, so each list stays a handful of small entries per request. Nobody would notice the memory or scan cost. Dropping lapsed entries in refuse is still tidier."
  • Not listed, a check of the code could not confirm it: "Retrying one block in a multi-block request can resend and reassign its siblings" (warning): "warning if multi-block getdata is used. route gives every key of one message the same order (broker.rs:470), so a reply to one sibling cannot reveal a skipped earlier sibling. The e.order < o.order test at broker.rs:296 excludes it. requeue pushes the whole message once per selected key (broker.rs:246), so several detected skips queue duplicate copies. A resend then also replaces the carrier of siblings still on the wire (broker.rs:475-480). The code shown has only single-block test messages, and it is unclear whether any caller in the repository sends a multi-block getdata. That decides whether this happens in practice.
    Refutation unsettled: The only route a sync manager has for asking for blocks is BlockRequest, which always builds a getdata for one block. Repo-wide, the only other enqueue call is a test wrapper that passes on messages from those managers. The public enqueue trait method still accepts any message, and I could not fetch dash-evo-tool to see whether a consumer sends a multi-block getdata. Rule checked: A reply can only reveal skipped siblings, and duplicate requeues can only happen, when several block keys share one message and so one order. Only a multi-block getdata going through enqueue produces that.
  • Premise "A sync manager in dash-spv enqueues a NetworkMessage::GetData holding more than one block inventory" unsettled. Every block getdata a sync manager enqueues comes from BlockRequest::into_message, which holds one Inventory::Block. The other GetData built in sync code goes out with send_to, which skips the broker, and asks for transactions, chainlocks or InstantSend locks, not blocks.
  • Premise "This trigger happens in realistic use: When a sync manager enqueues a getdata for several blocks and the peer skips one of them" unsettled. No sync manager enqueues a getdata for several blocks, so normal use never creates sibling keys that share one order. Each block request is its own message with its own order.
    Pair refutation unsettled: The broker gives every block in a batch the same order, so a reply for one cannot expose an earlier skipped sibling. When a retry selects just one block, the broker queues the original message and replaces the carrier of any sibling that is still on the wire. Rule checked: When a message carries several independently tracked requests, retrying one key must not resend or reassign the other keys.
  • Premise "A sync manager in dash-spv enqueues a NetworkMessage::GetData holding more than one block inventory" unsettled. The block sync pipeline sends one BlockRequest per wanted hash, and each converts to a GetData with exactly one block entry.
  • Premise "This trigger happens in realistic use: When a sync manager enqueues a getdata for several blocks and the peer skips one of them" unsettled. Dash Core can silently skip a block entry, but the stated sync-manager sequence never starts because the sync pipeline does not put multiple blocks in one request."
  • Not listed, on code this PR did not change: "A peer can answer before the broker records the send order" (warning): "warning with no realistic trigger. route registers sends only after its send loop (broker.rs:466-468). A reply that lands in that window sees Queued and settles with no skip check (broker.rs:304). That needs a peer round trip shorter than one routing pass. The next reply from that peer still detects the skip, since every registered later request has a higher order. The notfound part of the window was already there before this PR, and Core sends no block notfound."
  • Kept: "Refusals are tracked for the original copy but not for hedge copies" (suggestion): "note. A reply from a hedge peer skips the skip check (broker.rs:303), and hedge copies carry no order (broker.rs:138). A hedge peer that silently dropped its copy therefore stays eligible when the carrier later refuses. Once that request is resent there, it has an order, so that peer's next reply flags it. The cost is about one extra round trip. The block notfound part does not apply: Core sends no notfound for blocks (net_processing.cpp:3034-3035), and project memory records that not_found keeps its dev behaviour on this point."
  • Dropped: "An unvalidated reply can mark unrelated requests as refused" (ignore): "ignore. The skip set and the refusals it records apply only to requests carried by the replying peer and only against that peer's own address (broker.rs:296, 243). A peer that sends a bogus reply can at most get its own outstanding requests sent to other peers. It could do the same by not answering, so it gains nothing. The point about a reply to an older copy is Finding 1."
  • Not listed, it names no trigger that happens in realistic use: "A reply can settle a retry before its message reaches the queue" (warning): "warning with no realistic trigger. requeue publishes Queued under the lock (broker.rs:245) and pushes the message after dropping it (broker.rs:253). An arrival or release in between leaves a message that route sends once more. The window lasts only between the lock release and one queue insert, far shorter than any network reply. The base requeue had the same ordering. The cost is one duplicate request."
  • Not listed, over the review.notes limit: "The refusal regression test does not exercise the filter hedge guard" (suggestion): "note. The new test uses only block keys and calls hedge (broker.rs:1193, 1236). The existing hedge_filters tests predate refusals. Removing !o.retry.refused_by(p.addr()) at broker.rs:571 would fail no test. That part of the fix has no regression test, as AGENTS.md requires."
  • Kept: "The REFUSAL_HELD comment says a catching-up node refuses only briefly, but Dash Core can refuse for its whole index build" (suggestion): "note. Core advertises NODE_COMPACT_FILTERS once -peerblockfilters is set, with no check that the index is synced (dashpay/dash:src/init.cpp:1282). It drops filter requests while LookupFilterRange fails (net_processing.cpp:3552). A node building its index can refuse for far longer than 10 s, so the comment misstates why the hold is short. The code still works."
  • Not listed, over the review.notes limit: "Retry::refused keeps peer addresses in a Vec of pairs, not a map keyed by SocketAddr" (suggestion): "note. swapped_out and Bans store timed per-address records in HashMap<SocketAddr, _>. A map would give refuse its one-entry-per-address rule without the manual retain and push (broker.rs:108-109). Behaviour is correct as written."
  • Not listed, over the review.notes limit: "The arrived doc comment grows to eight lines, over the repository's three-line ceiling" (suggestion): "note. The PR adds a second paragraph (broker.rs:286-288), so the arrived doc comment now runs eight lines. The root AGENTS.md sets three lines as the ceiling. The added point already appears on settles_on_arrival."

Timing:

  • Parse: 8.1s
  • Review agents: 605.7s
  • Judge: 771.8s
  • Total: 1385.7s

@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.

⚠️ 2 warnings to address. Fix each one, reply in its thread with a reason Manki accepts, or tick 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.


4 suggestions are not listed.


Checked and left out: 1 finding

Not proven, so not listed · 1 warning

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 3ff2dc4, round 1
  • 250 changed lines read in 23m 6s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 6.4M in (5.1M from cache) · 160k out · about $8.68 at API prices
  • Runner: self-hosted · started after 12s · peak memory 4.6 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 15m 58s

Planner (5s)
    feat · 380 lines · 2 agents
    judge effort: high

Review (behavior · full): 10 findings
    ✅ Claude Opus 5.5 · high: 1 finding (3m 30s)
    ✅ GPT 6.2 Sol · high: 7 findings (4m 30s)
    ✅ Related checks, claim checks, pattern checks and fix checks: 18 of 18 done, 2 findings (2m 5s)
    ✅ Second reads: 1 of 1 done (1m 46s)

Judge (7m 47s)
    graded 10 findings: 8 kept · 1 dropped · 1 merged
    dropped, as the finders filed them: 1 blocker
    refuter: 4 checked · 2 confirmed · 1 disproved · 1 unsettled
    origin checks: 4 checked · 1 older than this PR
    verdict reader: read the diff (1m 43s)

Posted: 5 findings
    1 warning · 4 suggestions
    not posted: 1 over the review.notes limit · 1 no realistic trigger · 1 disproved by a check of the code

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 21% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 12% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Not listed, over the review.notes limit: "New doc comments go past the repository's three-line ceiling" (suggestion): "note. The root AGENTS.md sets three lines as the most a comment may have. That applies to dash-spv too. The added test doc at broker.rs:1199-1202 is four lines. The added paragraph at broker.rs:294-296 brings the arrived doc to nine lines. Nothing breaks when the code runs, so this is the style row."
  • Kept: "A request that never completes retains every send and old refusal" (suggestion): "note. sent_to gains one PeerId per send (broker.rs:145, broker.rs:501). refused keeps one entry per address (broker.rs:110-111). A refusal holds a peer off for REFUSAL_HELD (10 s), so even a request refused forever grows by a few small entries a minute. The peer set is small, and the history goes away when the key is released. Nobody would notice the memory or the scan in copies_at."
  • Dropped: "Moving a skipped request leaves its byte charge on the old peer" (ignore): "ignore. The stale charge comes from ResponseCosts::settle (costs.rs:232-255). The ledger is kept per connection and does not depend on broker state. This PR changes only broker.rs. Before this PR, a skipped request stayed on the wire at that peer, and its awaited entry stayed charged in the same way. Moving the request in the broker neither adds nor keeps the charge. The defect sits in code this PR does not touch and does not cause.
    Refutation unsettled: The stale charge is real: settle is the only code that frees bytes. A skipped filter batch stays first among the CFilters entries, so the mismatch check at costs.rs:238 returns early for every later batch and their charges stay held too. The cause is not in this PR: settle is the same on base and head, and nothing in the network module releases a charge when the broker requeues a request. Rule checked: In a per-connection cost ledger, a charge is released only when a matching reply settles it. A reply the peer never sends leaves its charge counted for as long as the connection lives, whatever the broker does with the request.
  • Premise "On the base branch dev, ResponseCosts::settle in dash-spv/src/network/costs.rs already leaves the charge of a request its peer skipped on that peer's ledger, and this PR does not change costs.rs" confirmed. ResponseCosts::settle and release read the same on base and head. The only charge releases are at costs.rs:226 and costs.rs:255, both inside settle, and no code under dash-spv/src/network clears or retains awaited anywhere else. So on base a skipped request, whether it stayed on the wire or was requeued by expiry, kept its charge in the same way.
    Pair refutation unsettled: The new skip handler requeues the request without touching the old connection’s ledger. When a later filter batch arrives, the ledger still checks its filters against the skipped batch’s stop hash and returns without releasing either charge. Rule checked: Requeuing a broker request does not clear a separate per-connection byte charge; the ledger releases that charge only when it matches a reply.
  • Premise "On the base branch dev, ResponseCosts::settle in dash-spv/src/network/costs.rs already leaves the charge of a request its peer skipped on that peer's ledger, and this PR does not change costs.rs" confirmed. The base and head copies of costs.rs are identical: Ledger::settle already left the skipped charge in place on a stop-hash mismatch before the PR added the broker’s skip-and-requeue path."
  • Kept: "The skip check can blame a peer for a request it still owes" (warning): "warning. release removes the registration and its sent_to history (broker.rs:198). A new enqueue starts from Retry::default() (broker.rs:187). So copies_at(peer) == 1 at broker.rs:300 holds for the new copy even when the same connection still owes the old one. When the old reply lands, every settle-on-arrival request sent to that peer between the two copies is taken as skipped (broker.rs:304). Those requests are requeued with a 10 s refusal (broker.rs:329), so they are downloaded twice and the peer is avoided for nothing. The overlapping-range part does not hold: memory records that batch boundaries are fixed. Whether the rescan re-requests the same stop hash on the same connection is left as a doubt.
    Refutation confirmed: reset_for_rescan releases the CFilters keys still on the wire (filters/manager.rs:261). That removes their registrations, sent_to included (broker.rs:198). start_download then calls send_pending straight away and re-enqueues the same stop hashes with a fresh Retry (manager.rs:454-456, pipeline.rs:152-158, broker.rs:187). The router can send the new copy to the same connection, and copies_at(peer) == 1 then holds (broker.rs:501). When the old reply's last cfilter lands (network/ma... Rule checked: A peer answers requests in the order it got them, so a reply that matches a newer registration is taken as proof that the peer skipped every earlier request it still holds. That inference is only valid if the reply answers the new copy, but release deletes the send history that would show an older copy is still pending.
  • Premise "After reset_for_rescan releases an in-flight CFilters key (filters/manager.rs:261), the filters manager enqueues the same stop hash again while the old reply from the first connection can still arrive, and the router can send the new copy to that same connection" confirmed. reset_for_rescan releases the wanted stop hashes. tick immediately calls start_download, which calls send_pending with batches from the stored tip + 1 (the last one ends at the same tip), so the same stop hashes are enqueued as fresh registrations. The router only avoids peers in the empty refused list, so it can pick the same connection.
  • Premise "This trigger happens in realistic use: When a wallet rescan releases filter batches still in flight and the same batch is requested again from the same peer before the old reply lands" confirmed. The rescan is triggered by a wallet added behind the scan progress during sync. The re-requests go out in the same tick, and the old replies are whole filter batches still in flight, so the window is the length of a batch download, not a narrow race.
    Pair refutation confirmed: A rescan can rewind the wallet's scan without moving the download frontier, so it can release and immediately redeclare the same unfinished filter batch. Release drops the old send history, and the first send of the new registration makes a late reply for the old one look like proof that the peer skipped intervening requests. Rule checked: A reply matched only by block hash cannot distinguish an earlier send from a later registration of the same hash on the same connection.
  • Premise "After reset_for_rescan releases an in-flight CFilters key (filters/manager.rs:261), the filters manager enqueues the same stop hash again while the old reply from the first connection can still arrive, and the router can send the new copy to that same connection" confirmed. Reset unregisters the wanted stop hash without cancelling the sent request or closing the connection, and restarting from the same stored-filter frontier redeclares that hash with no restriction against using the same connection.
  • Premise "This trigger happens in realistic use: When a wallet rescan releases filter batches still in flight and the same batch is requested again from the same peer before the old reply lands" confirmed. The wallet-behind test exercises a rescan with an outstanding filter request, and the production tick restarts immediately without waiting for the old reply; the router allows seconds of work in flight, so the sequence does not require a narrow timing window.", trigger 4 and harm 4 of 10: "It needs a released-and-re-enqueued key with a stale reply still in flight on the same connection, or overlapping getcfilters ranges such as during a rescan reset, which is realistic but uncommon."
  • Kept: "An unanswered request still has no deadline while its peer returns other traffic" (warning): "warning. The PR's stated goal is that a skipped request no longer lives forever at a busy peer. Skip detection runs only on a cfheaders, cfilter or block reply from the carrier (manager.rs:1375-1384, broker.rs:300). A headers reply still calls progress (manager.rs:1392-1400). That refreshes last_progress and last_answer for every request on the connection (broker.rs:351-353). Expiry measures both thresholds from those timestamps (broker.rs:373, broker.rs:377). So the skipped batch stays on that peer for as long as headers keep flowing. A reply to a hedge copy also detects no skip (broker.rs:311). Filter header sync waits on that batch until header sync goes quiet.
    Refutation confirmed: The mechanism holds: a CFHeaders batch the peer skipped gets no skip detection and no hedge copy, and the peer's Headers replies keep it alive. But it is not held forever. Once that peer sends no headers for REQUEST_TIMEOUT (10s), which happens once initial header sync ends, expire re-queues it, so the effect is a bounded delay that heals itself. Rule checked: A request expires only when its peer's last progress or answer is older than the timeout, and any headers reply from that peer resets those timestamps for every request it holds.
  • Premise "During header sync, a peer whose filter index lacks a range is sent a GetCFHeaders for it and keeps receiving getheaders from the client, with no later cfheaders, cfilter or block reply from it" confirmed. In the code, filter-header requests go out on each BlockHeadersStored event, so during header sync, and header requests can go to the same peer. dashd drops a getcfheaders it cannot serve without replying, and only blocks and cfilters get hedge copies. Whether a peer's index actually lags is runtime behaviour.
  • Premise "This trigger happens in realistic use: When a peer with a lagging filter index skips a getcfheaders batch while it still serves getheaders during initial sync" confirmed. On the code side, dashd advertises NODE_COMPACT_FILTERS whenever -peerblockfilters is set, with no check that the index has caught up, and drops a getcfheaders for a range its index lacks without replying, while header sync keeps sending getheaders to the peer that answers soonest.
    Pair refutation confirmed: Headers and Headers2 refresh both clocks on the outstanding filter-header batch without running skip detection. Neither expiry check uses the batch's send time, and the hedge paths do not cover filter-header batches. Rule checked: A request has no independent deadline when every qualifying reply from its peer resets both timeout clocks, even if the reply is for a different request.
  • Premise "During header sync, a peer whose filter index lacks a range is sent a GetCFHeaders for it and keeps receiving getheaders from the client, with no later cfheaders, cfilter or block reply from it" confirmed. The router can send both request types to the same eligible peer, and the header pipeline keeps refilling without waiting for any filter-header, filter, or block reply.
  • Premise "This trigger happens in realistic use: When a peer with a lagging filter index skips a getcfheaders batch while it still serves getheaders during initial sync" confirmed. Initial sync requests ranges from stored block headers without checking the serving peer's filter-index height, and Dash Core's missing-range branch returns without replying or closing the connection."
  • Dropped: "A block reply cannot expose a skipped block in the same inventory list" (ignore): "warning. Every key of one message gets the same order (broker.rs:491). The skip test needs e.order < o.order (broker.rs:304). Dash Core serves one block per call, in inventory order, and returns silently when it lacks the data (net_processing.cpp:3124-3135, 2887). So a reply for item 2 proves item 1 was skipped, yet item 1 stays on the refusing peer until expiry. That is the stall this PR sets out to remove. Requeuing the whole message per key (broker.rs:253) predates this PR. Whether a manager sends multi-block getdata is not in the code shown.
    Refutation disproved: Every block getdata that reaches the broker is built from one hash. BlockRequest::into_message and the blocks manager both wrap a single Inventory::Block, which gives each block request its own send order. The getdata messages that hold several items carry only transactions, InstantSend locks or ChainLocks. They go out through send_to, which writes straight to the peer and never passes through the broker. No code in the repository and no code in dashpay/platform enqueues a getdata wi... Rule checked: The broker gives every key of one message the same send order (broker.rs:491) and treats only strictly lower orders as skipped (broker.rs:304), so a skip inside one getdata goes unnoticed only if a single enqueued getdata holds two or more block items.
  • Premise "A sync manager enqueues a GetData message that carries more than one block inventory item" unsettled. The only code that enqueues a getdata is BlockRequest through SendRequest::send, and it always holds exactly one Inventory::Block. The other getdata messages (mempool transactions, InstantSend locks, ChainLocks) use send_to, which skips the broker. Only a broker unit test enqueues a two-block getdata.
  • Premise "This trigger happens in realistic use: When a multi-block getdata goes to a peer that lacks the first block but serves a later one" disproved. Normal use never sends a multi-block getdata through the broker. Each block is its own message with its own order, so a reply to a later block has a strictly higher order, and the e.order < o.order check catches a skipped earlier block.
    Pair refutation disproved: The broker gives every block in a GetData message the same order, so a reply for the second block does not trigger a retry of the first. A broker test enqueues a two-block list, but the sync pipeline sends one block per message, and no checked caller or test sends a multi-block list and receives only the later block. Rule checked: A strict sequence-number comparison cannot distinguish the order of two inventory entries assigned the same number.
  • Premise "A sync manager enqueues a GetData message that carries more than one block inventory item" disproved. The block sync pipeline sends a separate BlockRequest for each wanted hash, and each BlockRequest becomes a GetData with exactly one inventory entry.
  • Premise "This trigger happens in realistic use: When a multi-block getdata goes to a peer that lacks the first block but serves a later one" unsettled. Dash Core's code consumes a missing block entry without replying and can serve the next entry, but the two-block broker test only exercises release from the queue and does not establish that sequence in real use."
  • Not listed, it names no trigger that happens in realistic use: "The router can resend a request before seeing its new refusal" (warning): "warning. The race is real. refusers is built under the requests lock (broker.rs:422-437). The queue is popped later (broker.rs:449). A requeue that lands in between (broker.rs:250, broker.rs:260) puts back a message whose refusal the snapshot lacks. The cost is one repeated send to the refusing peer, and the next skip detection catches it again. The window is a few in-memory await points, far shorter than the network operations around it. The trigger is not realistic."
  • Kept: "A stale timeout or skip can record a refusal for a newer send" (suggestion): "warning. expire collects keys under one lock and requeues them under another, matching on the key alone (broker.rs:392, broker.rs:396). arrived drops its lock before it requeues (broker.rs:322, broker.rs:329). For a refusal to land on the wrong send, the request would have to be settled, released, enqueued again and routed in that gap. The gap is a lock release and reacquire inside one function, far shorter than any of those steps. The cost would be one 10 s refusal and one duplicate send. The trigger is not realistic."
  • Kept: "Retry.refused uses a Vec of address and time pairs where the other per-address timed records use a HashMap" (suggestion): "note. refuse keeps one entry per address by hand, with retain and then push (broker.rs:110-111). swapped_out (manager.rs:796) and Bans::entries (bans.rs:29) use a HashMap keyed by address. The code works today. A map would put the one-entry rule in the type and match the existing pattern."

Timing:

  • Parse: 11.0s
  • Review agents: 479.7s
  • Judge: 467.2s
  • Total: 957.8s

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

CI does not run on this PR while it is a draft. Someone with write access can start it here:

  • Run CI once on the current commit
  • Run CI on every push, starting now

Marking the PR ready for review also starts CI.

@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. The PR is also a draft, so mark it ready for review too. If no approval follows, comment /manki check.


2 suggestions · not blocking
✨ A stale timeout or skip can record a refusal for a newer send
Suggestion, not blocking · Concurrency · Moderate · dash-spv/src/network/broker.rs:396

Why: Expiry selects keys under one lock and applies the refusal under another, without checking the selected send. If the request is settled, released and sent again before the timeout applies, the new carrier inherits a ten-second refusal for an attempt it did not miss. The arrival path has the same gap when a newer send of the key uses the same connection.

}
if !unanswerable.is_empty() {
self.requeue(|k, _| unanswerable.contains(k), true).await;
}
culprits

How to fix it
Apply each refusal while holding the lock used to identify the affected send, or carry the exact send identity through to requeue and only update a matching attempt.

Checked in the code
On the flagged line: Applies the timeout with |k, _| unanswerable.contains(k), without checking the carrier or send order

Saves only key.clone() in unanswerable

);
unanswerable.insert(key.clone());
}
}
if !unanswerable.is_empty() {

Drops the arrival lock before line 329 checks only o.peer == peer && skipped.contains(k)

reqs.insert(key, ReqState::Arrived);
drop(reqs);
if !skipped.is_empty() {
tracing::debug!(
target: "dash_spv::network",

Applies retry.refuse(peer.addr()) to whichever on-wire attempt is selected under the second lock

if refused {
retry.refuse(peer.addr());
}
reqs.insert(key, ReqState::Queued(retry));
Some((height, msg))

  • Create an issue for this
✨ An unanswered request still has no deadline while its peer returns other traffic
Suggestion, not blocking · Pre-existing · Reliability · Moderate · dash-spv/src/network/broker.rs:300

Tracked in #1230.

The same problem remains here. This PR fixes it at dash-spv/src/network/broker.rs:329 but not on this path.

Already broken before this PR. Two checks found the same problem on dev at dash-spv/src/network/broker.rs:245, so it doesn't block this PR.

Why: A peer that silently skips a filter header batch but keeps returning headers can prevent the batch from ever being retried, including after its filter index catches up. Only a matched, uniquely sent carrier reply triggers skip detection. Header replies, hedge replies, and replies that arrive before the routing pass records their send do not trigger it, even though the pump counts them as progress for the unanswered request.

How to fix it
Base expiry on progress the peer can attribute to the specific send, with a deadline that allows for queued bytes and a large reply. Record sends in wire order before a reply can race their registration, and use unambiguous later replies as early retry signals rather than as the only way to detect a skip on a busy connection.

  • Create an issue for this

1 more suggestion is not listed.


Checked and left out: 1 finding

Disproved by a check of the code · 1 finding

  • A block reply cannot expose a skipped block in the same inventory list · dash-spv/src/network/broker.rs:491
    Every block getdata that reaches the broker is built from one hash. BlockRequest::into_message and the blocks manager both wrap a single Inventory::Block, which gives each block request its own send order.

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 1d3d8de, round 2
  • 380 changed lines read in 15m 58s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 5.8M in (4.4M from cache) · 147k out · about $8.42 at API prices
  • Runner: self-hosted · started after 14s · peak memory 4.7 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 12m 28s

Planner (5s)
    feat · 475 lines · 2 agents
    judge effort: high

Review (behavior · full): 9 findings
    ✅ Claude Opus 5.5 · high: 3 findings (2m 38s)
    ✅ GPT 6.2 Sol · high: 6 findings (3m 31s)
    ✅ Comparisons, related checks, claim checks, pattern checks and fix checks: 20 of 20 done (2m 10s)

Judge (7m 6s)
    graded 9 findings: 6 kept · 1 dropped · 2 merged
    dropped, as the finders filed them: 1 warning
    refuter: 2 checked · 1 confirmed · 1 disproved
    origin checks: 3 checked · 1 older than this PR
    verdict reader: read the diff (2m 7s)

Posted: 4 findings
    4 suggestions
    not posted: 1 no realistic trigger · 1 no proof

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 24% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 12% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Not listed, it names no trigger that happens in realistic use: "A copy that route sends while its key is already settled or released is never recorded as owed" (warning): "warning, with no realistic trigger. route pops, sends, then registers. If the key was released in between, reqs.get_mut at broker.rs:537 finds nothing. If it arrived in between, broker.rs:542 skips it. Either way the copy goes into neither sent_to nor owed. A later re-declare sent to the same peer then sees copies_at(peer) == 1 at broker.rs:327, and the old reply wrongly requeues and refuses the requests sent in between. This is the same mistake as P2 on another path. The failure needs a release inside the short window between a socket write and registration, followed by a re-declare routed to the same peer before the old reply. That window is much shorter than the operations around it, so the trigger is not realistic. The cost is one extra download and a 10 s refusal."
  • Kept: "owed keeps entries for copies that will never get a reply until the peer disconnects" (suggestion): "note. Entries leave owed only on a reply (forget_copy), on disconnect (broker.rs:295), on a re-declare (broker.rs:193) or on clear. A skipped or notfound copy keeps its entry while the connection lives. The _ arm at broker.rs:342 also forgets only from owed, never from a registered key's sent_to. The memory is a few small entries per connection. An overcount only turns skip detection off for one reply. That errs on the safe side: no false refusal, and a later reply still detects the skip. Nobody would notice the cost."
  • Kept: "New doc comments go over the three-line ceiling" (suggestion): "note. AGENTS.md sets three lines as the ceiling for a comment. The new doc on a_refused_request_is_retried_at_another_peer at broker.rs:1250-1253 has four lines, all added by this PR. The paragraph added to arrived is three lines, but it extends an existing five-line doc. This is formatting only."
  • Dropped: "Recognizing a skipped request leaves its byte charge on the peer" (ignore): "ignore. The stuck charge and the wrong cfilter matching both live in the ledger at costs.rs:232-238, and this PR does not change that file. The broker never settled a skipped batch's charge before this PR either. The PR description says the skipped batch stays a stall at a busy peer, which matches this. Requeuing at broker.rs:373 moves the request but neither adds nor removes a ledger charge. The release of those charges sits in another file, outside this change."
  • Kept: "Skip detection ignores replies to hedges and earlier copies in the same inventory" (suggestion): "warning. Skip inference runs only when the reply settles the peer's own primary copy (broker.rs:327), and it compares only primary orders (broker.rs:331). A reply to a hedge copy takes the arm at broker.rs:338 and infers nothing, although it proves the same skip. All blocks of one getdata share one order (broker.rs:535), so a skipped earlier block in the same inventory is never detected either. The skipped request then stays with that peer until it is overdue and hedged, which is the delay this PR sets out to remove. The inventory case depends on multi-block getdata being sent.
    Refutation confirmed: The hedge gap exists in the code. A reply from a peer to a hedge copy takes the arm at broker.rs:338 and infers no skip, because the skip check at 327-331 runs only for the peer's own primary copy. The cost is only a delay, though: the skipped request is caught the next time that peer answers a later primary, since every later primary has a higher order (535). Failing that, it is retried through the existing overdue/hedge path, so a later pass heals it. The multi-block inventory part of the find... Rule checked: A peer answers requests in the order it received them, so any reply sent after an earlier request it carries shows it skipped that request, whether the reply answers a primary copy or a hedge copy.
  • Premise "This trigger happens in realistic use: when a peer skips a filter batch or block it carries and then answers only a hedge copy it was sent of a later request" confirmed. On the code side, hedge_filters and hedge send a later request's copy to any answering peer other than its carrier. That includes a peer already carrying earlier primaries, even at its byte cap for the lowest batch. hedge_to records only the peer ID, and a reply to that copy goes through the arm at line 338 with no skip check. Whether a real peer skips a request is peer behaviour that no code here can show.
    Pair refutation confirmed: A hedge reply settles its key without checking for skips, and the strict order comparison cannot distinguish two blocks in the same inventory. The built-in block requester sends one block per inventory, so the second gap applies only to batched input. Rule checked: For a peer that processes requests in order, a reply to an unambiguous copy can reveal a skipped earlier request only if the broker tracks both copies’ positions in that peer’s queue.
  • Premise "This trigger happens in realistic use: when a peer skips a filter batch or block it carries and then answers only a hedge copy it was sent of a later request" confirmed. On the client side, the running filter hedger can send the later copy to a peer that still carries the earlier primary, and the inbound pump accepts the hedge reply without requiring an answer to the earlier request."
  • Not listed, a check of the code could not confirm it: "Retrying one block can resend or hold the whole inventory" (warning): "warning if multi-block getdata is sent. requeue returns the whole stored message once per selected key (broker.rs:270). Skip detection selects every key of an earlier message together, since they share one order. A multi-block inventory is therefore queued again once per block, and blocks that already arrived are downloaded again. The new refuses gate at broker.rs:485 uses .any over all keys of the message. A refusal of one block therefore keeps the whole inventory from that peer, so blocks it would serve also wait.
    Refutation disproved: The only production path that queues a block getdata is BlockRequest, which always builds a single-block inventory. The blocks pipeline sends one BlockRequest per block, and no other sync code calls enqueue with a block getdata. Every message that reaches broker.rs:270 and :485 therefore has one key, so nothing is queued twice and no other block's request is held back. Rule checked: A retry or refusal that covers a whole multi-key message only misbehaves if some caller actually queues a message holding more than one block key.
  • Premise "A sync manager enqueues a GetData that holds more than one Inventory::Block" unsettled. Sync managers queue blocks only as BlockRequest, whose message is GetData(vec![Inventory::Block(hash)]) with exactly one block. The other getdata builders (mempool, InstantSend, ChainLock) ask for non-block items through send_to, which bypasses the broker.
  • Premise "This trigger happens in realistic use: when a peer skips or sends notfound for blocks of a multi-block getdata" disproved. No multi-block getdata ever reaches the broker in normal use, so a peer skipping or sending notfound can only affect a single-block request, and the whole-message retry and refusal match exactly that one key.
    Pair refutation unsettled: The broker queues the original inventory once per selected on-wire key without removing blocks that already arrived. The refusal gate checks the same unsplit inventory, so a refusal for one key excludes that peer for the entire message. Rule checked: Retrying individual keys with an unchanged batch resends every item in that batch, and an any check rejects the batch if even one key fails the check.
  • Premise "A sync manager enqueues a GetData that holds more than one Inventory::Block" unsettled. The block sync pipeline sends a separate BlockRequest for each wanted hash, and each request converts to a one-block GetData.
  • Premise "This trigger happens in realistic use: when a peer skips or sends notfound for blocks of a multi-block getdata" confirmed. On the code side, an inbound notfound retries the listed on-wire block keys, and a later reply retries earlier outstanding keys from the same peer, including multiple keys from one earlier inventory."
  • Kept: "Redeclaring a key can move a dead copy past disconnect cleanup" (suggestion): "note. requeue_from drops the requests lock after its loop (broker.rs:284-293) and only then locks owed (broker.rs:295). An enqueue in between can move a departed connection's copy into a new Retry (broker.rs:193). That copy names a PeerId that never replies again, and a reconnect gets a new id. The only effect is one stale vector entry, and nobody would notice it."

Timing:

  • Parse: 12.3s
  • Review agents: 309.5s
  • Judge: 426.2s
  • Total: 748.0s

@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.

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. 4 suggestions, none of which block.

  • Check approval

What this does: The request broker remembers which peer addresses refused a request: skipped it, let a retry expire, or sent notfound. It avoids them for 10 seconds when routing or hedging.


1 suggestion · not blocking
✨ Skip detection ignores replies to hedges and earlier copies in the same inventory
Suggestion, not blocking · Pre-existing · Correctness · Moderate · dash-spv/src/network/broker.rs:327

The same problem remains here. This PR fixes it at dash-spv/src/network/broker.rs:373 but not on this path.

Already broken before this PR. Two checks found the same problem on dev at dash-spv/src/network/broker.rs:242, so it doesn't block this PR.

Why: The broker checks for skipped work only when the reply settles a current primary copy, and it checks only earlier primary copies. A peer that skipped a primary request and then answers a later hedge provides the same ordering evidence, but the primary stays on that peer. The same gap affects a skipped earlier block in one getdata inventory: all its blocks get the same order, although Dash Core serves them in inventory order.

How to fix it
Store a position for each sent copy, including hedges and individual inventory entries. Use a reply that unambiguously identifies a copy to retire earlier skipped copies on that connection. Requeue a skipped primary, but remove just the hedge when the primary still has a live carrier.

  • Create an issue for this

What to test

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

Setup: Run the SPV client against regtest with two or more peers, for example with just dash-spv::test, and enable debug logs for dash_spv::network.

  1. Sync blocks and filters with two peers. Expect sync to complete with no skipped ... retrying elsewhere loops in the log.
  2. Use a peer that has no filter index next to one that has it. Expect filter batches to move to the serving peer after the first skip, not to stall.
  3. Stop one peer from answering during block download. Expect the requests at that peer to be retried at the other peer. Expect no hedge copy to go to a reconnection from the same address within 10 seconds.
  4. Run with a single peer that skips one request. Expect that request to be sent to the same peer again after about 10 seconds, and other queued requests to keep going out meanwhile.
  5. Edge case: make every peer refuse the last pending block, then wait past 10 seconds with no other traffic. Expect the block to be requested again rather than sync hanging.
  6. Edge case: disconnect a peer that holds a hedge copy, then reconnect it. Expect the request to stay with its carrier and to be hedged again to another peer.

Checked and left out: 1 finding

Not proven, so not listed · 1 warning

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed c304a72, round 3
  • 475 changed lines read in 12m 28s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 5.0M in (3.9M from cache) · 116k out · about $6.88 at API prices
  • Runner: self-hosted · started after 16s · peak memory 4.8 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 11m 56s

Planner (3s)
    feat · 536 lines · 2 agents
    judge effort: high

Review (behavior · full): 6 findings
    ✅ Claude Opus 5.5 · high: 1 finding (3m 37s)
    ✅ GPT 6.2 Sol · high: 5 findings (2m 49s)
    ✅ Comparisons, related checks, claim checks, pattern checks and fix checks: 21 of 21 done (1m 33s)

Judge (7m 39s)
    graded 6 findings: 5 kept · 0 dropped · 1 merged
    refuter: 2 checked · 1 disproved · 1 unsettled
    origin checks: 4 checked · 1 older than this PR
    verdict reader: read the diff (2m 34s)

Posted: 1 finding
    1 suggestion
    not posted: 1 older than this PR · 1 no realistic trigger · 2 no proof

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 31% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 13% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Kept: "owed keeps an entry for every answered getheaders and getmnlistd until the peer disconnects" (suggestion): "note. route pushes the peer into sent_to for every key at broker.rs:556, including Headers and MnListDiff. release then moves that list into owed at broker.rs:229-230. The pump calls arrived only for Block, CFilter and CFHeaders (manager.rs:1375-1386), so these entries leave owed only on disconnect or clear. copies_at and the skip scan only matter for settles_on_arrival keys, so the stale entries change no routing decision. The cost is roughly one small entry per header batch or diff per connection, which nobody would notice."
  • Not listed, a check of the code could not confirm it: "Skipping a request can leave the peer unable to take its retry" (warning): "warning. The requeue at broker.rs:384 moves a skipped request off a live peer without touching that peer's ledger. In costs.rs:232-239, settle matches every incoming cfilter against the first awaited CFilters entry, which is now the skipped batch, and returns without settling. So the skipped batch's charge stays, and so does the charge of every later batch at that peer. The cap fills, route computes a budget of 0 at broker.rs:464-470, and the retry the PR describes for a lone peer after REFUSAL_HELD never goes out. The PR description says fix(dash-spv): settle the requests a peer skipped #1563 releases these charges, but no code in this PR shows that, so it is listed as a doubt. The grade is capped at warning because test 1 fails for part of it: the charge that clogs the peer comes from settle in costs.rs, which this PR does not change. The added lines only fail to work around it.
    Refutation unsettled: The only places that free a charge are costs.rs:226 for a notfound item and costs.rs:255-256 for a matched reply. When arrived requeues a skipped request, nothing touches the ledger. After a skipped CFilters batch, each later batch's filters are credited to the skipped batch's entry and return at costs.rs:238, so neither charge is freed. The charges pile up until route finds no room at that peer. Rule checked: A peer's byte ledger frees a charge only when settle matches a reply or a notfound item, and for cfilter it always credits the first awaited CFilters entry. So a batch the peer silently skips stays first in the ledger and blocks every later batch at that peer from settling.
  • Premise "No code in this PR's head releases a peer's ledger charge for a request that arrived or not_found puts back in the queue as refused" disproved. As a blanket claim it is false: a block that not_found requeues has its charge freed, because the same NotFound message reaches ledger.settle at peer.rs:780 and costs.rs:222-228 removes and releases the matching Block entry. The other half does hold: nothing releases the charge of a request that arrived requeues as skipped, since costs.rs:226 and costs.rs:256 are the only release sites.
    Pair refutation unsettled: When a peer skips a filter batch and finishes a later one, the ledger rejects the later stop hash before the broker sees it. The broker then requeues the skipped request without clearing either charge. A block explicitly reported in notfound is different: its charge is released before requeueing. Rule checked: Requeuing a broker request does not free its connection-level byte charge, and a filter reply can settle only the oldest outstanding filter batch.
  • Premise "No code in this PR's head releases a peer's ledger charge for a request that arrived or not_found puts back in the queue as refused" disproved. For a block named in notfound, the reader settles the message and releases the matching charge before the pump requeues the block as refused."
  • Not listed, on code this PR did not change: "Replies received during routing lose their skip evidence" (warning): "note. The window is real: route stages sends in on_wire at broker.rs:533 and publishes OnWire only after the send loop, at broker.rs:542-568. A reply that lands in between finds the request Queued, and arrived skips the scan at broker.rs:348. However, the reply must come back from the network before the local loop finishes writing a few small requests. The next reply from that peer to a registered request still proves the skip. Block notfound is not sent by Dash Core. No realistic sequence leaves a skip undetected, so the trigger is left empty."
  • Not listed, it names no trigger that happens in realistic use: "Copy history cannot tell which send a refusal retired" (warning): "note. sent_to is a plain Vec<PeerId> (broker.rs:114) and forget_copy removes one entry by connection (broker.rs:721). Consider an expired copy the peer actually skipped. It stays after the peer answers a later copy, and copies_at(peer) == 1 at broker.rs:332 then suppresses skip detection if the key is declared again to the same peer. Seeing this needs an expiry, a skip and a re-declare at the same connection. A block notfound for an older copy needs a non-Core node. Neither is a realistic trigger, and the conservative outcome only delays a retry until expiry."
  • Not listed, a check of the code could not confirm it: "Batched block requests hide skips and resend whole inventories" (warning): "warning. Every key of one message gets the same order at broker.rs:546. The skip scan requires e.order < o.order at broker.rs:336, so a reply to the second block of a getdata never proves that the first was skipped. When skips are detected later, requeue emits the full original message once per skipped key at broker.rs:278, so already-delivered blocks go out again, once per skipped key. The comment at broker.rs:545 expects multi-item inventories. Whether any manager actually sends one is not shown, so it is listed as a doubt.
    Refutation disproved: Every production enqueue goes through SendRequest::send. The only block request type, BlockRequest, builds a getdata with exactly one Inventory::Block, and the block pipeline is its only sender. Other getdata senders (mempool, chainlock, islock) carry no blocks and use send_to, not the broker queue, so the multi-key case never arises outside the broker's own tests. Rule checked: The broker can only mis-order or over-resend items of one getdata when a single enqueued message carries more than one Inventory::Block; a one-item message has one key, so a shared order and a full-message resend are both exact.
  • Premise "A sync manager enqueues a getdata that carries more than one Inventory::Block" disproved. No sync manager enqueues a multi-block getdata. BlockRequest wraps a single block hash, the block pipeline is its only sender, and the only production call to enqueue is SendRequest::send; multi-block getdata appears only in broker tests.
  • Premise "This trigger happens in realistic use: when a peer lacks the first block of a multi-block getdata and serves the next one" unsettled. The sequence needs a getdata whose first block a peer skips while it serves a later one, and no production caller sends a getdata with more than one block, so the case cannot arise.
    Pair refutation unsettled: The broker cannot detect a skip within one batch, and a later reply that exposes skipped keys queues a full inventory for each skipped key without deduplication. The broker tests enqueue multi-block inventories to check release behavior, but the sync manager sends one block per message, so those tests do not establish the reported failure in normal sync. Rule checked: A strict send-order comparison cannot distinguish items with the same order, and a retry that queues the original message resends its entire inventory.
  • Premise "A sync manager enqueues a getdata that carries more than one Inventory::Block" unsettled. Even when several blocks are pending, the sync pipeline sends a separate BlockRequest for each hash, and each request becomes a one-item getdata.
  • Premise "This trigger happens in realistic use: when a peer lacks the first block of a multi-block getdata and serves the next one" confirmed. On the code side, given such a batch, Dash Core silently consumes a block item whose data is missing and can send the next available block, whose reply the broker processes without retrying the equal-order item."

Timing:

  • Parse: 5.5s
  • Review agents: 251.3s
  • Judge: 459.0s
  • Total: 715.7s

@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.

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 skips a request, sends notfound or lets it expire is no longer asked for it again right away. The request goes to another peer, and that peer is avoided for 10 seconds.


What to test

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

Setup: Build dash-spv with the cli feature and sync testnet or regtest with debug logging for dash_spv::network, ideally with two or more peers.

  1. Run cargo test -p dash-spv --lib network::broker. Expect all broker tests to pass, including the new refusal and skip tests.
  2. Sync blocks with several peers and watch for skipped ... retrying elsewhere in the log. Expect the skipped block to go out to a different peer address.
  3. Use a peer that answers a block request with notfound. Expect the block to be retried at another peer, not the same address.
  4. During the block endgame, let the carrier of the lowest block stall. Expect the hedge copy never to go to an address that refused that block in the last 10 seconds.
  5. Disconnect a peer mid-sync and let it reconnect at the same address. Expect its requests to be re-queued and the new connection to be eligible for them at once.
  6. Edge case: connect a single peer and make it skip or expire a block. Expect the block to go out again to that peer about 10 seconds later, even with no other traffic.
  7. Edge case: re-declare a block key after releasing it while an old copy is still outstanding. Expect no false skip detection when the peer answers the old copy.

Checked and left out: 2 findings

Not proven, so not listed · 2 warnings

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 2e28168, round 4
  • 536 changed lines read in 11m 56s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 5.2M in (4.1M from cache) · 126k out · about $7.42 at API prices
  • Runner: self-hosted · started after 8s · peak memory 5.9 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/broker.rs Resolved
@manki-review

manki-review Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

✅ Review complete in 10m 45s

Planner (5s)
    feat · 554 lines · 2 agents
    judge effort: high

Review (behavior · full): 7 findings
    ✅ Claude Opus 5.5 · high: 0 findings (2m 26s)
    ✅ GPT 6.2 Sol · high: 7 findings (4m 10s)
    ✅ Comparisons, related checks, claim checks, pattern checks and fix checks: 20 of 20 done (2m 0s)

Judge (5m 32s)
    graded 7 findings: 4 kept · 3 dropped
    dropped, as the finders filed them: 3 blockers
    refuter: 3 checked · 1 confirmed · 1 disproved · 1 unsettled
    origin checks: 3 checked
    verdict reader: read the diff (1m 46s)

Posted: 1 finding
    1 warning
    not posted: 2 no realistic trigger · 1 disproved by a check of the code

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 33% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 13% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Dropped: "Skipped requests can leave a responsive peer stuck at its byte cap" (ignore): "ignore. The byte charge lives in the peer ledger in costs.rs, which this PR does not change. costs.rs:232 and costs.rs:238 pick the first awaited CFilters entry and never settle it on a later stop hash, independently of the broker. forget_copy at broker.rs:276 only edits the broker's own copy list and never touched the ledger before or after this PR. So a skipped batch's charge stuck at its peer predates this change, and the PR neither causes it nor makes it worse. The test near broker.rs:1350 only shows the PR routing around that existing state.
    Refutation disproved: The ledger code does keep a skipped CFilters batch's charge: line 232 picks the first awaited CFilters entry and line 238 returns unless the stop hash matches, so later batches never settle behind it. That code is identical at base and head, and whether a peer skips a batch in real use depends on how remote peers behave, which no code here shows. Rule checked: A peer's routing room is its cap minus its ledger's in_flight_bytes, and only Ledger::settle or a notfound releases a charge, so a charge that is never settled stays counted against the peer.

  • Premise "On the base branch, PeerLedger::settle in dash-spv/src/network/costs.rs already leaves the charge of a skipped request in in_flight_bytes and blocks later CFilters settles behind it, and this PR does not change costs.rs" confirmed. At base, Ledger::settle matches the first awaited CFilters entry and releases it only when the arriving filter's hash equals that entry's stop hash, so a skipped batch's charge stays and blocks later batches. The head copy of costs.rs reads the same in settle, charge and Reply::awaited, and the PR shows no change to costs.rs.
    Pair refutation unsettled: The broker requeues the skipped batch without releasing its charge, and the ledger returns before releasing the later batch's charge when its stop hash does not match the oldest batch. The ledger behavior itself is unchanged from the base. Rule checked: Removing a request from broker bookkeeping does not release its separate ledger charge, and a compact-filter reply can settle only the oldest outstanding compact-filter batch.

  • Premise "On the base branch, PeerLedger::settle in dash-spv/src/network/costs.rs already leaves the charge of a skipped request in in_flight_bytes and blocks later CFilters settles behind it, and this PR does not change costs.rs" confirmed. Base and head have identical costs.rs contents: a compact-filter reply with a different stop hash returns before releasing the oldest charge and never checks later batches."

  • Not listed, it names no trigger that happens in realistic use: "A filter inside an overlapping range falsely proves that the peer skipped the earlier request" (warning): "warning, pending the doubt. manager.rs:1378 maps every incoming cfilter to RequestKey::CFilters(filter.block_hash). arrived at broker.rs:333-343 treats a reply to a later request's stop hash as proof that every earlier filter batch at that peer was skipped. If a later batch's stop lies inside an earlier batch's range, the earlier batch's own reply settles the later key and requeues the earlier batch as refused. That batch is then downloaded twice and its peer is barred for REFUSAL_HELD. Results stay correct, so this is the degraded row. Project memory says batch boundaries are fixed, which would make overlapping ranges impossible from the in-repo filter manager, but the code shown does not prove that, so it is listed as a doubt."

  • Dropped: "Refusals for older copies leave retry history growing even after the ledger releases the bytes" (ignore): "ignore. Each part fails on the code or on the maintainers' record.

  • One copy per skip: each skip removes the copy of that attempt at broker.rs:276. A later attempt to the same peer pushes a new copy that its own skip removes, so copies do not pile up.

  • Expired copies: project memory records that expired copies are kept on purpose.

  • Header and masternode-list keys: their sent_to lives only while the key is registered and is now dropped on release at broker.rs:230.

  • notfound from a non-carrier: this needs a block notfound from a peer that no longer carries the request. Project memory records that Dash Core never sends that. The only effect would be a missed skip proof that falls back to expiry."

  • Dropped: "Refusing one block retries the entire inventory and loses ordering within it" (ignore): "warning, if multi-block getdata is used.

  • Shared order: broker.rs:547 gives every key of one message the same order, and the skip test at broker.rs:337 needs e.order < o.order. A served later block in the same getdata therefore never proves an earlier one was skipped, and that block waits for expiry instead.

  • Duplicate resends: when a later message does prove the skips, requeue at broker.rs:279 pushes the whole msg once per skipped key. The same inventory then goes out several times.

  • Hedges: hedge checks the refusal of only the lowest block at broker.rs:602 and then sends the full inventory at broker.rs:157.

Every result stays correct, but blocks are downloaded twice and a skipped block stalls, so this is the degraded row. Whether any caller batches blocks is not shown and is listed as a doubt.
Refutation disproved: Every block request that goes through the broker is a BlockRequest, and into_message builds a GetData with exactly one Inventory::Block. The blocks pipeline declares each wanted block as its own request, and the router never merges queued messages. So a message never holds several block keys that could share an order, be requeued as one inventory several times, or be hedged as a multi-block inventory. Rule checked: Requests that share one order value, and a whole-message resend repeated once per key, only matter when a single broker-tracked GetData carries more than one Inventory::Block.

  • Premise "A sync manager in the repository enqueues a GetData that carries more than one Inventory::Block" unsettled. The only place production code puts blocks on the broker is BlockRequest, which carries one Inventory::Block. Other GetData messages (mempool, InstantSend, ChainLock) go out through send_to, which writes straight to the peer and skips the broker.

  • Premise "This trigger happens in realistic use: when a multi-block getdata holds an earlier block the peer lacks and a later block it serves" unsettled. No broker-tracked getdata holds more than one block, so in normal use no message can contain both an earlier block the peer lacks and a later block it serves.
    Pair refutation unsettled: The broker does share one order and retain the full inventory for retries and hedges. The sync pipeline sends one block per message, and the multi-block broker test checks queue release without routing the batch, so the reported stall and duplicate downloads are not established in normal use. Rule checked: A strict send-order comparison cannot detect skips between inventory entries that share one order, and retrying the original message resends every entry it contains.

  • Premise "A sync manager in the repository enqueues a GetData that carries more than one Inventory::Block" unsettled. The block sync manager delegates to a pipeline that sends a separate BlockRequest for each wanted hash, and each request becomes a one-entry GetData.

  • Premise "This trigger happens in realistic use: when a multi-block getdata holds an earlier block the peer lacks and a later block it serves" unsettled. Dash Core can silently skip a block whose data is unavailable and serve the next entry, but the sync path does not send those entries in one inventory and the multi-block test does not exercise replies."

  • Not listed, it names no trigger that happens in realistic use: "The router can resend a request using a refusal snapshot taken before it was requeued" (warning): "warning cell, but no realistic trigger. route builds refusers under the requests lock at broker.rs:478-493, releases the lock, and then pops the queue at broker.rs:503-511. A requeue that inserts Queued at broker.rs:278 and pushes at broker.rs:286 entirely inside that gap is not in the snapshot, so it can go straight back to the refusing address. The window is only the few instructions between the lock release and the pop, far shorter than the surrounding operations. The cost is one more refused attempt, which skip detection catches again. Trigger left empty for that reason."

  • Kept: "A reply can reach the broker before the router records the send used to prove skips" (warning): "warning.

  • Late recording: route awaits each write at broker.rs:530 but records sends only after all of them, at broker.rs:543-557. Until then the request is still Queued.

  • Lost skip proof: a reply that arrives during the pass hits the Queued arm in arrived, which settles it with no skip proof. The router then skips the Arrived slot at broker.rs:554 without recording order or the copy in sent_to.

  • False skip proof: a lost copy record can make copies_at(peer) == 1 wrongly true later, so a reply to an older copy then proves false skips.

The effects are a skipped request left to expiry, or a needless requeue and repeated download. Results stay correct, so this is the degraded row. A write can wait on a slow peer up to WRITE_TIMEOUT, so the trigger is realistic.
Refutation confirmed: The code has the race. route awaits each write in turn, each up to the 5 s write timeout, and records the sends only after the whole pass (broker.rs:530-557). The separate pump task calls arrived meanwhile, and a request still Queued settles there with an empty skip set (broker.rs:349). The router then skips the Arrived slot without recording order or the copy (broker.rs:554). Whether a reply really arrives inside that window in normal use is not settled by code. Writes are small reque... Rule checked: Two tokio tasks share broker state only through a lock taken at each step. So while one task (the router) awaits a network write, the other (the inbound pump) can change any request the router has sent but not yet recorded.

  • Premise "This trigger happens in realistic use: when one routing pass writes to several peers and an early peer answers before a later write in the same pass finishes" confirmed. The code part holds. One route pass writes to the peers one by one and awaits each write, which can take up to WRITE_TIMEOUT (5 s) when the writer lock or socket is held. The PR's own test holds a second write mid-pass while the first peer already has the request (broker.rs:1748-1751). The inbound pump is a separate spawned task that calls broker.arrived with no tie to the router, so an early peer's reply is processed while the request is still Queued.
    Pair refutation confirmed: The router keeps successful sends in a local vector until the pass ends. A reply processed in that window settles the still-queued key without checking for skips, and the router then bypasses the send record because the key is already Arrived. Rule checked: An awaited write does not synchronize a separate receive task with bookkeeping deferred until after the write.
  • Premise "This trigger happens in realistic use: when one routing pass writes to several peers and an early peer answers before a later write in the same pass finishes" confirmed. The two-peer router test holds the second write after the first send, the production write has a five-second timeout, and the pump has no barrier that delays reply processing until the pass ends.", trigger 5 and harm 5 of 10: "It needs a reply to arrive while a later write in the same routing pass is still pending; writes can block for up to 5s, so this race is realistic but uncommon."
  • Dropped: "A multi-block getdata allocates a full inventory clone for every block" (ignore): "ignore. The msg: msg.clone() at broker.rs:560 is an unchanged context line in the diff. The per-key clone loop is the same on the base branch, and the reviewer says so too. This PR neither adds nor exposes it. The PR only adds a retry field beside the clone."

Timing:

  • Parse: 9.4s
  • Review agents: 304.3s
  • Judge: 331.7s
  • Total: 645.4s

@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. The PR is also a draft, so mark it ready for review too. If no approval follows, comment /manki check.


Checked and left out: 1 finding

Disproved by a check of the code · 1 finding

  • Refusing one block retries the entire inventory and loses ordering within it · dash-spv/src/network/broker.rs:547
    Every block request that goes through the broker is a BlockRequest, and into_message builds a GetData with exactly one Inventory::Block. The blocks pipeline declares each wanted block as its own request, and the router never merges queued messages.

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 8866cc5, round 5
  • 554 changed lines read in 10m 45s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 5.8M in (4.5M from cache) · 114k out · about $7.42 at API prices
  • Runner: self-hosted · started after 13s · peak memory 5.7 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/broker.rs Resolved
Dash Core sends nothing for a block it does not have, nor for a `getcfilters` or `getcfheaders` its filter index cannot serve. Such a request stayed on the wire until it expired, and then went back to the same peer.

Peers answer in request order, and the connection's ledger already settles the requests a reply proves skipped. `Ledger::settle` now also returns their keys, unless the peer still owes a later copy of the same request, which it may still answer. The peer reader passes them on just before the message that proves the skip, and the broker treats them like a `notfound`: the request is retried at once, and not at the address that skipped it.
The hedger asked a second peer for an overdue block only while the queue was empty. A request every peer with room refused stays queued until its refusals lapse, and a node still building its filter index can refuse a batch again and again, so block hedging stopped for as long as such a batch waited.

The gate now asks whether a queued message would go out to a peer with room that does not refuse it, the same check the router uses to leave a message queued.
The router recorded its sends only after the whole routing pass. A peer that answered a later request while the router was still writing to other peers proved an earlier request skipped, but that request was still queued, so the skip was dropped. The request then went on the wire at the busy peer, whose other answers kept it from expiring, and the ledger never reported it again.

Each message is now put on the wire right before its write. Its send time and overdue window are still taken at the end of the write, and its silence clock at the end of the pass. A failed write is not rolled back: it closes the connection, and the loss of the connection requeues what it carried. A message with no tracked request still goes back to the queue.
…ule only

Only the inbound pump in the network module calls it.
`Broker::refused` checked every carried request against the refused keys one by one, and `Ledger::settle` scanned the requests still owed once per skipped request. Both now build a set once. The set of requests still owed is built only when a reply proves a skip.
A request is on the wire before it is charged on the ledger of its peer. `a_refused_block_goes_to_another_peer` injected the reply as soon as the first block was on the wire, so the reply could arrive before the second block was charged, and the ledger then proved no skip. The test now waits until both blocks are charged.
@xdustinface
xdustinface force-pushed the fix/retry-refused-requests branch from 08e7f64 to d915da9 Compare December 4, 2026 13:06
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Your move: coderabbitai left review threads unresolved; resolve them.
Full checklist in the description.

manki-review[bot]
manki-review Bot previously approved these changes Dec 4, 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.

✅ Approved. No change to this PR since the reviewed commit 08e7f64. The previous verdict stands.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Your move: coderabbitai left review threads unresolved; resolve them.
Full checklist in the description.

@xdustinface

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@xdustinface
xdustinface requested a review from ZocoLini December 4, 2026 14:30
A request is put on the wire before its write, and its attempt is counted there. A write that failed still spent that attempt although the request never reached the peer. The loss of the connection requeues the request with its attempts, so the next peer that stalled on it was not blamed, as the request had already used up its `KICKING_ATTEMPTS`.

The router now takes the attempt back when the write fails, whether the request is still on the wire at that peer or the loss of its connection has already requeued it.
@manki-review

manki-review Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ Review complete in 17m 55s

Planner (6s)
    feat · 682 lines · 2 agents
    judge effort: high

Review (behavior · full): 10 findings
    ✅ Claude Opus 5.5 · high: 2 findings (6m 48s)
    ✅ GPT 6.2 Sol · high: 8 findings (3m 23s)
    ✅ Related checks, claim checks, pattern checks and fix checks: 15 of 15 done (1m 33s)
    ✅ Second reads: 1 of 1 done (1m 53s)

Judge (7m 9s)
    graded 10 findings: 9 kept · 0 dropped · 1 merged
    refuter: 3 checked · 2 confirmed · 1 disproved
    origin checks: 5 checked · 2 older than this PR
    verdict reader: read the diff (1m 39s)

Posted: 3 findings
    3 suggestions
    not posted: 1 older than this PR · 1 on code an earlier round reviewed · 1 listed by an earlier round · 1 no realistic trigger · 1 rare trigger · 1 no proof

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 42% (resets 2026-12-08 05:00 UTC)
  • ChatGPT subscription: weekly 4% (resets 2026-12-10 07:41 UTC)

Judge decisions:

  • Not listed, listed by an earlier round: "A skip or notfound from the peer holding a hedge copy is ignored, so the request is never hedged again" (warning): "warning. This keeps the earlier cell of P6. refused at dash-spv/src/network/broker.rs:276 matches only o.peer == peer, so the Skipped event the hedge peer's reader sends (dash-spv/src/network/peer.rs:783-785) does nothing. That peer stays in o.hedges. hedge returns early while o.hedges is non-empty (broker.rs:541), and hedge_filters skips the batch while that peer is still answering (broker.rs:584). The request then waits for the slow carrier to expire, which is the lagging-index case this PR targets."
  • Kept: "Refusals now count as attempts, so KICKING_ATTEMPTS no longer means two stalls" (suggestion): "note. retry.attempts += 1 at broker.rs:491 counts resends after skips, so after two refusals expire (broker.rs:348) requeues a stall at a third peer without blaming that peer. The request is still retried through the unanswerable requeue, and the judge's liveness check (manager.rs:1192-1199) still kicks a peer whose byte counter is frozen, so nothing visible goes wrong. The doc at broker.rs:329 says the attempts are stalls, which now misstates the code."
  • Not listed, a check of the code could not confirm it: "A partial refusal retries the whole inventory and overwrites unrelated in-flight requests" (warning): "warning, if multi-block inventories are enqueued. requeue returns (height, msg) with the full original message for every matched key (broker.rs:248-249). put_on_wire then replaces the live OnWire of every other key in that message, including its carrier and hedges (broker.rs:487, 494). Skips now feed this path through Skipped, so one skipped block re-downloads blocks the peer still owes. It is unclear from the code shown whether any caller enqueues more than one block per getdata. The tests use single-block messages.
    Refutation disproved: Every block request reaching the broker is a BlockRequest whose message holds exactly one Inventory::Block, and the broker sends queued messages one by one without merging them, so no getdata the broker tracks ever holds a second block to clobber or duplicate. Rule checked: A requeue that returns the whole original message for each matched key only overwrites other in-flight keys and multiplies retries when one enqueued message carries several keys.
  • Premise "a sync manager enqueues a GetData whose inventory holds more than one block" unsettled. The only sync code that enqueues block requests sends one BlockRequest per hash, whose into_message builds a single-block getdata; the multi-item getdata messages for mempool, chainlocks and InstantSend locks go through send_to, which bypasses the broker.
  • Premise "This trigger happens in realistic use: when a peer skips one block of a multi-block getdata it was sent" disproved. The broker routes each queued message unchanged and never merges single-block requests, so a peer is never sent a broker-tracked multi-block getdata it could partly skip.
    Pair refutation unsettled: The broker queues one full inventory per refused key; routing that inventory resends unrelated items and replaces their live carriers and hedges unless they have already arrived. A test supplies a two-block inventory, but it only tests release, while the skip test uses separate one-block messages, so neither establishes the combined trigger in normal use. Rule checked: When a broker tracks requests by key but retries the original message, retrying one key can resend and replace the state of other keys in that message.
  • Premise "a sync manager enqueues a GetData whose inventory holds more than one block" unsettled. The sync block pipeline sends one BlockRequest per hash, and each BlockRequest becomes a separate one-entry GetData.
  • Premise "This trigger happens in realistic use: when a peer skips one block of a multi-block getdata it was sent" confirmed. On the code path, the ledger tracks blocks in inventory order and reports an earlier unanswered key when a later block arrives, unless another copy is still owed; the reader passes that key to the broker's refusal handler."
  • Not listed, it names no trigger that happens in realistic use: "Ordinary Dash Core replies can mark a request as skipped while Core is still serving it" (warning): "ignore. Review memory records that filter batch boundaries are fixed, so batches do not overlap and a filter cannot match another batch's stop hash. The compact-block case does not occur either: of_item (costs.rs:97) does not charge a CompactBlock inventory. A full-block fallback therefore matches only a charged plain block request and settles it, and no earlier charged entry is reported as skipped.
    Refutation unsettled: Batch boundaries can move: a wallet rescan rebuilds the filter batches from a new start (and extend_target starts batches at whatever the old target was) while batches sent earlier are still in a peer's ledger, so a filter in an old range can match a new batch's stop hash. But reset_for_rescan has already removed those old keys from the broker, so broker.refused for the 'skipped' key is a no-op. The visible effect is only that the ledger settles the new batch's cost early, and I could not show t... Rule checked: Dash Core serves each getcfilters range in full and in order, so the ledger at costs.rs:261 settles the first outstanding batch whose stop hash equals the arriving filter's hash, and reports every earlier in-order entry as skipped.
  • Premise "every getcfilters the sync layer enqueues covers a fixed batch, so no filter inside one outstanding batch has the stop hash of another outstanding batch" unsettled. Batches are not fixed. extend_target starts new batches at old_target+1, which is not aligned to the 1000-block grid. On a wallet rescan, tick calls reset_for_rescan, which only releases the old stop keys from the broker and not from peer ledgers, then start_download calls init, which re-cuts 1000-block batches from download_start. A new stop hash can then fall inside an old batch that a peer is still streaming. Example: old [1000..1500] and [1501..2500], new [1000..1999], so new stop 1999 lies ...
    Pair refutation confirmed: A wallet-triggered rescan can rebuild filter ranges without clearing requests already charged to the peer ledger. When an old range streams a filter matching a new range’s stop hash, the ledger settles the new range and reports the still-streaming old range as skipped. Rule checked: An ordered reply proves an earlier request was skipped only if the reply can be attributed unambiguously to the later request.
  • Premise "every getcfilters the sync layer enqueues covers a fixed batch, so no filter inside one outstanding batch has the stop hash of another outstanding batch" disproved. Batches are disjoint within one pipeline, but a wallet rescan can replace their boundaries while the previous ranges remain charged on the same connection, letting an old range’s filter match a replacement stop hash."
  • Not listed, on code an earlier round reviewed: "A peer can force the ledger to rehash its entire backlog on each skipped reply" (suggestion): "note. The set is built only when a reply skips something (costs.rs:285-288), and each awaited entry is skipped at most once. The backlog a peer holds is bounded by its in-flight byte cap. The 20,000-entry case needs our own caller to pass a huge inventory to send_to, which is no outside input. The cost is real but nobody would notice it at realistic backlog sizes."
  • Not listed, on code this PR did not change: "A block notfound can retry a later copy the peer still owes" (warning): "warning cell without a realistic trigger. manager.rs:1380 refuses every block in the raw notfound inventory without checking the ledger, unlike the later-copy check at costs.rs:297. Reaching it needs an expired block retried at the same address only after REFUSAL_HELD lapses, then a notfound for the old copy arriving more than 10 s late. Review memory also records that Dash Core sends nothing for a block it lacks. The cost is one extra resend."
  • Not listed, its trigger is rated below review.min_warning_trigger: "A tracked write can miss the only disconnect notification and wait for expiry" (warning): "warning if the handle stays open after the reader exits. On a failed tracked write, the router only calls unsent_attempt (broker.rs:438-439, 519) and relies on the connection's loss to requeue. If the pump already ran requeue_from for that connection (manager.rs:1528) before put_on_wire registered the new attempt, no second Disconnected arrives. The request then stays on the wire at a dead connection until expire finds it. The reader sends Disconnected (peer.rs:841) without cancelling the token, but code not shown may cancel it.
    Refutation confirmed: The race can happen as the finding says: the reader's token stays uncancelled and the pump's requeue can run before put_on_wire. But the request is not lost: expire picks it up about REQUEST_TIMEOUT (10s) later and requeue_from(&culprits) sends it back to the queue. The effect is a bounded delay. Also, whether a write to a socket the peer closed actually fails depends on the operating system's TCP stack, which no code here shows. Rule checked: A request left OnWire at a connection whose only Disconnected event was already handled gets requeued only when Broker::expire times it out; expire scans every on-wire request, connected or not.
  • Premise "a PeerHandle whose reader exited on EOF still reports is_closed false when the router's snapshot uses it, because nothing cancels its token before PeerEvent::Disconnected is processed" confirmed. The token that is_closed checks is cancelled only by a failed send or by ConnectedPeer::close. The reader exits on EOF and sends Disconnected without cancelling it, and the pump's Disconnected branch removes the peer without calling close (unlike the timeout monitor at line 1321), so a snapshot handle still reports open.
  • Premise "This trigger happens in realistic use: when a peer closes its connection while a routing pass, using a snapshot taken before the close, still writes to it" confirmed. In the code, the router takes its peer snapshot once and holds it through a whole route pass, and each send in that pass can wait up to WRITE_TIMEOUT. The pump handles Disconnected concurrently, so a peer closing mid-pass leaves the router writing to the old handle. Whether that write then fails is up to the OS TCP stack, not this code.
    Pair refutation confirmed: The EOF path publishes its only disconnect event without cancelling the handle's token, and the pump removes the peer without closing it. If the router registers a request on that stale handle after the pump's requeue, a failed send cancels the token too late and only rolls back the attempt count. Rule checked: A one-time disconnect handler can only requeue requests registered when it runs; removing a peer from the live set does not invalidate previously cloned handles.
  • Premise "a PeerHandle whose reader exited on EOF still reports is_closed false when the router's snapshot uses it, because nothing cancels its token before PeerEvent::Disconnected is processed" confirmed. The EOF path and the pump's removal both leave the shared token uncancelled, so the retained handle still reports open unless a separate path has cancelled it.
  • Premise "This trigger happens in realistic use: when a peer closes its connection while a routing pass, using a snapshot taken before the close, still writes to it" confirmed. A normal routing batch retains its snapshot across writes, and the next selection checks only that the handle is uncancelled and under its cap, not that it still belongs to the live peer set.", trigger 3 and harm 4 of 10: "It needs a narrow race: the reader exits and the pump finishes requeuing that peer while the router is still writing to it from an older snapshot, which happens only occasionally during disconnects."
  • Kept: "The hedger can duplicate a request before its first write starts" (suggestion): "note. This is the round-10 finding that an unfinished write starts hedge timers, with the same code at the same spot. Its cell is kept. put_on_wire sets last_answer and sent before peer.send waits for the writer lock (broker.rs:497-498, peer.rs:346). A write held over HEDGE_AFTER can therefore be hedged. The cost is one duplicate download, which review memory records as accepted for losing copies."
  • Kept: "Two expanded test comments exceed the repository's three-line limit" (suggestion): "note. AGENTS.md sets three lines as the ceiling. The PR grows the comment at dash-spv/src/network/broker.rs:1240-1243 to four lines and the one at dash-spv/src/network/costs.rs:424-428 to five. It harms nothing at run time."

Timing:

  • Parse: 12.8s
  • Review agents: 633.0s
  • Judge: 428.8s
  • Total: 1074.6s

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Your move: coderabbitai left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Your move: coderabbitai left review threads unresolved; resolve them.
Full checklist in the description.

manki-review[bot]
manki-review Bot previously approved these changes Dec 4, 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.

✅ Approved. 3 suggestions, none of which block.

What this does: Before, a request a peer would not serve went straight back to that same peer. Now a notfound, a skip proven by an answer to a later request, or a repeated timeout sends it to another peer, and that address is not asked again for 10 seconds.


What to test

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

Setup: Run the client against a regtest network with at least two peers serving filters and blocks, with peer_speed and dash_spv::network debug logging on.

  1. Make one peer answer getdata for a block with notfound. Expect the block to be requested from the other peer and not from the refusing address for 10 seconds.
  2. Make one peer skip a block request and answer a later block first. Expect the skipped block to be re-queued and fetched from another peer.
  3. With only one peer connected, make it refuse a block. Expect the request to wait in the queue and be sent to that same peer again after about 10 seconds, with the router not spinning meanwhile.
  4. Let a block request stall at a peer past two attempts. Expect it to be retried at another peer without a kick, and no hedge copy sent to the stalling address.
  5. Block writes to a peer until the 5 s write timeout fires. Expect the connection to close and its block to go to the next peer, with the failed write not counted as an attempt.
  6. Have every connected peer refuse a filter batch while a block is overdue at a silent peer. Expect the block to still be hedged to another peer.
  7. Edge case: reconnect to an address that refused a request within the last 10 seconds. Expect the new connection to be passed over for that request until the refusal lapses.

Checked and left out: 2 findings (1 unproven, 1 rare)

Not proven, so not listed · 1 warning

  • A partial refusal retries the whole inventory and overwrites unrelated in-flight requests · dash-spv/src/network/broker.rs:249
    A check of the code could not confirm it.

Rare trigger, so not listed · 1 warning

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed ed38985, round 12
  • 682 changed lines read in 17m 55s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 8.3M in (6.7M from cache) · 158k out · about $10.59 at API prices
  • Runner: self-hosted · started after 11s · peak memory 3.9 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
Comment thread dash-spv/src/network/broker.rs Resolved
A refusal requeues a request and its next send adds an attempt, as a resend after a lost connection already did. The doc of `Broker::expire` still said the attempts were stalls.
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Your move: coderabbitai left review threads unresolved; resolve them.
Full checklist in the description.

@manki-review

manki-review Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ Review complete in 16m 24s

Planner (6s)
    feat · 697 lines · 2 agents
    judge effort: high

Review (behavior · full): 10 findings
    ✅ Claude Opus 5.5 · high: 1 finding (5m 12s)
    ✅ GPT 6.2 Sol · high: 7 findings (2m 44s)
    ✅ Related checks, claim checks, pattern checks and fix checks: 17 of 17 done, 2 findings (1m 19s)

Judge (6m 44s)
    graded 10 findings: 8 kept · 0 dropped · 2 merged
    refuter: 1 checked · 1 disproved
    origin checks: 6 checked · 1 older than this PR
    verdict reader: read the diff (1m 59s)

Posted: 3 findings
    3 suggestions
    not posted: 1 on code an earlier round reviewed · 1 listed by an earlier round · 2 no realistic trigger · 1 no proof

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 50% (resets 2026-12-08 05:00 UTC)
  • ChatGPT subscription: weekly 5% (resets 2026-12-10 07:41 UTC)

Judge decisions:

  • Not listed, listed by an earlier round: "A request skipped by the peer holding its hedge copy is dropped, so it is never hedged again and can go straight back to that peer" (warning): "warning. This matches P6 and keeps its cell, degraded in the normal column. The code shown confirms it. A hedge copy is charged to the hedge peer's ledger by send (peer.rs:349), so a skip there is reported (costs.rs:297-299, peer.rs:783-785). refused only matches o.peer == peer (broker.rs:276), so the hedge peer stays in o.hedges and its address is never refused. hedge_filters then skips the batch while that peer keeps answering (broker.rs:584), and hedge returns early once any hedge exists (broker.rs:541). The batch waits for its silent carrier to expire. That requeue refuses only the carrier's address (broker.rs:245-246), so the router can send the batch back to the peer that skipped it. Every result is still right, but sync stalls for the full expiry in the scenario this PR targets."
  • Not listed, it names no trigger that happens in realistic use: "Routing can resend a request to the peer that just refused it" (warning): "warning, with no realistic trigger. The snapshot at broker.rs:395 is taken before pop_guaranteed. A refusal recorded in between pushes the retry to the front of the queue (broker.rs:256), and the pop could hand it to the refusing peer. The window is only the time between releasing the requests lock and the pop finishing. Messages requeued after the pop are not in msgs. That window is far shorter than the operations around it. The cost is one extra round trip, since the peer skips the request again and it is refused again. This is a degraded cost without a realistic trigger."
  • Kept: "A timeout can mark a newly assigned peer as refusing" (suggestion): "warning, with no realistic trigger. This is the same defect as P2, a stale timeout recording a refusal against a newer send, so it keeps P2's cell. expire saves only keys (broker.rs:358) and requeue matches by key alone (broker.rs:362). Two things must happen between the scan's lock and requeue's lock: a refusal must requeue the key and a routing pass must put it on the wire at a new peer. That window is far shorter than the operations around it. The cost is a 10 s refusal of one address for one request."
  • Kept: "Block notfound messages bypass the check for a later outstanding copy" (suggestion): "warning, with no realistic trigger. The pump passes every notfound block key to refused (manager.rs:1380), unlike skips, which the ledger filters for a later owed copy (costs.rs:297). The failure needs the same peer to hold two copies of one block and to answer the older one with notfound. The maintainers record that Dash Core sends nothing, not notfound, for a block it lacks, so normal use does not produce this. A peer that sends notfound for a block it carries only refuses itself for 10 s."
  • Not listed, it names no trigger that happens in realistic use: "An overlapping filter range can make a valid reply look like a refusal" (warning): "warning, with no realistic trigger. The misread needs two pipelined getcfilters ranges where the earlier one contains the later one's stop block. The maintainers record that batch boundaries are fixed, so no caller in the repository sends overlapping ranges. A library caller would have to enqueue them through enqueue in a way no caller here does. The cost is a duplicate batch or a 10 s hold, which is degraded."
  • Not listed, a check of the code could not confirm it: "A batched block request allocates a full inventory copy for every block" (warning): "warning if multi-block getdata requests exist. The per-key msg.clone() is not new, since the old on-wire loop cloned per key too. What is new is the refusal check: refuses (broker.rs:726) treats a refusal of any key in the message as a refusal of the whole message, so the other blocks in that inventory are also kept from that peer. This only matters if some caller batches several blocks into one getdata, which the code shown does not settle. The allocation itself is the caller's own data, so it is no security defect.
    Refutation disproved: The only block request the sync layer queues is BlockRequest, whose into_message always builds a getdata holding exactly one Inventory::Block. The only non-test callers of enqueue are SendRequest::send and the manager's forwarding of it. With one key per block message, cloning per key makes a single copy, and refusing one key cannot hold back unrelated blocks. Rule checked: The broker copies and refuses a whole message per block key only when one queued getdata holds more than one Inventory::Block, so the cost and the shared refusal need a caller that batches blocks.
  • Premise "a sync manager in dash-spv enqueues a getdata holding more than one Inventory::Block item" unsettled. Sync managers queue blocks only through BlockRequest, which builds a one-block getdata. The other getdata messages (mempool, instantsend, chainlock) go out through send_to, not enqueue, and the mempool one carries only Inventory::Transaction items.
  • Premise "This trigger happens in realistic use: when a multi-block getdata is enqueued and its peer skips one of the blocks" disproved. A multi-block getdata is never queued in normal use. Every non-test enqueue call goes through SendRequest::send, and the only block request type builds one block per message. Only the broker's own tests queue multi-block getdata, and dash-evo-tool builds no getdata at all.
    Pair refutation unsettled: The broker test enqueues a two-block GetData, and routing stores a full copy under each registered block key. The base already cloned once per key after a successful send; this PR moves those clones before the write and adds a retry check that excludes a peer from the entire batch if it refused any one block. Rule checked: Cloning a message that owns a Vec copies the entire vector, so cloning an N-item message once per item takes quadratic time and space.
  • Premise "a sync manager in dash-spv enqueues a getdata holding more than one Inventory::Block item" unsettled. The block sync pipeline sends one BlockRequest per wanted hash, and each request becomes a one-item GetData.
  • Premise "This trigger happens in realistic use: when a multi-block getdata is enqueued and its peer skips one of the blocks" confirmed. On the code side, the broker accepts the tested multi-block batch, and if the peer reader reports one key as skipped, the manager requeues that key's full message and excludes the peer from the whole retry."
  • Kept: "The expiry doc comment exceeds the repository's three-line limit" (suggestion): "note. AGENTS.md sets three lines as the ceiling for a comment, and the rewritten expire doc comment spans four (broker.rs:326-329). It harms nothing at run time, so it is the style row."
  • Not listed, on code an earlier round reviewed: "On-wire times are corrected only after the routing pass, while the hedger already reads them" (suggestion): "note. This is the round 10 finding that an unfinished write starts the hedge timers. It keeps that round's improvement cell, and the maintainers chose to leave the hedge timers as they are. The finding also overstates the effect. For a request's timers to look 2 s old during the pass, a later write must be held more than 2 s. The earlier request's own write finished before that later write started, so it has really been on the wire about that long."

Timing:

  • Parse: 13.6s
  • Review agents: 566.2s
  • Judge: 404.3s
  • Total: 984.0s

manki-review[bot]
manki-review Bot previously approved these changes Dec 4, 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.

✅ Approved. 3 suggestions, none of which block.

What this does: A peer that skips a block or filter request, or answers notfound, now has that request sent to another peer at once. That address is not asked again for 10 seconds.


2 suggestions · not blocking
✨ A timeout can mark a newly assigned peer as refusing
Suggestion, not blocking · Concurrency · Quick fix · dash-spv/src/network/broker.rs:362

Why: The timeout scan identifies stalled attempts but saves only their request keys. If an attempt is moved to another peer before requeue takes the lock, the scan pulls the fresh attempt off the wire and records a refusal against its new address. This affects any keyed request moved between the scan and the retry, including a block or filter moved by a pending refusal event.

}
if !unanswerable.is_empty() {
self.requeue(|k, _| unanswerable.contains(k), Requeue::Refused).await;
}
culprits

How to fix it
Apply expiry to the exact attempt checked under the registry lock, or revalidate its identity and timeout before changing state. Do not expire whichever attempt happens to own the same key later.

Checked in the code
On the flagged line: Reacquires broker state through requeue with a key-only predicate

Takes the lock for the timeout scan

let mut unanswerable = HashSet::new();
for (key, state) in self.requests.lock().await.iter() {
let ReqState::OnWire(o) = state else {
continue;
};

Saves only key.clone() for a retry

);
unanswerable.insert(key.clone());
}
}
if !unanswerable.is_empty() {

Records the address of the attempt removed by requeue, not the one observed by the scan

if why != Requeue::Lost {
retry.refuse(peer.addr());
}
reqs.insert(key, ReqState::Queued(retry));
Some((height, msg))

  • Create an issue for this
✨ Block notfound messages bypass the check for a later outstanding copy
Suggestion, not blocking · Correctness · Moderate · dash-spv/src/network/manager.rs:1380

Why: A notfound settles only the first matching ledger entry, but the pump records a refusal for the key even when another copy is still owed or the ledger matched no request. Unlike an inferred skip, a negative reply to an older copy can therefore pull a current block request off the wire and stop the router from using that address for ten seconds.

if let NetworkMessage::NotFound(inv) = &*msg {
broker.refused(peer, &inventory_keys(inv)).await;
}

How to fix it
Have the ledger report explicit refusals only for matched entries whose last outstanding copy was settled, and feed those outcomes through the same broker path as inferred skips. Continue forwarding the original message to subscribers.

Checked in the code
On the flagged line: Derives broker refusals directly from the inventory rather than the ledger

Finds and removes only the first matching Awaited entry

let i = match msg {
NetworkMessage::NotFound(inv) => {
for reply in inv.iter().filter_map(Reply::of_item) {
if let Some(i) = awaited.iter().position(|a| a.reply == reply) {
*self.last_answer.lock().await = Instant::now();
self.release(awaited.remove(i).cost);
}

Returns Vec::new() instead of reporting the settlement outcome

}
return Vec::new();
}
NetworkMessage::CFilter(filter) => {
let Some(i) = awaited.iter().position(|a| matches!(a.reply, Reply::CFilters(_)))

Suppresses an inferred skip when owed.contains(&earlier.reply)

}
if !owed.contains(&earlier.reply) {
keys.extend(earlier.reply.request_key());
}
}

  • Create an issue for this

What to test

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

Setup: Run the dash-spv network unit tests and a testnet sync with cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir>, with peer_speed and dash_spv::network debug logs on.

  1. Run cargo test -p dash-spv --lib network::. Expect the new refusal, skip and failed-write tests to pass.
  2. Sync testnet from scratch. Expect blocks and filters to complete with no long pause after a notfound in the logs.
  3. Configure a single peer that lacks some blocks. Expect a refused block to be asked of that peer again after about 10 s, not lost.
  4. Kill a peer mid-sync while blocks are on the wire to it. Expect its requests to be re-queued and served by another peer.
  5. Leave the client syncing near the tip with two peers. Expect endgame: hedged block lines to still appear while a filter batch both peers refused sits queued.
  6. Edge case: stop and restart the network manager after refusals. Expect refused requests to go out again with no stale refusal kept.

Checked and left out: 1 finding

Not proven, so not listed · 1 warning

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 6e81119, round 13
  • 697 changed lines read in 16m 24s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 5.7M in (4.3M from cache) · 116k out · about $8.03 at API prices
  • Runner: self-hosted · started after 48s · peak memory 4.9 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/broker.rs Resolved

@ZocoLini ZocoLini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The core fix (settle returns skipped keys → requeue at once) looks right. Would remembering only the last refusing peer, and letting the router skip a refused message as it already does, be enough? The refusal map, hold in pop_guaranteed and has_routable add most of the size for cases that seem rare. Or am I missing something?

@manki-review

manki-review Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ Review complete in 14m 20s

Planner (5s)
    feat · 696 lines · 2 agents
    judge effort: high

Review (behavior · full): 12 findings
    ✅ Claude Opus 5.5 · high: 2 findings (3m 14s)
    ✅ GPT 6.2 Sol · high: 9 findings (3m 33s)
    ✅ Related checks, claim checks, pattern checks and fix checks: 17 of 17 done, 1 finding (1m 11s)

Judge (9m 32s)
    graded 12 findings: 9 kept · 1 dropped · 2 merged
    dropped, as the finders filed them: 1 warning
    refuter: 4 checked · 4 confirmed
    origin checks: 8 checked · 2 older than this PR
    verdict reader: read the diff (1m 55s)

Posted: 3 findings
    3 suggestions
    not posted: 1 older than this PR · 1 listed by an earlier round · 2 no realistic trigger · 1 rare trigger · 1 no proof

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 73% (resets 2026-12-08 05:00 UTC)
  • ChatGPT subscription: weekly 6% (resets 2026-12-10 07:41 UTC)

Judge decisions:

  • Not listed, listed by an earlier round: "A skip or notfound from the peer holding a hedge copy is ignored, so the request is not hedged again" (warning): "warning. This keeps the cell of P6. refused at broker.rs:276 matches only o.peer == peer. When the ledger of a hedge peer reports the hedge copy as skipped, nothing happens and the peer stays in o.hedges. hedge at broker.rs:540 then returns early for that block, and hedge_filters at broker.rs:583 skips the batch while that peer answers. The hedge peer's address is also never recorded in retry.refused. The lowest batch or block waits for its carrier's timeout. That case is the testnet peer without a filter index that this PR targets."
  • Not listed, its trigger is rated below review.min_warning_trigger: "A failed write to a peer whose disconnect was already handled leaves its request on the wire and gets the address banned" (warning): "warning. A tracked message whose write fails now gets only unsent_attempt at broker.rs:437-438, which lowers attempts and leaves the OnWire entry in place. The code relies on the disconnect to requeue it. If the pump already ran requeue_from for that connection (manager.rs:1528) before put_on_wire registered the request, the reader has exited and no second Disconnected comes (peer.rs:841). The request then waits for the timeout monitor. That monitor treats a culprit no longer in the set as kicked (manager.rs:1248) and bans its address (manager.rs:1315). The old code put the message straight back in the queue. This depends on the reader not cancelling the token on EOF, which the code shown does not settle.
    Refutation confirmed: Every code step holds: the reader leaves on end of stream without cancelling its token, the pump removes the peer without closing it, the router's copied peer list still offers it, and a failed tracked write leaves the request registered at the dead connection until expire blames it and the monitor bans the address. Whether that write fails after the peer closed is operating-system behaviour no file read states, and if the write succeeds the same stall and ban come from code older than this PR. Rule checked: A tokio CancellationToken is cancelled only by an explicit cancel() on it or on a parent, and a request registered after requeue_from ran for a connection is never requeued by that connection's single Disconnected event.
  • Premise "The peer reader exits on EOF without cancelling the peer's token, so has_room still passes for a departed peer in a routing pass that took its peers snapshot earlier" confirmed. On end of stream the reader takes None => break and only sends Disconnected, is_closed() reads only that token, and the Disconnected handler removes the peer without calling close(), so has_room still accepts it from a peer list copied earlier.
    Pair refutation unsettled: The pump can finish requeueing a departed peer’s requests while the router still holds its handle. If the router then registers a new request and the write fails, it only decrements the attempt count; the reader has already emitted its only disconnect event. Rule checked: A disconnect handler can requeue only requests already registered to that connection; removing a peer from the live set does not invalidate cloned handles.
  • Premise "The peer reader exits on EOF without cancelling the peer's token, so has_room still passes for a departed peer in a routing pass that took its peers snapshot earlier" confirmed. The EOF branch exits without cancelling the shared token, and the pump removes the peer without closing it, so the stale handle still passes the closed check if it has room.", trigger 3 and harm 6 of 10: "It needs a specific race: a route snapshot taken before an EOF disconnect, a requeue_from that runs before put_on_wire, and then a failed write, which is plausible but uncommon."
  • Not listed, it names no trigger that happens in realistic use: "One skipped block batch can generate an unbounded queue of duplicate requests" (warning): "ignore. Block requests are built as BlockRequest, documented as "getdata for one block" (mod.rs:68), so a multi-block inventory is not what the sync layer sends. Even for one, the copies are not unbounded. A refusal matches only keys still carried by the refusing peer. Each later put_on_wire moves every key to the newest carrier, so one refusal yields at most one copy per key. requeue already returned one message per key before this PR.
    Refutation confirmed: Several copies of a multi-block getdata do get queued and resent. But a refusal only matches keys whose current carrier is the refusing peer (broker.rs:276), and each resend moves every key to the newest carrier (broker.rs:484-493). So one refusal adds at most one copy per skipped key, and no unbounded growth follows. The cost is extra resends whose number is set by how many blocks one request holds. No production caller sends such a request. Rule checked: When a getdata carrying several block keys is refused, requeue (broker.rs:235-256) pushes one copy of the whole message per refused key, and put_on_wire (broker.rs:479-501) moves every registered key to whichever peer receives the newest copy.
  • Premise "Every caller of enqueue passes a getdata that holds at most one block inventory" disproved. enqueue is public API of a library crate. pub mod network exposes the public NetworkManager::enqueue, and SendRequest::send accepts any NetworkMessage through impl Request for NetworkMessage, without checking how many blocks a getdata holds. Broker::enqueue registers every block key of the message. A test in this repo does call enqueue with GetData(vec![block(1), block(2)]). All production callers send BlockRequest, which holds one block, but not every caller of enqueue keeps to one block.
    Pair refutation confirmed: The broker queues a full copy of the inventory for each skipped key. Sending one copy re-arms all still-pending keys and sends the entire inventory, including the block that already arrived. Matching refusals to the current carrier limits each refusal to one copy per key, but does not stop the next send from re-arming those same keys. Rule checked: Retrying a whole batch once per failed item lets the queue grow whenever one send produces more retry entries than it removes.
  • Premise "Every caller of enqueue passes a getdata that holds at most one block inventory" disproved. The single-block restriction belongs to BlockRequest, not enqueue: a test passes two blocks to Broker::enqueue, and the public implementation forwards raw messages to that same method without a count check."
  • Not listed, it names no trigger that happens in realistic use: "A retry queued during routing can go straight back to the refusing peer" (warning): "warning cell, no realistic trigger. route computes refusers at broker.rs:394 and then pops the queue right after. A requeue has to land between releasing the requests lock and popping that class. That window is far shorter than the surrounding operations. If it happens, one copy goes back to the refusing peer, which skips it again and gets refused again. has_routable has the same window, and only for one hedger tick."
  • Kept: "Expiry can record a refusal against a replacement peer" (suggestion): "warning cell, no realistic trigger. This keeps the cell of P7. expire collects keys under the lock at broker.rs:333-357 and calls requeue at broker.rs:361 with a predicate that ignores the carrier. Between those two steps, a requeue and a fresh routing to another peer must both happen. That window is only a lock release and reacquire, so the trigger needs a timing window much shorter than the operations around it."
  • Dropped: "An overlapping filter range can turn an in-order reply into a false refusal" (ignore): "ignore. The false match needs two outstanding getcfilters on one connection whose ranges overlap. The maintainers' recorded decision states that batch boundaries are fixed, so filter ranges do not overlap. A filter inside one batch therefore never carries the stop hash of another outstanding batch."
  • Kept: "A block notfound can mark the peer as refusing a copy it still owes" (suggestion): "warning cell, no realistic trigger. This keeps the cell of P8. The notfound path at manager.rs:1380 calls refused with the raw inventory and skips the later-copy check at costs.rs:297. The trigger needs one peer to owe two copies of the same block and then send notfound for it. The maintainers recorded that Dash Core sends nothing, not notfound, for a block it does not have, so normal use does not produce this sequence."
  • Not listed, on code this PR did not change: "Unrelated replies can still keep a skipped request alive indefinitely" (warning): "warning, held by its doubt as P3 was. Headers and Headers2 are not in_order (costs.rs:84), so they never prove a skip. Yet manager.rs:1404-1412 refreshes both clocks of every request at that peer on each such reply (broker.rs:316). expire reads only those clocks (broker.rs:338, broker.rs:342), and getcfheaders has no hedge. The PR sets out to stop a skipped request living on at a busy peer, so this sibling path in a changed file is part of the change. Whether header replies reach such a peer often enough is not settled by the code shown.
    Refutation confirmed: The refresh path is real. While header sync runs, getheaders replies at a peer keep a skipped getcfheaders there alive, and getcfheaders has no hedge. But the stall is not indefinite. Once header sync ends, Headers replies come only with new blocks, so after ANSWER_TIMEOUTS × timeout (6 × at least 10 s) with no answer expire requeues or blames the request. Any later getcfheaders reply from the same peer also proves the skip. The effect is a delay that a later pass heals, not a permanen... Rule checked: A broker request expires only when its own peer's clocks go stale, and any Headers/Headers2 reply from that peer refreshes the clocks of every request it carries, whether or not the reply settles one.
  • Premise "The sync layer enqueues getheaders requests that can be routed to a peer while a getcfheaders that peer skipped is still on the wire there" confirmed. Header segments declare getheaders through network.send, which goes to enqueue and the broker. choose_peer sends a Headers-class message to the open peer with the shortest queue, and that can be a peer still holding a skipped getcfheaders.
  • Premise "This trigger happens in realistic use: When header sync and filter header sync run at once and the peer carrying a skipped getcfheaders keeps answering getheaders" confirmed. Filter header sync is driven by every BlockHeadersStored event, so it runs during initial header sync by design. Header requests are routed to any open peer, including the one carrying the skipped getcfheaders, and each Headers/Headers2 reply from it refreshes both clocks of all its requests. The code shows this part; whether a peer actually skips a getcfheaders is peer behaviour the code cannot show.
    Pair refutation confirmed: A Headers or Headers2 message never proves a compact-filter-header request was skipped, even when it matches the ledger. The message still resets both expiry clocks for every request carried by that peer, and neither hedger handles compact-filter-header requests. Rule checked: A request has no independent expiry deadline if unrelated replies can reset every clock used to expire it.
  • Premise "The sync layer enqueues getheaders requests that can be routed to a peer while a getcfheaders that peer skipped is still on the wire there" confirmed. The two pipelines enqueue distinct request keys, and the router can send GetHeaders to an eligible peer that already carries GetCFHeaders.
  • Premise "This trigger happens in realistic use: When header sync and filter header sync run at once and the peer carrying a skipped getcfheaders keeps answering getheaders" confirmed. Normal catch-up starts filter-header work as block headers are stored, while the block-header pipeline advances its locator and requests more headers; replies from the same peer refresh the outstanding request without proving the skip."
  • Kept: "The expiry comment overstates which sends use a kicking attempt" (suggestion): "note. broker.rs:328 says every send counts toward KICKING_ATTEMPTS. Hedge copies only push to hedges (broker.rs:149) and never touch attempts, and unsent_attempt takes back the attempt of a failed write (broker.rs:518). A comment that misstates the code is the improvement row."
  • Not listed, a check of the code could not confirm it: "Request timing is fixed only after the routing pass, while the stall check reads the earlier times during it" (warning): "warning. put_on_wire sets last_progress and last_answer to the time before the write (broker.rs:495-497). The real times are written only after the whole pass (broker.rs:447-460). The timeout monitor, a separate task, runs expire during the pass (manager.rs:1298). A pass that spends several write timeouts (peer.rs:352) can therefore get a peer kicked and banned for a request it received only moments ago. Once expire has requeued that request, the reset after the pass skips it. The early hedge through last_answer is the maintainers' accepted case. The kick is not covered by that decision.
    Refutation confirmed: The race is real but its effect is small. put_on_wire stamps a request at most one write, up to WRITE_TIMEOUT (5s), before that write ends, and a write that times out closes its peer. So a peer blamed during a long pass has had at least the full 10s since receiving its request if its own write was fast, and at least about 5s in the worst case. A peer that was idle before the pass is also blamed at the same moment by StallJudge's own owing-bytes check, which ignores the broker's times. So the c... Rule checked: In tokio, a task that awaits a write does not stop other spawned tasks from running, so the timeout monitor can read the times put_on_wire set while a routing pass is still waiting on later writes.
  • Premise "The request timeout expire applies to a connected peer can be shorter than a routing pass held up by several slow writes of up to WRITE_TIMEOUT each" confirmed. A peer's timeout is max(10s, 6 × its handshake lag), so a nearby peer gets 10s. A pass writes to peers one after another and each write can wait up to 5s. A peer whose write stalls is closed and skipped, so three stalled peers in one pass take about 15s, which is longer than 10s.
  • Premise "This trigger happens in realistic use: When one routing pass is held up past the request timeout by writes to several peers that stopped reading" confirmed. The code part holds. The router awaits each peer's write in turn without holding the request lock, and nothing limits how many writes can stall in one pass. The timeout monitor ticks every second in its own task and calls expire. Whether several peers actually stop reading in the same pass depends on how peers behave on the network, which no code shows.
    Pair refutation confirmed: The monitor can read the provisional timestamps while routing is still awaiting later writes, but an expiry is not itself a ban: the stall judge also requires enough observed link uptime for a witnessed kick. The tests show one held write, not a normal-use sequence of several stalls that causes a premature kick or retry. Rule checked: A timeout task can act on a timestamp published before an awaited write if the timestamp is not corrected until the routing pass ends.
  • Premise "The request timeout expire applies to a connected peer can be shorter than a routing pass held up by several slow writes of up to WRITE_TIMEOUT each" confirmed. The monitor uses a 10-second request timeout for low-lag connected peers, and the router awaits writes serially, so three writes with separate five-second budgets can outlast that timeout.
  • Premise "This trigger happens in realistic use: When one routing pass is held up past the request timeout by writes to several peers that stopped reading" confirmed. On the code side, the live router sends queued work to multiple connected peers in one pass and continues after a write timeout without resetting earlier timestamps; this does not establish that several peers actually stop reading in normal use."

Timing:

  • Parse: 12.1s
  • Review agents: 276.8s
  • Judge: 571.6s
  • Total: 860.4s

Last reviewed c3a7d97 · head c3a7d97 · up to date

  • Pause automatic reviews
  • Review again
  • Deeper review

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Your move: coderabbitai left review threads unresolved; resolve them.
Full checklist in the description.

@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. 3 suggestions, none of which block.

What this does: A peer that skips a request, sends notfound or lets it expire was asked for the same data again at once. The broker now remembers which addresses refused each request for 10 seconds and sends it elsewhere, or waits.


2 suggestions · not blocking
✨ Expiry can record a refusal against a replacement peer
Suggestion, not blocking · Concurrency · Moderate · dash-spv/src/network/broker.rs:361

Why: expire records only the key of an exhausted attempt, then drops the request lock before requeueing it. If the reader or disconnect handler requeues that key and routing assigns it to a new peer in between, expiry requeues the fresh attempt and holds off its address for 10 seconds even though it has not stalled.

}
if !unanswerable.is_empty() {
self.requeue(|k, _| unanswerable.contains(k), Requeue::Refused).await;
}
culprits

How to fix it
Validate expiry and move the expired attempt to the queued state in the same request-lock transaction. Alternatively, carry an attempt identity into the requeue operation and apply it only if that exact attempt is still on the wire.

Checked in the code
On the flagged line: Reacquires the lock through requeue with a predicate that ignores OnWire.

Reads stall state under the request lock, but line 357 retains only key.clone().

let mut unanswerable = HashSet::new();
for (key, state) in self.requests.lock().await.iter() {
let ReqState::OnWire(o) = state else {
continue;
};

Records a refusal against whichever peer owns the entry when it is removed.

if why != Requeue::Lost {
retry.refuse(peer.addr());
}
reqs.insert(key, ReqState::Queued(retry));
Some((height, msg))

);
unanswerable.insert(key.clone());
}
}
if !unanswerable.is_empty() {

  • Create an issue for this
✨ A block notfound can mark the peer as refusing a copy it still owes
Suggestion, not blocking · Correctness · Quick fix · dash-spv/src/network/manager.rs:1380

Why: A peer can owe two copies of a block, for example when another copy is sent after an expiry and the refusal hold lapses. A notfound can settle the older copy while the newer one is still outstanding, but the pump uses the raw inventory to requeue the current copy and renew the hold. The skip path checks for a later copy, but the notfound path bypasses that check.

if let NetworkMessage::NotFound(inv) = &*msg {
broker.refused(peer, &inventory_keys(inv)).await;
}

How to fix it
Have the ledger report notfound refusals only for matching outstanding copies with no later copy still owed. Let the pump consume those reconciled refusals rather than inferring them from raw inventory.

Checked in the code
On the flagged line: Calls broker.refused(peer, &inventory_keys(inv)) independently of what the ledger matched.

Requeues expired requests as refused, and dash-spv/src/network/broker.rs:125 allows the address again after the hold.

if !unanswerable.is_empty() {
self.requeue(|k, _| unanswerable.contains(k), Requeue::Refused).await;
}
culprits
}

Finds and removes the first matching ledger entry and line 251 returns Vec::new().

for reply in inv.iter().filter_map(Reply::of_item) {
if let Some(i) = awaited.iter().position(|a| a.reply == reply) {
*self.last_answer.lock().await = Instant::now();
self.release(awaited.remove(i).cost);
}

Suppresses an inferred skip when owed still contains the reply.

}
if !owed.contains(&earlier.reply) {
keys.extend(earlier.reply.request_key());
}
}

  • Create an issue for this

What to test

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

Setup: Run the CLI against testnet with cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir> and enable debug logs for dash_spv::network.

  1. Sync from scratch with several peers. Expect headers, filters and blocks to complete, with no growing re-send loop for one request in the logs.
  2. Connect a single peer that lacks a requested block, so it answers notfound. Expect the block to be asked of that peer again only about every 10 s, not in a tight loop.
  3. With two or more peers, make one peer skip a block, for example by answering a later block first. Expect the skipped block to go to another peer.
  4. Make a peer stall until its write times out. Expect the connection to close and its requests to go to the peer that joins next.
  5. During the block endgame, keep a filter batch refused by every peer. Expect endgame: hedged block lines to appear anyway.
  6. Edge case: let every connected peer refuse the same request. Expect it to stay queued and other queued requests to keep going out until the refusals lapse.

Checked and left out: 2 findings (1 unproven, 1 rare)

Not proven, so not listed · 1 warning

  • Request timing is fixed only after the routing pass, while the stall check reads the earlier times during it · dash-spv/src/network/broker.rs:447
    A check of the code could not confirm it.

Rare trigger, so not listed · 1 warning

  • A failed write to a peer whose disconnect was already handled leaves its request on the wire and gets the address banned · dash-spv/src/network/broker.rs:437
    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 c3a7d97, round 14
  • 696 changed lines read in 14m 20s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 8.3M in (6.6M from cache) · 148k out · about $10.13 at API prices
  • Runner: self-hosted · started after 11s · peak memory 5.5 GiB of 30.0 GiB
  • How Manki reviews

/// already stalled [`KICKING_ATTEMPTS`] times is retried without blaming its peer.
/// Returns the peers of stalled requests, each with the earliest instant it is blamed from.
/// A request stalls on a timeout without progress, or [`ANSWER_TIMEOUTS`] timeouts unanswered.
/// Every send counts toward [`KICKING_ATTEMPTS`], after which a stall is retried without blame.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✨ Suggestion, not blocking · Documentation · Quick fix

The expiry comment overstates which sends use a kicking attempt

Why: The comment says every send counts, but hedge sends do not increment the attempt counter and a failed primary write rolls its increment back.

How to fix it and 6 places read

How to fix it
Describe the threshold in terms of successfully written primary attempts.

Checked in the code
On the commented line: Says Every send counts.

Increments attempts during primary registration, and line 518 rolls that increment back on write failure.

};
retry.attempts += 1;
*slot = ReqState::OnWire(Box::new(OnWire {
peer,
msg: msg.clone(),

Records a hedge in self.hedges, and lines 549 and 598 send it without updating attempts.

);
self.hedges.push(peer.id());
(self.msg.clone(), self.height, peer.clone())
}
}

};
retry.attempts = retry.attempts.saturating_sub(1);
}
}

  • Create an issue for this
  • Dismiss this finding

This branch has not been deployed

No deployments
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