Skip to content

fix(dash-spv): rank a stalled peer last when routing - #1375

Draft
xdustinface wants to merge 16 commits into
devfrom
fix/stalled-peer-last
Draft

xdustinface wants to merge 16 commits into
devfrom
fix/stalled-peer-last

Conversation

@xdustinface

@xdustinface xdustinface commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

A peer that stopped delivering kept the rates it had earned, so shortest-queue routing kept picking it. In a mainnet run one peer serving 2 to 3 MB/s stalled with blocks owed, received 51 more block requests within 4 s, and each was hedged after 10 s.

A peer that owes replies and delivers under 8 KB/s for HEDGE_AFTER is now stalled. While any open peer is not stalled, a stalled peer takes no new request and its free room does not count, so work waits for a delivering peer even when every delivering peer is at its cap. A stalled peer gets work only when every open peer is stalled, and the router looks again as soon as a stall begins or ends. The flag clears with the first tick of real delivery, so a fast peer computing one reply keeps its rank, and a peer still streaming a big reply is never flagged. A tick in which our own link stalled counts too, since one tick cannot tell it from a slow peer: in a real outage every owing peer stalls together, so routing falls back to all of them, and each flag clears once its peer delivers again. Hedges already skip a silent peer, and they now also skip a stalled peer that still answers small replies whenever another candidate has room. A stalled peer with room still gets the copy when no delivering one has room, so a hedge is never dropped for it.

Sampling the serving rate while a peer is backlogged moved to #1564.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.63462% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.97%. Comparing base (58f0518) to head (d2e7005).
⚠️ Report is 6 commits behind head on dev.

Files with missing lines Patch % Lines
dash-spv/src/network/manager.rs 96.95% 5 Missing ⚠️
dash-spv/src/network/peer.rs 93.75% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1375      +/-   ##
==========================================
+ Coverage   87.96%   87.97%   +0.01%     
==========================================
  Files         270      270              
  Lines       72505    72688     +183     
==========================================
+ Hits        63780    63949     +169     
- Misses       8725     8739      +14     
Flag Coverage Δ
core 83.65% <ø> (-0.02%) ⬇️
rpc 83.65% <ø> (-0.02%) ⬇️
spv 95.32% <96.63%> (-0.01%) ⬇️
wallet 83.65% <ø> (-0.02%) ⬇️
Files with missing lines Coverage Δ
dash-spv/src/network/broker.rs 98.88% <100.00%> (+0.30%) ⬆️
dash-spv/src/network/peer.rs 94.06% <93.75%> (+0.47%) ⬆️
dash-spv/src/network/manager.rs 97.50% <96.95%> (-0.01%) ⬇️

... and 3 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

Copy link
Copy Markdown
Collaborator Author

Follow-up from the #1345 review: a culprit that StallJudge spares while it waits for its paced kick still gets new requests from route and hedge. Headers and filters routed to it wait until the kick, up to a timeout per culprit ahead of it. When this rebases onto #1345, skip those peers or rank them last here too.

@xdustinface
xdustinface force-pushed the fix/stalled-peer-last branch from c54619d to 3ad9174 Compare December 1, 2026 12:24
@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:24
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 14m 36s

Planner (5s)
    feat · 167 lines · 2 agents
    judge effort: medium

Review (behavior · full): 11 findings
    ✅ Claude Opus 5.5 · high: 2 findings (1m 37s)
    ✅ GPT 6.2 Sol · high: 7 findings (3m 0s)
    ✅ Comparisons, related checks, claim checks and pattern checks: 12 of 12 done, 1 finding (1m 33s)
    ✅ Second reads: 1 of 1 done, 1 finding (1m 23s)

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

Posted: 4 findings
    1 warning · 3 suggestions
    not posted: 2 older than this PR · 2 over the review.notes limit

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:

  • Not listed, on code this PR did not change: "A stalled peer still takes every request the delivering peers have no room for" (warning): "warning. route passes choose_peer only peers below their cap (broker.rs:359), and budget counts the stalled peer's free room (broker.rs:332-336). When every delivering peer is full, delivering at broker.rs:582 is empty, and the fallback at broker.rs:586 hands the work to the stalled peer. That holds until the peer's in-flight bytes reach its decaying cap. The requests then wait for the 10 s hedge, a slowdown sync users notice, though results stay correct. Whether the stalled peer keeps cap room after it is flagged depends on cap decay (manager.rs:541-570) against its frozen in-flight bytes, so that premise is listed as a doubt.
    Refutation disproved: A peer is only flagged stalled after 8 ticks (2 s, HEDGE_AFTER) with almost no delivery. During those ticks it is not yet stalled, so routing treats it like any other peer. In bulk download, where the other peers are full, it is the only peer with room, so the router fills it up to its cap. After that its in-flight bytes stay frozen, because they drop only when it replies. Its cap meanwhile decays toward served*2, and served itself falls 12.5% per tick when nothing arrives. So by the time the fl... Rule checked: The router at broker.rs:359 only sends to peers with in_flight_bytes() < cap(). A peer's in-flight bytes go down only when that same peer replies (Ledger::settle/release). Its cap shrinks every tick while it is serving_all, meaning it either holds at least its cap or has a backlog larger than twice its falling rate.
  • Premise "A peer flagged stalled by PeerFlow::update still has in_flight_bytes() < cap() for at least one routing pass after the flag is set, so route at broker.rs:359 keeps it in open" disproved. Before the flag, the router fills the soon-to-stall peer to its cap. In bulk download it is the only peer in 'open', and choose_peer does not skip it because it is not stalled yet. After that its in-flight bytes are released only by its own replies (costs.rs:219-268). Over the 2 s it takes to set the flag, its cap shrinks: served decays toward 0 (manager.rs:560) and the cap loses 50%/s of its excess over the target (manager.rs:570). So when the flag is set, in_flight >= cap. The probe (+8 KB/tic...
  • Premise "This trigger happens in realistic use: when bulk download keeps every delivering peer at its cap and a peer with cap room left stalls" unsettled. A peer with free room can stall while the others are full. But in bulk download, with work queued, the router fills that peer to its cap during the 2 s before the flag is set (broker.rs:350-363). So the state the finding needs, a flagged peer that still has room, does not come from this sequence. The code read does not show whether some other sequence produces it, such as the queue being empty right up to the flag.
    Pair refutation unsettled: If a stalled peer is the only peer below cap, its headroom supplies the routing budget and the fallback sends it work until it is no longer eligible. The tests establish post-stall headroom and bulk saturation separately, but do not establish that queued work and both conditions coincide in normal sync; the claimed fixed 10-second hedge delay also does not follow from the code. Rule checked: Filtering an iterator cannot recover peers excluded by an earlier filter, so the fallback ranks only peers that are below their caps.
  • Premise "A peer flagged stalled by PeerFlow::update still has in_flight_bytes() < cap() for at least one routing pass after the flag is set, so route at broker.rs:359 keeps it in open" confirmed. The eight-tick test where both peers stall still expects a send to peer 1 after the flow updates, and that send requires peer 1 to remain below its published cap.
  • Premise "This trigger happens in realistic use: when bulk download keeps every delivering peer at its cap and a peer with cap room left stalls" unsettled. The bulk helper fills each peer directly, and the mixed-rate stall test leaves a delivering peer eligible; neither shows live bulk routing reaching the combination, especially since the router can spend the future stalled peer's headroom before the flag is set."
  • Kept: "The stall test feeds PeerFlow::update a made-up in-flight value instead of running the flow controller" (suggestion): "note. In the bulk phase the test passes peer.cap() as in_flight while the ledger holds only one header and one block charge (manager.rs:3338-3339, 3359). It also drives its own PeerFlow array instead of the controller. That builds a state production never reaches, which AGENTS.md forbids. The test still fails if update or choose_peer is reverted, so this is about how the test is built."
  • Kept: "The stall detector mistakes socket traffic for reply progress" (suggestion): "note. got at manager.rs:615 counts every byte read (peer.rs:114), and the 8 KB/s floor is a stated design choice (manager.rs:481-483 and the description). The effects are limited to routing order. A peer streaming under 8 KB/s is ranked last, and a peer that is that slow ranks low anyway. Unrelated traffic above 2 KB per tick delays a flag. This is worth asking about as a choice, not a defect shown to cause a noticeable failure."
  • Not listed, on code this PR did not change: "Two silent peers can keep each other eligible for new requests" (warning): "warning, without a realistic trigger. With two frozen peers owing bytes and nothing arriving, link_silent (manager.rs:1090-1098) marks the tick as a link stall, so neither peer accrues stall ticks (manager.rs:623). The effect is self-limiting:
  • While the healthy peer is idle, choose_ranked picks it first, since its queue is empty (broker.rs:597-600).
  • Once it delivers, link_silent turns false and the frozen peers accrue ticks again.
    The only cost is a delayed flag. No sequence in normal use shows a noticeable slowdown, and the description states that a link-stall tick neither adds to a stall nor ends it."
  • Not listed, over the review.notes limit: "A local link stall can clear a peer's stalled rank" (suggestion): "note. manager.rs:621 resets stalled_ticks on delivery or an empty ledger before the link_stalled check, so a link-stall tick can end a stall, against the doc comment at manager.rs:612. Ending a stall when the peer actually delivered at least 2 KB or owes nothing is correct behaviour. So the issue is a comment that misstates the code, not a routing defect."
  • Kept: "Measured hedge candidates ignore the stalled rank" (warning): "warning. hedge_peer ranks measured peers by their old rate (broker.rs:621-625) and applies the stall-aware choose_peer only as a fallback (broker.rs:626). This is a sibling path in a file the PR changes. The description relies on answering (broker.rs:533) to skip silent peers. A stalled peer that answered a small reply recently passes that check and can win the hedge, which delays the second copy. Whether the stalled flag and a recent answer can coincide is the premise in doubt.
    Refutation confirmed: A slow peer streaming small CFilter messages sets last_answer on each filter, so it passes answering, yet it is flagged stalled. hedge_peer then ranks it by its measured serving_rate. That rate only changes while the peer is bound, so it can stay at the old fast value and beat a healthy peer. choose_peer's stall filter runs only when no peer has a rate. Rule checked: A peer counts as answering when it settled any reply in the last HEDGE_AFTER. It counts as stalled when it delivered under 2 KB in each 250 ms tick for 2 s while owing bytes. Neither check excludes the other, and hedge_peer applies the stalled check only in its fallback.
  • Premise "A peer can be flagged stalled by PeerFlow::update while Ledger::silent_for() is below HEDGE_AFTER, because a small awaited reply settled within the last two seconds" confirmed. silent_for takes the later of the oldest awaited send time and last_answer. Every CFilter or other matched reply refreshes last_answer. The stall counter only looks at bytes per tick, so a peer settling small replies under 2 KB per tick is both stalled and under HEDGE_AFTER silent.
  • Premise "This trigger happens in realistic use: when a peer delivering under 8 KB/s settles a small reply shortly before a block or filter hedge is due" confirmed. Filter batches are answered as a stream of small CFilter messages, and each one refreshes last_answer. A peer throttled below 8 KB/s while owing a batch is the case the stall flag targets. hedge_filters runs on such batches, and for the lowest batch it admits every answering peer.
    Pair refutation confirmed: A small matching reply can refresh the silence timer without clearing the stalled flag when other replies remain outstanding. Both hedge paths can then rank that peer first using its historical rate, even with a non-stalled alternative. Rule checked: Rust's Option::or_else runs its fallback only on None, so a positive-rate hedge candidate bypasses the stall-aware selector.
  • Premise "A peer can be flagged stalled by PeerFlow::update while Ledger::silent_for() is below HEDGE_AFTER, because a small awaited reply settled within the last two seconds" confirmed. A matching reply refreshes last_answer, but fewer than 2 KiB received in a 250 ms tick does not reset the stall counter if other replies are still owed.
  • Premise "This trigger happens in realistic use: when a peer delivering under 8 KB/s settles a small reply shortly before a block or filter hedge is due" confirmed. The network reader settles small awaited replies while other work can remain charged, and the periodic hedger can act on a different peer's overdue request anywhere within the resulting two-second eligibility window."
  • Not listed, over the review.notes limit: "The new test duplicates the broker's block and header fixtures" (suggestion): "note. get_block at manager.rs:1623 is identical to broker.rs:831. get_headers at manager.rs:1627 is get_headers(2) from broker.rs:796. AGENTS.md asks to reuse helpers. This only tidies the code."
  • Dropped: "Catch-up ticks may count as separate samples of silence" (ignore): "ignore. A burst of catch-up ticks only flags a peer after more than 2 s of controller delay. Even then:
  • The first burst tick sees all the delayed bytes and resets the counter.
  • With two or more peers owing bytes, the empty ticks count as link silence and do not accrue (manager.rs:1090-1098).
  • Any false flag clears on the next real tick of delivery.
    At most this is a one-pass routing blip, a note-level cost, so it is dropped."
  • Kept: "A request the broker gave up on keeps its peer flagged stalled whenever it goes quiet" (warning): "warning. charge adds to the ledger (costs.rs:205-217), and only settle releases it. requeue from expire (broker.rs:305-319, 188-211) leaves the charge on the peer. Project memory confirms Dash Core answers an unservable block request with nothing. With in_flight > 0 for good, every quiet tick adds to stalled_ticks (manager.rs:621-624). The healthy peer is then flagged and ranked last for header and block routing (broker.rs:582-585) whenever another peer delivers. The phantom charge predates this PR, but the new stall logic turns it into lost routing capacity.
    Refutation confirmed: expire re-queues requests that already stalled KICKING_ATTEMPTS times without kicking their peer, and requeue never touches that peer's ledger. Only settle releases a charge, so the peer keeps a charge it will never pay off. The new PeerFlow::update then adds to stalled_ticks on every tick where the peer delivers under 8 KB/s, flags it stalled after HEDGE_AFTER, and choose_peer routes it work only when every open peer is stalled. In practice that means when the other peers are at the... Rule checked: A charge added to a peer's ledger by charge is released only by settle on a matching reply or notfound, so a request the peer silently ignores leaves in_flight_bytes > 0 for the life of the connection, and the new stall test counts every quiet tick with in_flight > 0.
  • Premise "No code path other than Ledger::settle removes an Awaited entry or releases its charge after Broker::expire re-queues a request without kicking its peer" confirmed. Under dash-spv/src/network, only Ledger::settle removes awaited entries and calls release (costs.rs:226, 255). Broker::requeue, which expire calls, only switches the request state to Queued and never touches the peer's ledger.
  • Premise "This trigger happens in realistic use: when a connected peer silently ignores a block or getmnlistd request it cannot serve until the broker stops blaming it" confirmed. Dash Core returns without any reply for a block it has no index entry for, and for a getmnlistd that is rate limited or that its pruned or snapshot node cannot serve. After KICKING_ATTEMPTS, expire re-queues such a request without kicking the peer it is on.
    Pair refutation confirmed: The broker requeues the timed-out request without removing its charge from the still-connected peer’s ledger. That stale charge can keep a quiet peer marked stalled after the broker has stopped waiting for its reply. Rule checked: A timeout that requeues a request must also clear the old peer’s charge if that charge is used to decide whether the peer still owes a reply.
  • Premise "No code path other than Ledger::settle removes an Awaited entry or releases its charge after Broker::expire re-queues a request without kicking its peer" confirmed. For a live connection, only Ledger::settle removes awaited entries and subtracts their charges; requeue changes only broker state and the request queue.
  • Premise "This trigger happens in realistic use: when a connected peer silently ignores a block or getmnlistd request it cannot serve until the broker stops blaming it" confirmed. Normal block sync sends GETDATA, Dash Core silently drops requests for missing block data or unavailable masternode history, and the broker stops blaming a request’s carrier at the retry threshold.", trigger 5 and harm 5 of 10: "Dash Core silently ignoring a getdata, getmnlistd or getheaders it cannot serve is realistic but uncommon, and it then needs the peer to go quiet with the leaked charge still on it."

Timing:

  • Parse: 7.9s
  • Review agents: 365.0s
  • Judge: 503.0s
  • Total: 875.9s

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


1 suggestion · not blocking
✨ Measured hedge candidates ignore the stalled rank
Suggestion, not blocking · Pre-existing · Performance · Quick fix · dash-spv/src/network/broker.rs:626

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

Why: A peer marked stalled for low throughput can still have a recent small reply, so it passes the hedge silence check. Both block and filter hedges then use its old rate ahead of a healthy candidate, because only the no-rate fallback applies the new rank.

How to fix it
Apply the same stall preference to hedge candidates before comparing finish times. Keep the existing silence check, which also excludes peers that do not qualify as hedge recipients at all.

  • Create an issue for this

2 more suggestions are not listed.

About this review
  • Reviewed 3ad9174, round 1
  • 167 changed lines read in 14m 36s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 4.1M in (3.0M from cache) · 94k out · about $6.43 at API prices
  • Runner: self-hosted · started after 11s · peak memory 3.7 GiB of 30.0 GiB
  • How Manki reviews

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

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 12m 58s

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

Review (behavior · full): 14 findings
    ✅ Claude Opus 5.5 · high: 1 finding (3m 26s)
    ✅ GPT 6.2 Sol · high: 9 findings (3m 25s)
    ✅ Comparisons, related checks, claim checks and pattern checks: 12 of 12 done, 3 findings (1m 41s)
    ✅ Second reads: 1 of 1 done, 1 finding (1m 47s)

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

Posted: 5 findings
    1 warning · 4 suggestions
    not posted: 1 older than this PR · 4 on code an earlier round reviewed · 1 over the review.notes limit · 1 already caught by a test

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:

  • Kept: "A stalled peer still gets new requests whenever every delivering peer is at its cap" (suggestion): "note. The mechanics are right. route counts the stalled peer's spare room in budget at broker.rs:335. It drops full peers from open at broker.rs:359 before choose_peer checks the stall flag at broker.rs:582-586. So once every delivering peer is at its cap, the stalled peer gets new work. The test case at manager.rs:3328, "a stalled peer is still picked when the delivering one is full", shows the author chose this. It is intended behaviour, so this is a question about the choice. During bulk download the delivering peers sit at their caps, so the stalled peer keeps taking requests that then wait for a hedge. Is filling that room worth more than holding the work in the queue until a delivering peer frees space?"
  • Not listed, on code this PR did not change: "Quiet ticks hide a stalled peer when another peer still owes work" (warning): "warning. link_silent at manager.rs:1090-1098 reports a link stall whenever at least two peers owe bytes and none sent any in that tick. update adds to stalled_ticks only when !link_stalled (manager.rs:623). Picture a frozen peer next to a healthy peer that is still computing its reply. Every tick in which the healthy peer is silent adds nothing to the frozen peer's count. The frozen peer then keeps its rank in choose_peer (broker.rs:582) past HEDGE_AFTER and keeps receiving work that an idle peer could take. In bulk sync the healthy peers send bytes in almost every tick, so this mostly delays detection at sparse times.
    Refutation confirmed: On a tick where nobody sends a byte while two peers owe replies, stalled_ticks is neither reset nor increased (manager.rs:618-623). So a frozen peer is still marked stalled after 8 ticks of 250 ms in which some peer delivers. The only effect is a delay. New work is routed mostly as replies arrive, and those arrivals end the silent ticks. Separately, hedging of the frozen peer's requests uses silent_for (broker.rs:533) and does not depend on this flag. A bounded detection delay is negligible,... Rule checked: A peer's stall counter goes up only on ticks that do not look like our own link stalling, so skipped ticks delay the stalled flag without resetting it.
  • Premise "This trigger happens in realistic use: when a peer freezes while the only other peers owing replies are computing a slow reply, so no peer sends a byte for several ticks" confirmed. In the code, a tick where every owing peer is silent counts as a link stall. Idle peers add no traffic to break that silence, because the client's version message sets relay to false, so peers send it no transaction announcements. While two or more peers owe replies and none sends a byte, the frozen peer's stalled_ticks stops increasing. How long a real peer takes to build a reply is runtime behaviour that no code here shows.
    Pair refutation confirmed: When two peers owe replies and no bytes arrive, the flow controller marks the tick as a link stall and leaves the frozen peer's counter unchanged. Seven counted ticks after eight skipped ticks still leave that peer below the eight-tick routing threshold. Rule checked: A stall counter that skips shared-silence ticks measures only the ticks it counts, not the elapsed time a peer has been silent.
  • Premise "This trigger happens in realistic use: when a peer freezes while the only other peers owing replies are computing a slow reply, so no peer sends a byte for several ticks" confirmed. The loopback test supplies eight byte-free ticks with two replies outstanding, then resumes traffic from only one peer, exercising the observable trigger without assuming why a remote peer was quiet."
  • Kept: "Raw socket throughput is not evidence of reply progress" (suggestion): "note. This is the same point as P3, and the code at manager.rs:614-624 has not changed since that round. delivering compares raw bytes_read() growth against 2 KB per tick. That count includes unrelated messages (peer.rs:114) and leaves out reply settlement (costs.rs:256). The earlier cell stands, since there is no new evidence."
  • Not listed, on code an earlier round reviewed: "Routing can skip the stalled fallback when a peer changes status" (suggestion): "note. choose_peer reads the live stalled() flag twice: once at the probe (broker.rs:583) and again while choose_ranked iterates (broker.rs:584). The flow controller flips that flag every 250 ms (manager.rs:627). If the only unstalled peer flips between the two reads, the result is None and the message goes back to the queue. The window is the few instructions between the two reads, much shorter than the tick around it. The delay that follows is bounded by the next notify or STALL_CHECK. Snapshotting the flags once is a cheap fix."
  • Not listed, an existing test already fails when the change it names is reverted: "The slow-stream test passes even if both streaming peers are marked stalled" (suggestion): "note. The finding is right that the case at manager.rs:3326 also passes if both peers are flagged, because the all-stalled fallback ranks them the same way. But reverting the delivering reset at manager.rs:621 would flag both peers in the case at manager.rs:3323 as well. Its fallback would then pick the faster peer 1, not the expected 2, so that existing case already fails. This only sharpens what one case proves."
  • Kept: "The routing regression bypasses the public request API" (suggestion): "note. The test calls net.state.broker.enqueue (manager.rs:3391) instead of the public NetworkManager::enqueue. That literally goes against "Test through the public API." The public method only delegates to the broker (manager.rs:338-340), and the test sets no internal state by hand. So the gap is small: calling net.enqueue(0, request) keeps the test on the public path."
  • Not listed, on code an earlier round reviewed: "The new request fixtures duplicate existing test helpers" (suggestion): "note. get_block and get_headers in manager.rs:1624-1633 copy the private helpers in the broker tests (broker.rs:796, broker.rs:831). Reusing them means moving those helpers to shared test support. This is tidying only."
  • Not listed, on code an earlier round reviewed: "The PR description incorrectly says a link stall cannot clear the peer flag" (suggestion): "note. The reset at manager.rs:621 runs before the !link_stalled guard at manager.rs:623, so a link-stall tick can end a stall when the peer is idle or delivering. The doc comment at manager.rs:612 now says only "adds nothing to a stall", which matches the code. The PR description still says such a tick "neither adds to a stall nor ends it". The code behaves sensibly here, so only the description needs a fix."
  • Not listed, over the review.notes limit: "The routing test comment exceeds the repository's three-line limit" (suggestion): "note. AGENTS.md sets three lines as the ceiling for a comment. The doc comment on a_stalled_peer_gets_no_new_requests runs four lines, manager.rs:3319-3322."
  • Dropped: "Missed interval ticks may count several times against a peer" (ignore): "ignore. Burst catch-up ticks would only flag a peer when the flow-controller task itself runs more than 2 s late. Even then the flag lasts only until the next tick with real delivery. That is at most a degraded cost in a rare internal case, a note, and the reviewer could not confirm the interval behaviour or point to proving lines."
  • Not listed, on code an earlier round reviewed: "A reply streaming in below 8 KB/s still marks its peer as stalled" (suggestion): "note. The comment at manager.rs:482 says "any reply streaming in rises above" STALLED_BELOW_BYTES_PER_SEC. The check at manager.rs:620 is a fixed 2 KB per 250 ms tick. A reply streaming on a link slower than 8 KB/s therefore counts as a stall after HEDGE_AFTER. The comment misstates the code, so readers may rely on a guarantee it does not give."
  • Kept: "Stall counting sits in a method that needs a live ConnectedPeer, outside the numeric tick that tests drive" (suggestion): "note. The stall counter lives in update(&ConnectedPeer, ...) at manager.rs:613. The Served harness drives flow.tick (manager.rs:1981), so that harness cannot exercise stall counting. a_stalled_peer_gets_no_new_requests covers the counter through the running flow controller, though. Moving the counting into a numeric helper would be a structural improvement."
  • Kept: "A peer left owing a request it will never answer is flagged stalled for good and gets no new work" (warning): "warning. This is the same defect as P1, and the code is unchanged since that round. expire re-queues a request after KICKING_ATTEMPTS without kicking its peer or releasing its ledger charge (broker.rs:305-319). Only settle releases a charge (costs.rs:219-268), so in_flight stays above 0 for the rest of the connection. When that peer goes quiet, update counts stall ticks (manager.rs:621-625) and choose_peer ranks it last (broker.rs:582). "For good" overstates it: when every delivering peer is full the peer still gets work, and any delivery resets the count. The earlier cell stands.
    Refutation confirmed: The stale charge is real: expire re-queues a request after KICKING_ATTEMPTS (2) without blaming its peer, and only the original peer of a hedged block is ever blamed, so the hedge peer's charge stays. But 'for good' does not hold for a quiet peer. The judge's liveness check makes any peer with in_flight > 0 and a byte counter frozen past its timeout (at least 10s) a culprit to kick, so the peer is disconnected and the state heals. The flag lasts only while the peer keeps trickling small messages... Rule checked: A ledger charge is released only when a matching reply or notfound comes in, so a request the peer never answers keeps its in_flight above 0 until something else clears it or the peer disconnects.
  • Premise "This trigger happens in realistic use: when a peer silently ignores a block request it cannot serve until the broker retries it elsewhere without kicking that peer" confirmed. On the code side the premise holds. Dash Core returns without any reply (no notfound) for a block it has no index or no data for. Neither routing (choose_ranked) nor hedge_peer checks whether the peer has the block. expire blames only o.peer, and from the second attempt on it only re-queues without kicking, so the charge of a peer that ignored the request stays. Whether real peers lack the requested block at run time is network behaviour no code shows.
    Pair refutation confirmed: The stale charge can mark a peer stalled and make the router skip it while another eligible peer is not stalled. But the timeout monitor can independently close a peer whose byte counter stops advancing, and the router can still select a stalled peer when no eligible non-stalled peer remains; the code checked does not establish lasting exclusion in normal use. Rule checked: Requeuing a broker request does not clear its separate per-connection charge, but that stale charge does not by itself make routing exclusion permanent.
  • Premise "This trigger happens in realistic use: when a peer silently ignores a block request it cannot serve until the broker retries it elsewhere without kicking that peer" confirmed. Dash Core's block handler returns without a block or NOTFOUND for an unknown hash, and on the client side the broker requeues an unanswered block at the attempt limit without nominating its carrier for a kick, though the separate timeout monitor can still do so."

Timing:

  • Parse: 9.1s
  • Review agents: 399.4s
  • Judge: 369.4s
  • Total: 777.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.

CI started for d2e7005: Continuous integration, Pre-commit Checks, Sanitizer.

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

Still open from earlier reviews:

  • dash-spv/src/network/manager.rs:621: A request the broker gave up on keeps its peer flagged stalled whenever it goes quiet (view thread)

1 suggestion is not listed.

About this review
  • Reviewed 91a07b2, round 2
  • 188 changed lines read in 12m 58s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 5.8M in (4.8M from cache) · 105k out · about $6.60 at API prices
  • Runner: self-hosted · started after 13s · peak memory 3.9 GiB of 30.0 GiB
  • How Manki reviews

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

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 11m 41s

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

Review (behavior · full): 11 findings
    ✅ Claude Opus 5.5 · high: 1 finding (2m 24s)
    ✅ GPT 6.2 Sol · high: 6 findings (3m 36s)
    ✅ Comparisons, related checks, claim checks, pattern checks and fix checks: 14 of 14 done, 3 findings (1m 33s)
    ✅ Second reads: 1 of 1 done, 1 finding (1m 37s)

Judge (5m 2s)
    graded 11 findings: 7 kept · 2 dropped · 2 merged
    dropped, as the finders filed them: 2 suggestions
    refuter: 2 checked · 2 confirmed
    origin checks: 2 checked · 1 older than this PR
    verdict reader: read the diff (51s)

Posted: 3 findings
    3 suggestions
    not posted: 2 on code an earlier round reviewed · 1 already caught by a test · 1 no realistic trigger

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

Judge decisions:

  • Kept: "During a bulk block download, a stalled peer with free cap room still gets new block requests" (suggestion): "note. This is the routing gap of the open thread on choose_peer (P5), extended to hedge. route builds open after the cap filter (broker.rs:359), and hedge does the same (broker.rs:429), so delivering_first (broker.rs:586-592) falls back to the stalled peer once every delivering peer is full. The test case 'a stalled peer is still picked when the delivering one is full' (manager.rs:3371) shows the author chose this fallback. The earlier round graded it on the improvement row, and the code here has not changed in a way that adds a defect. The hedge path is the same choice in a sibling call, so the cell stays the same."
  • Kept: "A bursty healthy connection can keep a silent peer ranked highly beyond two seconds" (warning): "warning. link_silent (manager.rs:1090-1098) calls a tick silent when at least two peers owe bytes and none delivered any. The controller passes that result as link_stalled (manager.rs:708). update then skips the stall count on that tick (manager.rs:623-624). So when the healthy owing peer delivers in one tick out of four, three of every four ticks are judged link stalls. The silent peer gains only one stall tick per burst. It needs 8 ticks (manager.rs:650), so it is flagged after about 8 s instead of 2 s. Until then choose_peer keeps ranking it by its old queue, and each block sent to it waits for a hedge. That is the routing delay this PR sets out to remove.
    Refutation confirmed: The mechanism is real. On any tick where no peer read a byte while two or more owe, link_silent returns true, update skips the increment, and the silent peer needs 8 counted ticks before it is flagged. But the damage is bounded and short: a request routed to the not-yet-flagged silent peer still gets a second copy once its peer has answered nothing for HEDGE_AFTER (broker.rs:96). That is the pre-PR behaviour, so the effect is a few seconds of extra latency rather than a wrong result. Rule checked: A per-tick stall counter that skips any tick judged a link-wide silence, meaning at least two peers owe bytes and none sent any, grows only on ticks in which some other peer delivered bytes. So a bursty co-owing peer slows down how fast a silent peer gets flagged.
  • Premise "This trigger happens in realistic use: When one peer owes a reply and goes silent while another owing peer delivers its replies in bursts spaced more than 250 ms apart" confirmed. Answered on the code part only. bytes_read counts raw socket bytes as they arrive (peer.rs:113), so a tick is link-silent exactly when the healthy peer owes a reply but none of its bytes arrive within that 250 ms tick, for example while a reply's round trip is still under way. The controller then passes link_stalled=true, and the silent peer's stalled_ticks does not grow on that tick. Whether real peers' round trips or bursts leave such gaps is network behaviour that no code here can show.
    Pair refutation confirmed: When both peers keep owing replies, ticks with no incoming bytes do not count against the silent peer. If only one tick per second sees a burst, the peer needs about eight seconds rather than two to be marked stalled. Rule checked: A stall counter that advances only on samples with incoming traffic measures qualifying samples, not elapsed time.
  • Premise "This trigger happens in realistic use: When one peer owes a reply and goes silent while another owing peer delivers its replies in bursts spaced more than 250 ms apart" confirmed. The test suite supplies a silent peer and a burst-delivering peer that both remain charged across gaps longer than 250 ms."
  • Dropped: "The stall threshold also flags replies that stream below 8 KiB/s" (ignore): "ignore. This problem was already answered in its review thread as a deliberate byte threshold. The constant and its comment at manager.rs:481-483 and the check at manager.rs:620 have not changed since that answer."
  • Not listed, an existing test already fails when the change it names is reverted: "The streaming test passes even when both peers are falsely marked stalled" (suggestion): "note. The 40-tick case at manager.rs:3369 alone would still pick peer 1 through the all-stalled fallback. A revert of the delivery reset at manager.rs:620-622 still fails the suite, though. In the first case (manager.rs:3366), peer 2 owes a block and delivers 16 KB/s of filters, which never settle it. Without the reset, peer 2 would also be stalled, so the fallback picks peer 1 where the case expects 2. Making the streaming case discriminate on its own is a small test improvement."
  • Not listed, on code an earlier round reviewed: "The network tests duplicate the broker's request builders" (suggestion): "note. get_block at manager.rs:1624 is identical to broker.rs:848. get_headers() at manager.rs:1628 is broker.rs:813 with the locator fixed to 2. AGENTS.md asks to reuse and extend an existing test helper rather than write a near copy. Nothing breaks at run time, so this is the improvement row."
  • Kept: "The test-only hedge accessor has broader visibility than its caller needs" (suggestion): "note. hedges_of (broker.rs:512) is new and declared pub. Its only caller is the sibling manager tests, and network/mod.rs declares both broker and manager as private modules, so pub(super) compiles. AGENTS.md requires the most restrictive visibility that compiles."
  • Not listed, it names no trigger that happens in realistic use: "Catch-up ticks may count scheduler delay as peer silence" (warning): "warning, with no realistic trigger. The interval at manager.rs:684 sets no missed-tick policy. If ticks burst after a delay, the first update takes all the bytes and the rest see none, so each adds a stall tick (manager.rs:623-624) when only one peer owes and the link is not judged silent. Reaching the 8-tick threshold needs the controller task to be held up for about 2 s. Nothing in normal use is shown to produce that, and the flag clears on the next delivering tick.
    Refutation confirmed: The interval at manager.rs:684 never sets a missed-tick policy, and Burst is tokio's default. So after a delay, the first catch-up tick takes in all the bytes that arrived meanwhile. The later catch-up ticks see none, and when only one peer owes work, each adds a stall tick. Reaching HEDGE_AFTER (2 s, or 8 ticks of 250 ms) takes the controller being held up about 2.25 s. I found nothing in normal use shown to cause that. The only effect is the peer ranking behind delivering peers in choose_peer,... Rule checked: A tokio Interval defaults to MissedTickBehavior::Burst, so ticks missed while the task was held up fire back to back with no time between them for new bytes to arrive.
  • Premise "The flow controller's tokio::time::interval(FLOW_TICK) at manager.rs:684 keeps tokio's default MissedTickBehavior::Burst, so ticks missed during a delay fire back to back" confirmed. manager.rs:684 calls tokio::time::interval(FLOW_TICK) and no file sets a MissedTickBehavior, so the Interval gets MissedTickBehavior::default(). In the tokio version read (1.54.1, picked for the 1.32 requirement because no lockfile is committed), that default is documented and implemented as Burst.
    Pair refutation confirmed: The first catch-up update records the accumulated bytes; later updates with no new bytes can count toward the eight-tick stall threshold because one owing peer does not trip the link-silence guard. The stall can affect routing until the next delivering tick, but I did not find a normal-use path that delays the controller long enough while work remains outstanding. Rule checked: A timer that replays overdue ticks can run several updates without waiting a full period between byte samples.
  • Premise "The flow controller's tokio::time::interval(FLOW_TICK) at manager.rs:684 keeps tokio's default MissedTickBehavior::Burst, so ticks missed during a delay fire back to back" confirmed. The controller leaves the missed-tick policy unset, and Tokio 1.54.1—the fresh resolution, since no committed lockfile pins Tokio—defaults to Burst and replays overdue ticks without a full-period wait."
  • Not listed, on code an earlier round reviewed: "An outage of our own link still marks a lone owing peer stalled" (suggestion): "note. link_silent needs two owing peers (manager.rs:1098), and the timeout monitor sees a link stall only after the request timeout (manager.rs:228-229). So with one owing peer, a dead link adds stall ticks (manager.rs:623-624). The comment at manager.rs:612 says a tick of our own link's stall adds nothing to a stall, which overstates the code. The routing cost is negligible: during the outage every other peer sits behind the same dead link, and the flag clears with the first delivering tick. What remains is a comment that misstates the code."
  • Dropped: "A reply charge that is never settled can leave a healthy peer flagged as stalled" (ignore): "ignore. This is the settled P3 problem, already answered in its review thread and tracked in fix(dash-spv): release the charge of a request the broker gave up on #1574. Neither the reset at manager.rs:621 nor the requeue in Broker::expire (broker.rs:305-319) changed since that answer."

Timing:

  • Parse: 10.5s
  • Review agents: 387.8s
  • Judge: 302.2s
  • Total: 700.5s

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

  • Check approval

What this does: A peer that owes data but has gone almost silent kept its old speed figures, so the router could still pick it for new block, header or filter requests and for backup copies. Such peers are now flagged as stalled and passed over while another peer can take the work.


1 suggestion · not blocking
✨ A bursty healthy connection can keep a silent peer ranked highly beyond two seconds
Suggestion, not blocking · Pre-existing · Correctness · Moderate · dash-spv/src/network/manager.rs:623

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

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

Why: When two peers owe replies, the controller calls every 250 ms interval without incoming bytes a local link stall. If one peer is silent and the other returns blocks or filter data in bursts about once a second, the silent peer earns only one stall tick per burst and can keep its old rank for about eight seconds instead of two. New requests can still queue behind that peer during the delay.

How to fix it
Use recent activity to distinguish an intermittent but working link from a sustained outage when measuring peer stalls. Keep the per-tick silence signal for cap protection, but do not use it alone to stop the peer stall clock.

  • Create an issue for this

📌 1 follow-up agreed for later

Agreed in their threads as later work. None of them blocks.

  • dash-spv/src/network/manager.rs:621: A request the broker gave up on keeps its peer flagged stalled whenever it goes quiet (view thread)

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 several peers and peer_speed and dash_spv::network debug logging enabled, for example cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir>.

  1. Sync normally with several peers. Expect sync speed comparable to before and few or no stalled: log lines.
  2. Freeze one peer mid-sync, for example by blocking its traffic with a firewall rule. Expect a <addr> stalled: owes ... KB debug line after about 2 seconds.
  3. Keep that peer frozen. Expect new block and header requests and hedge copies to go to the other peers, not to the frozen one.
  4. Unblock the peer before the timeout monitor kicks it. Expect a no longer stalled after ...s line once it delivers again.
  5. Drop your own network briefly. Expect no peer to be marked stalled because of the outage.
  6. Edge case: run with a single peer and freeze it. Expect requests still to be routed to it, since a stalled peer is used when it is the only one.
About this review
  • Reviewed d3268c6, round 3
  • 273 changed lines read in 11m 41s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 5.5M in (4.3M from cache) · 96k out · about $7.24 at API prices
  • Runner: self-hosted · started after 17s · peak memory 4.6 GiB of 30.0 GiB
  • How Manki reviews

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 7m 50s

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

Review (behavior · full): 7 findings
    ✅ Claude Opus 5.5 · high: 0 findings (3m 28s)
    ✅ GPT 6.2 Sol · high: 5 findings (3m 38s)
    ✅ Comparisons, related checks, claim checks, pattern checks and fix checks: 19 of 19 done, 1 finding (54s)
    ✅ Second reads: 1 of 1 done, 1 finding (48s)

Judge (2m 38s)
    graded 7 findings: 4 kept · 2 dropped · 1 merged
    dropped, as the finders filed them: 2 warnings
    origin checks: 1 checked
    verdict reader: read the diff (48s)

Posted: 3 findings
    3 suggestions
    not posted: 1 on code an earlier round reviewed

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:

  • Kept: "A routing pass keeps using a peer after it stalls" (suggestion): "warning, unposted without a realistic trigger. live is computed once at broker.rs:333 and reused at broker.rs:358 across the awaited peer.send at broker.rs:363. A stall that begins during a pass could still send that pass's remaining messages to the newly stalled peer. A pass is budget-limited and its small request writes normally finish in far less than one 250 ms flow tick. A peer reaches the stall flag only after 2 s of near-silence. So the window needs the flag to flip during the short pass, which is much shorter than the operations around it. A recovered peer is picked up on the next pass, because the flow controller wakes the broker when a stall ends (manager.rs:716-718). The cost is at most a few requests hedged later, and no realistic trigger is shown."
  • Dropped: "A peer streaming a valid reply below 8 KiB/s loses all new work" (ignore): "ignore. The fixed byte threshold is a deliberate design that the code implements as described: manager.rs:481-483 and 610-614 flag a peer owing replies that delivers under 8 KB/s for HEDGE_AFTER. The PR states that such a peer then takes no work while any other peer is not stalled, even when every delivering peer is at its cap. Project memory records the maintainers' decision to keep the byte threshold over reply-progress tracking, because the ledger sees a block only once it is whole. Ranking a 7 KB/s peer behind delivering peers is the intended behaviour, not a defect."
  • Kept: "The no-send tests accept a broken frame recorder as evidence of no traffic" (suggestion): "note. The recorder loop at peer.rs:493 ends on a decode error. Feeder::received at manager.rs:1719 treats a closed inbox the same as an empty one. A recorder that broke would therefore let the cases expecting 0 pass. The sibling cases expecting peer 1 or 2 use the same recorder, so they would fail on a broken decoder. That makes this a robustness point about how the test is built, not a test that cannot fail on a revert."
  • Not listed, on code an earlier round reviewed: "The stall tests duplicate the broker's request builders" (suggestion): "note. manager.rs:1629 adds a get_block identical to broker.rs:828. manager.rs:1633 adds get_headers(), a fixed-locator copy of get_headers(locator) at broker.rs:793. The rule in AGENTS.md asks to extend an existing helper rather than write a near copy. No runtime damage follows, so this is the improvement row."
  • Dropped: "Missed flow ticks may age a stall without two seconds of observed silence" (ignore): "ignore. A burst of catch-up ticks needs the flow controller task to be starved for about 2 s. Even then, the false flag clears on the next real tick in which the peer delivers 2 KB, because manager.rs:611-612 reset stalled_ticks on delivery. The cost is at most one tick of misranking, which nobody would notice. That is a note-level point resting on interval settings not shown, so it is dropped."
  • Kept: "The router's comment on an empty routing pass no longer matches when it happens" (suggestion): "note. broker.rs:333-334 now sum budget over delivering_first peers only. route therefore also returns 0 while stalled peers still have room. The flow controller's new broker.wake() at manager.rs:716-718 is a wake source the comment does not name. The comment at manager.rs:454 says every peer is at its cap, which this PR made untrue, so it breaks the AGENTS.md rule to fix such comments. Behaviour is right, so this is a comment that misstates the code."

Timing:

  • Parse: 6.2s
  • Review agents: 306.3s
  • Judge: 157.7s
  • Total: 470.1s

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

  • Check approval

What this does: A peer that owes replies but has stopped delivering could still receive new requests and hedge copies, because it kept the rate and cap it had before. Such a peer is now marked stalled and gets new work only when every peer is stalled.


2 suggestions · not blocking
✨ A routing pass keeps using a peer after it stalls
Suggestion, not blocking · Performance · Quick fix · dash-spv/src/network/broker.rs:358

Tracked in #1237.

Why: route selects the non-stalled peers once, then reuses that list across awaited writes. If a socket write waits while the flow controller marks a peer stalled, the remaining batch can still go to that peer even though another peer is delivering. The reverse also happens: a recovered peer stays excluded until the next pass.

// `peers` can be a snapshot taken before the timeout monitor closed one of them.
let open =
live.iter().copied().filter(|p| !p.is_closed() && p.in_flight_bytes() < p.cap());
let Some(peer) = choose_peer(open, classify(&msg)) else {
unsent.push((height, msg));

How to fix it
Use the initial peer set to size the batch, but refresh eligibility before each send or whenever the flow controller publishes a stall transition. Put unsent messages back when no currently eligible peer has room.

Checked in the code
On the flagged line: Rechecks only !p.is_closed() && p.in_flight_bytes() < p.cap() on the saved list

Computes live before any writes

// goes back to the queue and wakes the router again at once.
let live = delivering_first(peers.iter().filter(|p| !p.is_closed()));
let budget: u64 = live.iter().map(|p| p.cap().saturating_sub(p.in_flight_bytes())).sum();
if budget == 0 {
return 0;

Awaits peer.send(&msg) inside the batch loop

};
if peer.send(&msg).await.is_ok() {
sent += 1;
// Before the next send, which queues behind this request.
let overdue_after = overdue_after(peer);

Lets a write wait for WRITE_TIMEOUT, which is five seconds at line 92

};
let outcome = match tokio::time::timeout(WRITE_TIMEOUT, write).await {
Ok(Ok(())) => Ok(()),
Ok(Err(e)) => Err(format!("Write failed: {}", e)),
// The peer stopped reading; treat it as a failed write.

  • Create an issue for this
✨ The router's comment on an empty routing pass no longer matches when it happens
Suggestion, not blocking · Documentation · Quick fix · dash-spv/src/network/manager.rs:454

Why: The comment says sent == 0 means Every peer is at its in-flight cap. After this change, route also returns 0 when every delivering peer is at its cap and only stalled peers have room, because budget sums delivering_first peers only. The router then also waits for a stall to begin or end (the new broker.wake() in the flow controller), not only for a response or a kicked peer.

How to fix it
Reword the comment to say that every peer that may take work is at its cap, and that a stall beginning or ending also wakes the router.

-                // Every peer is at its in-flight cap: wait for a response or a kicked peer to free
+                // Every peer that may take work is at its cap: wait for a response, a kicked peer or a stall that begins or ends (all notify). The sleep is only a backstop against a missed wake.

Repository rule
This PR breaks a required rule of AGENTS.md: When your change makes a nearby comment untrue, fix that comment.

Checked in the code
On the flagged line: if sent == 0 { // Every peer is at its in-flight cap: wait for a response or a kicked peer to free a slot (both notify)

let live = delivering_first(...) and budget summed over live, if budget == 0 { return 0; }, so stalled peers' room no longer counts

// goes back to the queue and wakes the router again at once.
let live = delivering_first(peers.iter().filter(|p| !p.is_closed()));
let budget: u64 = live.iter().map(|p| p.cap().saturating_sub(p.in_flight_bytes())).sum();
if budget == 0 {
return 0;

if stalls_changed { state.broker.wake(); } is a new wake source the comment leaves out

// Stalls decide which peers may take work, so queued work may fit now.
if stalls_changed {
state.broker.wake();
}

  • Create an issue for this

📌 1 follow-up agreed for later

Agreed in their threads as later work. None of them blocks.

  • dash-spv/src/network/manager.rs: A request the broker gave up on keeps its peer flagged stalled whenever it goes quiet (view thread)

What to test

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

Setup: Run the client against testnet with RUST_LOG=dash_spv::network=debug, enough peers for comparison (for example max_peers 3) and filters enabled.

  1. Sync filters and blocks normally. Expect occasional stalled: owes ... KB and no longer stalled after ... debug lines, and no drop in overall throughput.
  2. Freeze one peer mid-reply, for example by firewalling its inbound traffic for a few seconds. Expect its stalled line after about 2 s and no new getdata or getcfilters routed to it while the other peers deliver.
  3. With that peer frozen, check the hedged filter batch and endgame: hedged block lines. Expect the copies to go to peers other than the frozen one.
  4. Unfreeze the peer before the 10 s request timeout. Expect no longer stalled and new work routed to it again.
  5. Run with a single peer and freeze it briefly. Expect requests still to be routed to it, since a stalled peer is used when every peer is stalled.
  6. Drop the whole network link for several seconds. Expect no new stalled lines for peers that were not already flagged before the outage.
About this review
  • Reviewed c765f5a, round 4
  • 348 changed lines read in 7m 50s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 4.2M in (3.2M from cache) · 81k out · about $6.10 at API prices
  • Runner: self-hosted · started after 8s · peak memory 6.4 GiB of 30.0 GiB
  • How Manki reviews

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

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 9m 37s

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

Review (behavior · full): 11 findings
    ✅ Claude Opus 5.5 · high: 1 finding (3m 7s)
    ✅ GPT 6.2 Sol · high: 8 findings (3m 15s)
    ✅ Comparisons, related checks, claim checks, pattern checks and fix checks: 15 of 15 done, 2 findings (1m 31s)

Judge (4m 36s)
    graded 11 findings: 6 kept · 4 dropped · 1 merged
    dropped, as the finders filed them: 4 warnings
    refuter: 1 checked · 1 confirmed
    origin checks: 2 checked
    verdict reader: read the diff (44s)

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

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

Judge decisions:

  • Dropped: "A peer left with a charge for a request it will never answer is stalled for good and gets no more work" (ignore): "ignore. This is the settled P3 and is marked Already answered: the stuck charge is tracked in dash-spv: Ledger charges leak on retries without a kick and starve healthy peers #1232. The stall test at dash-spv/src/network/manager.rs:610-615 and the requeue at broker.rs:319 are unchanged since that answer, so nothing at this spot got worse."
  • Not listed, on code an earlier round reviewed: "A full peer prevents a hedge from using the only peer with room" (suggestion): "note. The behaviour is real. At dash-spv/src/network/broker.rs:427-429, delivering_first drops stalled peers before the cap filter runs, so a full delivering peer rules out a stalled peer that has room. It is also chosen. The PR description says work waits for a delivering peer even when every delivering peer is at its cap. The test case a peer answering next to nothing gets no copy while the delivering one is full => 0 at manager.rs encodes this outcome. This is intended but surprising behaviour, so the question is whether a stalled peer that still answers should take a due hedge when it is the only candidate with room."
  • Not listed, it names no trigger that happens in realistic use: "A routing pass keeps sending to a peer after it stalls" (warning): "note. This matches P5, and broker.rs did not change since that round, so its cell stays degraded/normal. live is computed once at dash-spv/src/network/broker.rs:333 and reused at :358. A peer that crosses the stall line during one pass can still take later messages of that batch. The trigger needs the stall flag to flip inside a single routing pass, a window much shorter than the 2 s stall threshold. The next wake recomputes live, so no realistic trigger is named and trigger stays empty."
  • Kept: "Quiet gaps between healthy replies keep frozen peers eligible" (suggestion): "warning. This is P4, and the earlier check confirmed its trigger. link_silent at dash-spv/src/network/manager.rs:1096-1104 returns true whenever at least two peers owe and none delivered in the tick. Two frozen peers that owe replies satisfy that on every tick in which the healthy peer is between bursts. link_looks_stalled (:231) is then passed to update at :713, and stalled_ticks only grows on !link_stalled (:613). So the frozen peers gain one stall tick only on ticks in which the healthy peer delivers. That can take several times HEDGE_AFTER, and meanwhile choose_peer still ranks them by the rates they earned before (broker.rs:594). This is the slow rerouting the PR sets out to fix.
    Refutation confirmed: The mechanism holds in code: with two frozen owing peers, every quiet 250 ms tick of the third peer counts as a link stall, so the frozen peers gain stall ticks only on ticks where the healthy peer delivers, and none while it is idle. But the timeout monitor separately flags peers whose bytes stay frozen past REQUEST_TIMEOUT (10 s) for removal, and hedging runs on last_answer regardless of the stall flag. So the visible effect is a bounded delay (about 2 s becoming up to roughly 10 s, if quiet t... Rule checked: A tick counted as our own link's stall adds nothing to a peer's stall count, and link_silent calls a tick silent whenever at least two peers owe and nobody delivered in that one tick, ignoring recent deliveries by other peers.
  • Premise "This trigger happens in realistic use: when two peers freeze while owing replies and the remaining peer delivers in bursts more than 250 ms apart" confirmed. On its code part: the default set is three peers, and link_silent returns true on any tick where two peers owe and none delivered, including ticks where the healthy third peer is idle (owes nothing) or between replies. So with two peers frozen while owing, every quiet tick of the healthy peer is silent and adds no stall tick to the frozen peers; whether peers freeze this way is network behaviour the code cannot show.
    Pair refutation confirmed: With two peers still owing replies, each 250 ms sample without incoming bytes is classified as a link stall and adds nothing to either peer's timer. If the third peer delivers in one sample per second, the frozen peers need about eight seconds to accumulate the eight samples required for the two-second cutoff. Rule checked: A stall timer that advances only on samples classified as link-up measures counted samples, not elapsed silence.
  • Premise "This trigger happens in realistic use: when two peers freeze while owing replies and the remaining peer delivers in bursts more than 250 ms apart" confirmed. The three-peer timeout test supplies exactly two silent peers with registered work and a witness whose byte counter grows once per second."
  • Not listed, on code an earlier round reviewed: "The stall timer credits time before a peer owed a reply" (suggestion): "note. Sampling in_flight once per FLOW_TICK (dash-spv/src/network/manager.rs:700, :611-614) makes the stall threshold accurate only to one 250 ms tick, so 1.75 s against a 2 s heuristic. A queue that drains and refills between ticks without 2 KB of delivery is a peer serving under 8 KB/s, which is the deliberate byte threshold. A one-tick error in a heuristic threshold is a cost nobody would notice."
  • Dropped: "A peer steadily streaming a large reply can be marked stalled" (ignore): "ignore. The pure byte-rate threshold at dash-spv/src/network/manager.rs:610 is the maintainers' recorded decision. Project memory says reply progress alone would flag a peer still streaming one big block, because the ledger sees the block only once it is whole. Manki already withdrew the same point in its review thread. A peer delivering under 8 KB/s is stalled by that definition."
  • Kept: "The loopback recorder drops the cause of a decode failure" (suggestion): "note. In the test helper at dash-spv/src/network/peer.rs:494, both Some(Err(_)) and None end the recorder. Feeder::received (manager.rs:1725) now panics on the closed inbox, so a broken recorder fails the test, but the panic message lacks the decode error. for_test_reading drops the receiver and now decodes frames instead of draining raw bytes. Every frame is a regtest v1 message from the codec, so nothing in the code shown makes this fail. This is a test-diagnostics improvement only."
  • Not listed, on code an earlier round reviewed: "The routing tests duplicate the broker's request builders" (suggestion): "note. dash-spv/src/network/manager.rs:1630 adds get_block(n), identical to broker.rs:828. manager.rs:1634 adds get_headers(), a fixed-locator copy of broker.rs:793. AGENTS.md requires reusing an existing test helper and extending it with a parameter rather than writing a near copy. Sharing the builders means moving them where both test modules can see them. It harms nothing at run time."
  • Dropped: "Catch-up flow ticks may turn a local scheduler pause into a peer stall" (ignore): "ignore. Burst catch-up ticks could add stall ticks only after the runtime paused for more than about 2 s, with exactly one peer owing. Even then, the flag clears on the first tick of real delivery (dash-spv/src/network/manager.rs:611-612), so the peer loses its rank for about one tick. That is a note-level cost on a path the code shown does not settle, so it is dropped."
  • Dropped: "A hedge copy can go to a stalled peer while a delivering peer is open" (ignore): "ignore. A peer that answering (dash-spv/src/network/broker.rs:532) leaves out is no hedge candidate, so the description's claim, that hedges skip a stalled peer whenever another candidate is available, holds. The proposed reorder would not move the copy to the streaming peer either. answering would still drop that peer, leaving no hedge at all. Whether no copy beats a copy to a stalled peer that still answers is a design choice, not a defect shown in the code."

Timing:

  • Parse: 10.5s
  • Review agents: 290.4s
  • Judge: 275.6s
  • Total: 576.5s

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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

@xdustinface
xdustinface force-pushed the fix/stalled-peer-last branch from b32a034 to 4e3eda1 Compare December 2, 2026 18:56
@github-actions github-actions Bot removed the merge-conflict The PR conflicts with the target branch. label Dec 2, 2026
@manki-review

manki-review Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

✅ Review complete in 11m 55s

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

Review (behavior · full): 14 findings
    ✅ Claude Opus 5.5 · high: 4 findings (4m 16s)
    ✅ GPT 6.2 Sol · high: 7 findings (2m 57s)
    ✅ Comparisons, related checks, claim checks, pattern checks and fix checks: 18 of 18 done, 2 findings (1m 31s)
    ✅ Second reads: 1 of 1 done, 1 finding (1m 2s)

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

Posted: 3 findings
    3 suggestions
    not posted: 2 older than this PR · 2 on code an earlier round reviewed · 1 listed by an earlier round · 2 over the review.notes limit

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 69% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 0% (resets 2026-12-09 07:04 UTC)

Judge decisions:

  • Not listed, over the review.notes limit: "Hedges skip a stalled peer even when the only delivering peer has no room, which the description does not say" (suggestion): "note. The behaviour is deliberate. At broker.rs:426-429, delivering_first runs before the room filter. The test case a peer answering next to nothing gets no copy while the delivering one is full expects 0. This matches routing, where work also waits for a delivering peer. The description's phrase "whenever another candidate is available" can be read as including a full peer, so this is a wording question about the chosen behaviour, not a defect."
  • Not listed, listed by an earlier round: "The router comment says every peer is at its cap, but stalled peers can now have room" (suggestion): "note. The comment at manager.rs:454 still says every peer is at its cap. With this PR, route at broker.rs:333-336 returns 0 when the delivering peers are full, even while stalled peers have room. The comment also omits the new stall wake added at manager.rs:718-719. A comment that misstates the code is the improvement row. The grade is kept from P6."
  • Not listed, over the review.notes limit: "Two new test doc comments are four lines long, over the three-line limit" (suggestion): "note. Both /// blocks above a_stalled_peer_gets_no_new_requests and a_hedge_skips_a_stalled_peer are four lines long, as the diff shows. That breaks the AGENTS.md ceiling of three lines. This is a comment convention only."
  • Kept: "New get_block and get_headers test helpers copy the ones in the broker tests" (suggestion): "note. manager.rs:1642-1651 adds get_block and a fixed-locator get_headers. These are near copies of broker.rs:828 and broker.rs:793, which the AGENTS.md reuse rule forbids. Sharing them means moving the helpers out of the private broker test module. This is a structure point with no runtime effect."
  • Not listed, on code this PR did not change: "A routing pass keeps sending to a peer after it stalls" (warning): "note. The code at that spot is unchanged since round 7, so the cell is kept from P8. live is a snapshot taken at broker.rs:333 and reused at broker.rs:358 across the awaits at broker.rs:363. For this to matter, a peer has to cross the 2 s stall threshold in the middle of a single routing pass that only sends to peers with room. No realistic sequence of events produces that, so the trigger is left empty."
  • Not listed, on code an earlier round reviewed: "Backpressured queued work suppresses an available block hedge" (suggestion): "note. The mechanics are right. When the only delivering peer is full, route leaves the queue non-empty (broker.rs:333-336), and the hedger only calls hedge when broker.len() == 0 (manager.rs:809). The hedge this blocks would go to a stalled peer, since every other candidate is stalled. The block it would copy sits on a peer that is still delivering. Holding work for a delivering peer is the PR's stated design, so this is a question about that choice, not a defect."
  • Dropped: "A healthy peer streaming below 8 KiB/s is excluded from routing" (ignore): "ignore. Project memory records the fixed byte threshold as the maintainers' deliberate choice. Tracking reply progress instead would flag a peer still streaming a large block, because the ledger only sees a reply once it is complete. Manki already withdrew the same concern in a thread (Finding 13). A flagged peer is only ranked last, and routing falls back to every peer once all are stalled, so no work is lost."
  • Not listed, on code this PR did not change: "A stalled filter hedge prevents a healthier peer from taking a copy" (warning): "warning. answering keeps any peer with silent_for < HEDGE_AFTER (broker.rs:532), and any cfilter that matches an awaited batch refreshes last_answer (costs.rs:236). So a stalled peer that trickles small filters still counts as answering. If it holds a copy, broker.rs:466 rejects the batch before delivering_first at broker.rs:473 is ever reached. The lowest filter batch then waits on the stalled peer until its timeout, even though this PR's own fix would pick a delivering peer for a new copy. This is a sibling path of that fix, in a file the PR changes.
    Refutation confirmed: The code works as the finding says: a peer still sending small replies at least every 2 s stays answering even when it is stalled, and broker.rs:466 then rejects the batch before delivering_first is reached. But the only effect is a delay. The original holder is still kicked and its batch re-queued after the 10 s request timeout, or else it keeps delivering, so the lowest batch waits longer but nothing is lost or wrong. Rule checked: In hedge_filters, any copy holder whose ledger got an awaited reply within HEDGE_AFTER counts as answering and blocks a further copy, whether or not the flow controller has marked it stalled for delivering under 8 KB/s.
  • Premise "This trigger happens in realistic use: When a filter batch's copy sits on a peer that has stalled but still trickles small cfilter messages, and a delivering peer is free to take a copy" confirmed. Only the code part can be read here. A peer is stalled when it owes replies and gets under 8 KB/s for HEDGE_AFTER, and it is answering when any awaited reply refreshed last_answer within HEDGE_AFTER, so a peer sending a small cfilter every second or so is both. A copy can sit on such a peer when it was picked before it stalled, or when every peer was stalled. While it holds the copy, line 466 blocks a new copy even if a delivering peer is free. Whether real peers send replies that slowly is netw...
    Pair refutation confirmed: A non-stop CFilter refreshes the hedge peer's answer clock without clearing its pending batch or its throughput-based stall flag. The broker therefore rejects the overdue batch before it can consider the healthier peer. Rule checked: A batch rejected by an iterator's filter never reaches the later peer-selection step, even if that step would exclude the peer that caused the rejection.
  • Premise "This trigger happens in realistic use: When a filter batch's copy sits on a peer that has stalled but still trickles small cfilter messages, and a delivering peer is free to take a copy" confirmed. The ordinary hedge path records a copy before its holder slows down, the loopback tests supply below-threshold filter traffic that keeps the answer clock fresh, and the periodic hedger can see another peer resume delivery while that copy remains outstanding."
  • Dropped: "The first sample counts time before the peer owed a reply" (ignore): "ignore. This finding is marked already answered, and the code at manager.rs:613-616 and 652-653 has not changed since that answer. The open thread on the same lines still tracks it."
  • Not listed, on code an earlier round reviewed: "Catch-up ticks may count time with no fresh delivery samples as a stall" (suggestion): "note. With burst catch-up, the ticks after a pause of 2 s or more in the controller task would see no new bytes and push stalled_ticks up (manager.rs:613-616). Such a pause is the state this needs, and only a scheduling stall of the controller's own task produces it. Even then every owing peer is flagged together, so routing falls back to all of them, and the next tick with real delivery clears the flag. The effect is a one-tick blip. The interval setup at manager.rs:687 is not shown.
    Refutation confirmed: The controller does keep Burst. After a pause, the first catch-up tick takes the whole byte delta and the burst ticks after it count as stalled. Reaching the 2 s HEDGE_AFTER threshold needs the controller's own task to be blocked for over 2 s, and nothing found shows normal use doing that. Even then the flag clears on the next tick that sees real delivery, so the effect is a short transient blip. Rule checked: A tokio::time::interval made without set_missed_tick_behavior uses MissedTickBehavior::Burst, so after a pause it fires every missed tick back to back.
  • Premise "The flow controller's time::interval(FLOW_TICK) keeps tokio's default MissedTickBehavior::Burst" confirmed. manager.rs:687 calls tokio::time::interval(FLOW_TICK) and never calls set_missed_tick_behavior anywhere in dash-spv/src. Tokio's interval starts from MissedTickBehavior::default(), which is Burst.
    Pair refutation confirmed: Tokio’s paused-clock test shows multiple overdue ticks ready after one clock advance, and the controller can count eight unchanged byte readings after the first tick consumes the accumulated delta. I did not run a controller test or find a normal-use path that causes the required pause; the next qualifying delivery clears the flag, and routing falls back to all candidates if all are flagged. Rule checked: A Tokio interval using Burst replays overdue ticks without waiting a full period between them, so one tick does not necessarily represent one fresh sampling interval.
  • Premise "The flow controller's time::interval(FLOW_TICK) keeps tokio's default MissedTickBehavior::Burst" confirmed. The controller never overrides the interval policy, and Tokio 1.54.1, the fresh resolution because the PR commits no lockfile, initializes it to Burst."
  • Kept: "The block hedge goes to a stalled peer while a delivering peer is open but mid-reply" (warning): "warning. last_answer is set only when a whole message arrives (costs.rs:250), so silent_for (costs.rs:196) counts a peer streaming a large block as silent. answering then drops it at broker.rs:532. delivering_first at broker.rs:427 only sees the stalled peers that remain, and falls back to them at broker.rs:579-580. The block's single hedge goes to a stalled peer, and broker.rs:423 refuses any further hedge, so the block waits on two slow peers until its timeout. The stall rank this PR adds is applied after the filter that removed the delivering peer.
    Refutation unsettled: The code does what the finding says: a peer still streaming a big block counts as silent and is removed (costs.rs:196, broker.rs:532), and when only stalled peers remain they all come back (broker.rs:580). But the base code did the same: it called hedge_peer on answering without the delivering peer, so this PR does not change the result in this scenario. The trigger also needs every other non-carrier peer to be stalled and still answering at once. A stalled peer must owe bytes and deliver unde... Rule checked: answering() keeps only peers that finished an awaited reply in the last 2 s or owe nothing, and delivering_first falls back to every peer it is given when all of them are stalled.
  • Premise "This trigger happens in realistic use: When the lowest block is overdue, the only delivering peer has been streaming a large reply for over 2 s, and the other peers are stalled but trickle small replies" unsettled. Code alone cannot say whether this situation occurs in real use. The streaming peer is dropped, since last_answer is set only when a whole reply arrives (costs.rs:196, 250; broker.rs:532). But at the 250 ms tick when the lowest block first becomes overdue (manager.rs:798, 810), every other non-carrier peer must also owe bytes and deliver under 8 KB per tick for 2 s (manager.rs:609-616, 653) while having finished a reply within 2 s (broker.rs:532). Peers that owe nothing are never stalled and w...
    Pair refutation confirmed: The flow controller counts partial bytes, but the hedge eligibility check counts completed replies. A peer streaming a large reply can therefore be excluded while a stalled peer sending tiny matching filters survives the check and gets the hedge if it has room. Rule checked: A preference applied after a filter cannot recover a candidate that the filter already excluded.
  • Premise "This trigger happens in realistic use: When the lowest block is overdue, the only delivering peer has been streaming a large reply for over 2 s, and the other peers are stalled but trickle small replies" confirmed. On the code side, a partial reply can keep one peer above the delivery threshold for more than two seconds without resetting its reply timer, while complete tiny filters reset another peer's reply timer without clearing its stall flag."
  • Kept: "No test covers the stall check added to hedge_filters" (suggestion): "note. The new hedge test queues only get_block(2) and never checks where a filter batch copy goes. The broker.rs diff adds no tests. Whether some other test fails on reverting line 473 cannot be settled from the code shown, so it is left in ruleUnseen. A missing test is the improvement row."

Timing:

  • Parse: 10.4s
  • Review agents: 409.7s
  • Judge: 295.1s
  • Total: 715.2s

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

  • Check approval

What this does: A peer that owes replies but has sent almost nothing for two seconds kept getting new requests and hedge copies, because its old rate still ranked it well. Such a peer is now flagged as stalled and skipped while another peer is delivering, so requests go to peers that answer.


1 suggestion · not blocking
✨ The block hedge goes to a stalled peer while a delivering peer is open but mid-reply
Suggestion, not blocking · Pre-existing · Performance · Moderate · dash-spv/src/network/broker.rs:427

The same problem remains here. This PR fixes it at dash-spv/src/network/broker.rs:333 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:420, so it doesn't block this PR.

Why: delivering_first sees only the peers answering kept. A peer streaming a large block at full speed has not finished a reply for 2 s, so answering removes it although it is not stalled. If the only other candidates trickle tiny replies, they count as stalled, the fallback picks one of them, and the lowest block's one hedge goes to that peer. Line 423 then refuses any further hedge for that block, so it stays stuck until the timeout reassigns it.

How to fix it
Apply the stall filter before answering drops anything: compute whether any open, non-stalled peer exists, and fall back to stalled peers only when there is none. Otherwise skip stalled peers and send no hedge this round.

  • Create an issue for this

2 more suggestions are not listed.


📌 1 follow-up agreed for later

Agreed in their threads as later work. None of them blocks.

  • dash-spv/src/network/manager.rs: A request the broker gave up on keeps its peer flagged stalled whenever it goes quiet (view thread)

What to test

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

Setup: Run the SPV client against several peers, for example testnet with cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir>, with debug logging for dash_spv::network.

  1. Sync from scratch with several peers connected. Expect sync to complete, with occasional stalled: owes ... KB and no longer stalled after ... debug lines.
  2. Freeze one peer mid-sync, for example by pausing its process or dropping its traffic with a firewall rule. Expect a stalled line for it within about 2 s, and new block and header requests going only to the other peers.
  3. Unfreeze that peer before the request timeout. Expect a no longer stalled line and the peer taking new work again.
  4. Briefly cut the client's own network for a few seconds. Expect every owing peer to show as stalled, no peer to be swapped out, and sync to resume once the link is back.
  5. Edge case: connect a single peer and freeze it. Expect requests to stay routed to it, since a peer is skipped only while another is delivering, until the timeout monitor kicks it.
About this review
  • Reviewed 4e3eda1, round 8
  • 374 changed lines read in 11m 55s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 6.9M in (5.6M from cache) · 115k out · about $8.03 at API prices
  • Runner: self-hosted · started after 13s · peak memory 4.2 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/manager.rs Resolved
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 12s

Planner (4s)
    feat · 375 lines · 2 agents
    judge effort: high

Review (behavior · full): 9 findings
    ✅ Claude Opus 5.5 · high: 3 findings (5m 56s)
    ✅ GPT 6.2 Sol · high: 4 findings (3m 58s)
    ✅ Comparisons, related checks, claim checks and pattern checks: 14 of 14 done, 2 findings (1m 32s)

Judge (3m 20s)
    graded 9 findings: 6 kept · 3 dropped
    dropped, as the finders filed them: 1 blocker · 1 warning · 1 suggestion
    origin checks: 2 checked · 1 older than this PR
    verdict reader: read the diff (56s)

Posted: 4 findings
    4 suggestions
    not posted: 1 older than this PR · 1 on code an earlier round reviewed

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 70% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 0% (resets 2026-12-09 07:04 UTC)

Judge decisions:

  • Dropped: "A reply charge that never settles can keep a peer marked stalled, so it gets no more work" (ignore): "ignore. This problem was already answered in its review thread and settled as P3, tracked in dash-spv: Ledger charges leak on retries without a kick and starve healthy peers #1232. The code at dash-spv/src/network/manager.rs:613-617 and the ledger release paths in costs.rs are unchanged since that answer, so nothing at this spot got worse."
  • Kept: "get_cfilters stays duplicated in the manager tests after the other request helpers were shared" (suggestion): "note. dash-spv/src/network/manager.rs:1631-1637 has the same body as dash-spv/src/network/broker.rs:800-806. This push shares get_block and get_headers from broker::tests (manager.rs:1609) but leaves get_cfilters copied in the same test module, so the fix for P11 stops one helper short. This PR did not add the copy, so the reuse rule is not broken by an addition. It is still a cheap cleanup in a file the PR changes."
  • Not listed, on code an earlier round reviewed: "for_test_recording is pub(crate) although pub(super) compiles" (suggestion): "note. The new test helper at dash-spv/src/network/peer.rs:483 sits in network::peer. Its only caller is in network::manager tests, so pub(super) would compile, and the repository rule asks for the most restrictive visibility that compiles. This is visibility hygiene with no runtime effect."
  • Dropped: "Unrelated peer traffic can keep usable peers out of routing" (ignore): "ignore. Project memory records the maintainers' decision that the stall detector counts raw socket bytes on purpose ("The stall detector mistakes socket traffic for reply progress" does not apply). Reply progress alone would flag a peer still streaming a large block, because the ledger settles a reply only once it is whole. Flagging slow replies below 8 KB/s is the same threshold choice answered under Finding 9. The routing outage this finding describes needs the non-answering peer's requests to escape expire, which uses per-request last_progress and last_answer, not raw bytes, so its own timeout still bounds it."
  • Kept: "An alternate at its cap can prevent an overdue request from being hedged" (suggestion): "note. The behaviour is real. dash-spv/src/network/broker.rs:427 applies delivering_first before the cap filter at line 429. A full delivering peer therefore rules out a stalled peer that still answers and has room, and the hedge waits. The author chose this. The test case at dash-spv/src/network/manager.rs:3529 asserts 0 for exactly this setup, and the PR description says work waits for a delivering peer even when every delivering peer is at its cap. As a design question: is waiting better than sending the overdue block to a peer that answers small replies but delivers almost nothing?"
  • Kept: "A routing pass keeps using stall flags after they change" (suggestion): "note. This is the same finding as P8, and the code at dash-spv/src/network/broker.rs:333 and :358 is unchanged, so it keeps its earlier cell. For a flag to change in the middle of one pass, a 250 ms flow tick has to land inside the few awaited sends of a single routing pass. That window is short compared with the operations around it, so no realistic trigger is shown. The next pass, which wake() starts, uses the new flags."
  • Kept: "A peer can be marked stalled before it has owed a reply for two seconds" (suggestion): "note. This is the same finding as P9 and the open thread, and the code is unchanged. dash-spv/src/network/manager.rs:616 charges a whole tick on the first silent sample, and :653 flags the peer at eight ticks. A request sent just before a tick can therefore be flagged up to one tick early, at about 1.75 s instead of 2 s. That keeps the earlier improvement cell."
  • Not listed, on code this PR did not change: "A block's only hedge copy goes to a stalled peer while the carrier is still delivering" (warning): "note. The path is real. dash-spv/src/network/broker.rs:426 removes the carrier before delivering_first at :427. When every other answering peer is stalled, the fallback at :579-580 returns them, and the single hedge allowed by :423 goes to a stalled peer. The block still arrives from the carrier, which is delivering, so the only cost is a later hedge to a peer that starts delivering again. That needs the carrier to stay 10 s on one block while every alternate is stalled, and then a delivering peer to appear before the block lands. No realistic trigger is shown. This is the same kind of gap as P10: a delivering peer left out of the set that delivering_first sees."
  • Dropped: "A reply streaming in below 8 KB/s is flagged as stalled, contrary to the new comment" (ignore): "ignore. This problem was already answered and withdrawn in its review thread: the byte threshold is deliberate. The comment at dash-spv/src/network/manager.rs:481-483 and the check at :609 are unchanged since that answer, so nothing got worse."

Timing:

  • Parse: 7.4s
  • Review agents: 404.2s
  • Judge: 200.1s
  • Total: 611.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. 3 suggestions, none of which block.

Caution

Claude subscription has used 70% of its weekly limit, past the 70% mark. It resets 2026-12-04 01:00 UTC.

Once a limit is used up, reviews on that account stop until it resets.

  • Check approval

What this does: Before, a peer that stopped sending data while it still owed replies could keep receiving new requests and backup copies. The client now marks such a peer stalled after 2 seconds and sends new work and backup copies to peers that are still delivering.


2 suggestions · not blocking
✨ A routing pass keeps using stall flags after they change
Suggestion, not blocking · Concurrency · Moderate · dash-spv/src/network/broker.rs:358

Tracked in #1237.

Why: The router snapshots stall eligibility once, but a pass can wait for socket writes while the flow controller continues to update those flags. During a multi-request pass, work can still go to a newly stalled peer after another peer has recovered, and the recovery notification cannot change the pass already in progress.

// `peers` can be a snapshot taken before the timeout monitor closed one of them.
let open =
live.iter().copied().filter(|p| !p.is_closed() && p.in_flight_bytes() < p.cap());
let Some(peer) = choose_peer(open, classify(&msg)) else {
unsent.push((height, msg));

How to fix it
Recompute the preferred set from the open peers before assigning each queued message, not just when calculating the initial budget. Keep the initial budget as a bound on the pass and requeue the remainder if no currently eligible peer has room.

Checked in the code
On the flagged line: Rechecks closure and capacity against live, but not stall eligibility

Builds live once using delivering_first

// goes back to the queue and wakes the router again at once.
let live = delivering_first(peers.iter().filter(|p| !p.is_closed()));
let budget: u64 = live.iter().map(|p| p.cap().saturating_sub(p.in_flight_bytes())).sum();
if budget == 0 {
return 0;

Awaits peer.send(&msg) inside the routing loop

};
if peer.send(&msg).await.is_ok() {
sent += 1;
// Before the next send, which queues behind this request.
let overdue_after = overdue_after(peer);

Waits for the writer lock and the socket write, with WRITE_TIMEOUT applied at line 357

let write = async {
let mut writer = self.writer.lock().await;
// Charged under the writer lock, since filter replies settle in the order their
// requests are written.
self.ledger.charge(&msg).await;

  • Create an issue for this
✨ get_cfilters stays duplicated in the manager tests after the other request helpers were shared
Suggestion, not blocking · Maintainability · Quick fix · dash-spv/src/network/manager.rs:1631

Why: The PR now imports get_block and get_headers from broker::tests. Its new so it does for a filter batch case still uses the manager's own get_cfilters, which is identical to broker.rs:800.

use tokio_util::codec::FramedRead;
fn get_cfilters(start: u32) -> NetworkMessage {
NetworkMessage::GetCFilters(GetCFilters {
filter_type: 0,

How to fix it
Make get_cfilters in broker::tests pub(crate) and import it with the other two helpers. Then delete the copy at manager.rs:1631.

Checked in the code
On the flagged line: fn get_cfilters(start: u32) builds GetCFilters { filter_type: 0, start_height: start, stop_hash: BlockHash::dummy(start) }

Has the same body

fn get_cfilters(start: u32) -> NetworkMessage {
NetworkMessage::GetCFilters(GetCFilters {
filter_type: 0,
start_height: start,

use crate::network::broker::tests::{get_block, get_headers};

use crate::client::ClientConfig;
use crate::network::broker::tests::{get_block, get_headers};
use crate::network::peer::build_version;
use crate::test_utils::test_socket_address;
use dashcore::consensus::encode::{self, serialize};

  • Create an issue for this

📌 1 follow-up agreed for later

Agreed in their threads as later work. None of them blocks.

  • dash-spv/src/network/manager.rs: A request the broker gave up on keeps its peer flagged stalled whenever it goes quiet (view thread)

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 several peers and debug logging for dash_spv::network, for example cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir>.

  1. Sync filters from scratch. Expect the sync to finish with occasional stalled: owes ... KB lines, each followed by a matching no longer stalled after ... line or a kick.
  2. Pause one peer's traffic mid-sync, for example by firewalling its address. Expect a stalled line for it within about 2 s, new requests going to the other peers, and a kick after the request timeout.
  3. Lift the block before the kick. Expect no longer stalled and the peer getting new requests again.
  4. Drop the client's own network for about 20 s mid-sync. Expect every owing peer to be logged as stalled, no peer banned, and the sync to resume once the link is back.
  5. Edge case: run with max_peers set to 1 and stall that peer. Expect requests still sent to it, because every peer is stalled.
About this review
  • Reviewed a650726, round 9
  • 375 changed lines read in 10m 12s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 4.8M in (3.9M from cache) · 92k out · about $6.07 at API prices
  • Runner: self-hosted · started after 8s · peak memory 4.7 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/broker.rs Resolved
@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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

A peer that stopped delivering kept the rates it had earned, so shortest-queue routing kept picking it. In a mainnet run one peer serving 2 to 3 MB/s stalled with blocks owed, received 51 more block requests within 4 s, and each was hedged after 10 s. A peer owing less than its cap is not serving all it can, so its served rate and cap stay where they were and keep its queue looking short.

A peer that owes replies and delivers under 8 KB/s for `HEDGE_AFTER` is now stalled, and routing picks a stalled peer only when every candidate is stalled. The flag clears with the first tick of real delivery, so a fast peer computing one reply for less than `HEDGE_AFTER` keeps its rank, and one still streaming a big reply is never flagged. A tick in which our own link stalled neither adds to a stall nor ends it.
The test ticked its own `PeerFlow` pair and passed each peer's cap as its in-flight bytes during bulk download, a state the ledger never held. It now fills both peers to their caps with real requests through `feed`, answers every batch, and lets the running flow controller flag the stall before the router picks a peer. Our link's stall comes from a tick in which no peer delivers, as in production.
A tick in which our own link stalled still ends a stall when the peer delivered or owes nothing, which is right, so the doc no longer claims it never does.
The stall test built its peers through bulk download and then answered every batch inline. A hedge test needs the same start, so the setup moves into a helper, together with the framed bulk filter and batch answer it sends.
A peer flagged stalled that still settled a small reply in the last `HEDGE_AFTER` passes the hedge silence check. `hedge_peer` then ranked it by the rate it had before the stall, so a peer trickling tiny filters could win a second copy over a healthy one. Hedges now pick from the non-stalled candidates whenever one exists, through the same `delivering_first` that routing uses.
The stall counter lived in `PeerFlow::update`, which needs a live peer, while the cap and rates are worked out in the numeric `tick`. It now sits in `tick` beside them, and `update` only publishes and logs.
The stall and hedge tests queued their requests on the broker directly and read the carrier from its registry. They now queue through `NetworkManager::enqueue` and watch which peer's far end receives the request, through a loopback peer that records what its far end reads. The test-only `hedges_of` accessor goes with it.
`route` dropped full peers before it looked at the stall flag, and it counted a stalled peer's room in its budget. In bulk download every delivering peer sits at its cap, so the overflow went to the stalled peer up to the cap it had earned, the incident this branch set out to stop. A stalled peer that owes less than `MIN_CAP_BYTES` is never serving all it can, so that cap does not even shrink.

The stall rule now applies to every open peer before the cap check, in routing and in both hedges. While any open peer is not stalled, a stalled peer adds nothing to the budget and takes no request, so the work waits for a delivering peer to free room. The flow controller wakes the router when a stall begins or ends, so work held back for a peer that then stalls too goes out within a tick.
The loopback recorder ends on a frame it cannot decode and drops its sender, and `Feeder::received` read a closed inbox like an empty one. A test that expects no peer to receive a request then passed with a broken recorder. A closed inbox now fails the test, so only an empty, live inbox means nothing was sent.
`for_test_reading` wrapped the decoding recorder of `for_test_recording` and dropped its channel. A frame the recorder could not decode stopped the far end from reading, so the peer's writes failed or blocked in tests that never look at what the peer sends. `for_test_reading` drains the far end raw again, as before the recorder existed, and both helpers share the loopback setup in `for_test_link`.
A frame the recorder could not decode ended it silently, and `Feeder::received` only said the recorder stopped. The recorder now sends the decode error through its channel and drains the rest of the socket raw, so the test fails with the cause.
With two or more peers owing, `link_silent` calls any tick in which no peer delivered a stall of our own link, and such ticks added nothing to a peer's stall. Beside a peer that delivers in bursts, a silent peer then gained a stall tick only on the burst ticks. With one burst in four ticks it was flagged after about 8 s instead of `HEDGE_AFTER`, and kept taking new work meanwhile.

Every tick now counts. One tick cannot tell an outage of our own link from a slow peer, and the stall flag only steers routing and hedges, which is safe in a real outage: every owing peer stalls together, `delivering_first` then falls back to every open peer, an idle peer owing nothing stays unflagged and may take work, and each peer clears its flag on its first delivering tick once the link is back. Kicks never read the flag. The per-tick link-silence check still holds the caps and the serving-rate samples.
The manager tests carried their own `get_block` and `get_headers`, the first a copy of the shared builder and the second the broker tests' builder with a fixed locator. `get_headers` moves into `test_utils` beside the other request builders, and both test modules import them.
`a_hedge_skips_a_stalled_peer` only reached `hedge` through a block, so nothing tested that `hedge_filters` puts a stalled peer last. The test now takes the request, and a filter batch case expects its copy to skip the stalled peer. Without `delivering_first` in `hedge_filters` the copy goes to the stalled peer and the case fails.
@xdustinface
xdustinface force-pushed the fix/stalled-peer-last branch from a650726 to 6619f94 Compare December 2, 2026 19:56
@github-actions github-actions Bot removed the merge-conflict The PR conflicts with the target branch. label Dec 2, 2026
@manki-review

manki-review Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Review superseded by the new commit d2e7005. No verdict was posted for 6619f94.

`hedge` and `hedge_filters` ranked stalled peers last before they dropped the peers at their cap. With every delivering alternate at its cap, the stalled alternates with room were already gone, so nothing was hedged at all. The cap now filters first and `delivering_first` ranks what is left, so a stalled peer with room gets the copy when no delivering one has room. The lowest filter batch still ignores the cap.

In `a_hedge_skips_a_stalled_peer` the case with the delivering peer full now expects the copy at the stalled peer instead of no copy.
@manki-review

manki-review Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

✅ Review complete in 9m 44s

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

Review (behavior · full): 8 findings
    ✅ Claude Opus 5.5 · high: 0 findings (3m 53s)
    ✅ GPT 6.2 Sol · high: 6 findings (2m 44s)
    ✅ Comparisons, related checks, claim checks, pattern checks and fix checks: 18 of 18 done, 1 finding (1m 21s)
    ✅ Second reads: 1 of 1 done, 1 finding (1m 6s)

Judge (3m 12s)
    graded 8 findings: 3 kept · 5 dropped
    dropped, as the finders filed them: 2 warnings · 3 suggestions
    origin checks: 2 checked · 1 older than this PR
    verdict reader: read the diff (44s)

Posted: 2 findings
    2 suggestions
    not posted: 1 no realistic trigger

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 70% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 0% (resets 2026-12-09 07:04 UTC)

Judge decisions:

  • Kept: "A routing pass keeps sending to peers that stall mid-pass" (suggestion): "note. This is the same defect as P12 and keeps its cell, because the code at dash-spv/src/network/broker.rs:333 and :358 is unchanged. live is computed once per pass. For a peer to become stalled during the pass, a peer.send at :363 would have to block for most of the two-second stall window while that peer owes replies and delivers nothing. Normal use does not produce that sequence, so there is no realistic trigger, and the next pass uses the new flags because state.broker.wake() runs at manager.rs:719."
  • Not listed, it names no trigger that happens in realistic use: "Queued work can prevent a hedge for the lowest block" (warning): "note. The broker.len() == 0 gate at manager.rs:809 existed before this PR, and the block hedge has always been endgame-only. The change at broker.rs:333 keeps queued blocks away from a stalled peer, so the queue drains through the delivering peer and the endgame hedge fires once it is empty. Before this PR, the queue drained faster only by piling more blocks onto stalled peers. The copy the finding wants would also go to another stalled peer, which delivers under 8 KB/s, so the code gives no sign that anyone would notice the difference. A stuck block still expires and is requeued through the answer timeout."
  • Dropped: "The lowest filter hedge can go behind a full peer's queue" (ignore): "ignore. The lowest batch skips the cap check on purpose, as the comment at broker.rs:470-471 says, because bulk download keeps every peer at its cap. Picking a delivering peer with a queue of about two seconds over a peer that has delivered under 8 KB/s for two seconds is a ranking choice. Nothing in the code shows the stalled peer would answer sooner, and the hedge is never dropped, since a full delivering peer still gets the copy."
  • Kept: "Flow ticks can mark a peer stalled before it has owed a reply for two seconds" (suggestion): "note. The early-flag part is unchanged since P9 and P11 and keeps their improvement cell. manager.rs:616 adds a whole tick per silent sample, and :653 compares FLOW_TICK * stalled_ticks with HEDGE_AFTER. The catch-up part is new. tokio::time::interval at :687 uses the default burst behaviour, so after the task is delayed, the replayed ticks see no new bytes and can raise stalled_ticks to 8 at once. The flag clears on the next tick that counts real delivery at :613, so the demotion lasts about one tick."
  • Dropped: "The stall regressions bypass the public peer setup and send APIs" (ignore): "ignore. The tests set no internal field or state by hand. Peers join through admit at manager.rs:1762. Owed work is charged through the real PeerHandle::send path, which charges the ledger. Bytes arrive over loopback sockets and the running flow controller sets the stall flag. The request whose routing is checked goes through net.enqueue. The maintainers already accepted this feeders harness as the public path for an earlier backlog test."
  • Dropped: "The test helper duplicates the production getheaders constructor" (ignore): "ignore. get_headers already existed in the broker tests, and this PR only moves it into test_utils so both test modules share it. BlockHash::dummy(0) is all zeros, the same value as BlockHash::all_zeros(), so the message matches production. Building it through HeadersRequest instead is a matter of preference."
  • Dropped: "A peer streaming a reply below 8 KB/s is flagged as stalled, which the new comment says cannot happen" (ignore): "ignore. This problem was already answered in its review thread, and the comment and threshold at manager.rs:481-483 and :609 have not changed since that answer."
  • Dropped: "A peer that silently skipped a request is shut out of routing for the rest of the session" (ignore): "ignore. Settled finding P3 names the same failure: a peer left owing a request it will never answer is flagged stalled for good and gets no new work. The reset condition at manager.rs:613 is the same as when that thread was settled. When every peer is stalled, delivering_first also falls back to all of them, so the peer is not fully shut out."

Timing:

  • Parse: 8.8s
  • Review agents: 383.5s
  • Judge: 191.8s
  • Total: 584.0s

Last reviewed d2e7005 · head d2e7005 · up to date

  • Pause automatic reviews
  • Review again
  • Deeper review
  • Review this draft
  • Review every push

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

Caution

Claude subscription has used 70% of its weekly limit, past the 70% mark. It resets 2026-12-04 01:00 UTC.

Once a limit is used up, reviews on that account stop until it resets.

  • Check approval

What this does: Peers that owe replies but deliver almost nothing for 2 seconds are now marked as stalled. New requests and second copies of slow requests go to peers that are still delivering.


1 suggestion · not blocking
✨ A routing pass keeps sending to peers that stall mid-pass
Suggestion, not blocking · Pre-existing · Performance · Moderate · dash-spv/src/network/broker.rs:358

Tracked in #1237.

The same problem remains here. This PR fixes it at dash-spv/src/network/broker.rs:430 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:332, so it doesn't block this PR.

Why: The router chooses the non-stalled peers once, before it awaits the queue and socket writes. If a write waits on a busy socket long enough for the flow controller to mark a peer stalled, the router can still send the rest of the batch to that peer based on its old rate.

How to fix it
Use the initial peer set to estimate the pop budget, but recompute stall eligibility from all currently open peers before each send. Keep the rule that stalled peers are eligible only when every open peer is stalled, and return unsent work to the queue when the eligible peers have no room.

  • Create an issue for this

📌 1 follow-up agreed for later

Agreed in their threads as later work. None of them blocks.

  • dash-spv/src/network/manager.rs: A request the broker gave up on keeps its peer flagged stalled whenever it goes quiet (view thread)

What to test

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

Setup: Run the SPV client against several peers, for example with the CLI on testnet with DASHD_TEST_LOG=1 or a debug log level for dash_spv::network.

  1. Sync filters and blocks from several peers. Expect stalled: owes ... KB and no longer stalled after ... debug lines only for peers that pause, and sync to complete.
  2. Freeze one peer mid-download, for example by pausing its process or dropping its traffic with a firewall rule. Expect it to be logged as stalled within about 2 s and new router: sent work to go to the other peers.
  3. Unfreeze that peer. Expect no longer stalled on its first tick with data and the peer to take new requests again.
  4. With a single connected peer, freeze it briefly. Expect requests to keep routing to it once it delivers again, not to stay queued forever.
  5. Freeze all peers at once, simulating a drop of your own link. Expect queued work to fall back to all peers and sync to resume when the link returns.
  6. Edge case: let a stalled peer hold the lowest block during the endgame while another peer is idle. Expect the endgame: hedged block copy to go to the idle, delivering peer.
About this review
  • Reviewed d2e7005, round 10
  • 381 changed lines read in 9m 44s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 4.1M in (3.0M from cache) · 87k out · about $6.46 at API prices
  • Runner: self-hosted · started after 12s · peak memory 4.6 GiB of 30.0 GiB
  • How Manki reviews

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant