Repository navigation
fix(dash-spv): stop a shared stall from emptying the peer set - #1345
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1345 +/- ##
==========================================
+ Coverage 86.28% 86.39% +0.11%
==========================================
Files 268 270 +2
Lines 70237 70830 +593
==========================================
+ Hits 60601 61194 +593
Misses 9636 9636
|
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
52e040b to
fb93704
Compare
7e7e4a7 to
43d5e8c
Compare
80d80bf to
ca66de7
Compare
761b7d8 to
0467c8c
Compare
ca66de7 to
e89874d
Compare
0467c8c to
2a5a48e
Compare
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
2a5a48e to
78d6190
Compare
e89874d to
5cc69f8
Compare
3b3971d to
a37e9b9
Compare
|
✅ Review complete in 4m 33s Planner (4s) Review (behavior · pair): 4 findings Judge: 3 kept · 0 dropped (1m 30s) Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
|
Bots are done — your move: address manki-review[bot] requested changes; ZocoLini requested changes, then post |
|
/manki review |
|
|
|
✅ Review complete in 13m 56s Planner (5s) Review (behavior · full): 13 findings Judge: 7 kept · 5 dropped (4m 3s) Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
🔴 Changes requested: 2 new blockers, plus 2 warnings and 2 suggestions in threads.
What blocks: The shared queue in #1228 can deliver bytes from one connection every second while other healthy peers' replies are still queued. The judge counts each such tick as proof against those peers, so it can evict and ban them after just over one request timeout even though they never got a chance to deliver.
1 suggestion · not blocking
✨ The main stall tests replace the request path they are meant to verify
Suggestion, not blocking · Testing · Moderate · dash-spv/src/network/manager.rs:1875
Why: The amended timeout tests insert on-wire requests directly, bypassing the router and the peer's byte ledger. The new table tests also reimplement the broker's expiration logic, so they can pass when production sends the judge the wrong timestamp.
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1873 to 1877 in 75128d3
How to fix it
Enqueue requests through NetworkManager::enqueue and let the real router send and charge them over loopback. For judge-only tests, pass explicit culprit inputs rather than copying expiration logic, and verify the broker-to-judge handoff in the network tests.
Repository rule
This PR breaks a required rule of AGENTS.md: Test through the public API. Don't set internal fields or states by hand: a test that builds a state production never reaches proves nothing.
Checked in the code
On the flagged line: Uses broker.mark_on_wire in the amended departure test
Uses broker.mark_on_wire and line 2010 injects a reply directly into the pump
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1979 to 1983 in 75128d3
Uses broker.mark_on_wire in the amended requeue test
rust-dashcore/dash-spv/src/network/manager.rs
Lines 2046 to 2050 in 75128d3
Builds stalled by copying the timeout checks from dash-spv/src/network/broker.rs:253
rust-dashcore/dash-spv/src/network/manager.rs
Lines 2240 to 2244 in 75128d3
dash-spv/src/network/broker.rs:433: Implementsmark_on_wireby insertingReqState::OnWiredirectlydash-spv/src/network/manager.rs:2010:.send(PeerEvent::Message(conn(peer, 0), piece.into()))dash-spv/src/network/manager.rs:2189:in_flight: matches!(role, Role::Charged(_) | Role::Resumes(..) | Role::Flaps(..))dash-spv/src/network/manager.rs:2236:if let Some((_, progress)) = requests.get_mut(&id) {
- Create an issue for this
1 more suggestion is not listed.
Related work: open PRs and issues this PR may duplicate or fix. None of them blocks.
- This PR may fix #1234 dash-spv: a peer whose filter replies wait in our own backlog is kicked as stalled. Add
Closes #1234to the description if it does.
About this review
- Reviewed
75128d3, round 9 - 954 changed lines read in 13m 56s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 3.1M in (2.4M from cache) · 77k out · about $5.32 at API prices, partly priced
- Runner: self-hosted · started after 16s · peak memory 3.5 GiB of 30.0 GiB
- How Manki reviews
| } | ||
| // The cap keeps ticks the monitor ran late from counting an outage as uptime. | ||
| if let Some(last) = self.last_tick.filter(|_| any_grew) { | ||
| self.link_up += now.duration_since(last).min(TIMEOUT_CHECK); |
There was a problem hiding this comment.
🚫 Blocker · Correctness · Larger change
Traffic from one peer can still cause healthy peers to be banned on a congested link
What goes wrong: The shared queue in #1228 can deliver bytes from one connection every second while other healthy peers' replies are still queued. The judge counts each such tick as proof against those peers, so it can evict and ban them after just over one request timeout even though they never got a chance to deliver. Kick pacing spreads out those evictions but does not prevent them.
How to fix it and 21 places read · confirmed with tools
How to fix it
Separate evidence that the link is reachable from evidence that a particular peer had a chance to serve. Use the shared backlog and measured drain rate to defer witnessed kicks and bans while the client's own queue can explain the delay.
Checked in the code
On the commented line: Credits the whole interval up to TIMEOUT_CHECK, regardless of how many bytes arrived
Sets any_grew = true for growth on any connection
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1090 to 1096 in 75128d3
Treats up > p.timeout as sufficient proof against the silent peer
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1167 to 1174 in 75128d3
Exempts only the unwitnessed kick from Ban::Kicked
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1266 to 1271 in 75128d3
dash-spv/src/network/bans.rs:9: SetsKICK_BANto10 * 60secondsdash-spv/src/network/peer.rs:92:pub const INITIAL_CAP_BYTES: u64 = 256 * 1024;dash-spv/src/network/manager.rs:463:const MIN_CAP_BYTES: u64 = INITIAL_CAP_BYTES;dash-spv/src/network/manager.rs:482:const QUEUE_FLOOR_BYTES: f64 = 1024.0 * 1024.0;dash-spv/src/network/manager.rs:576:let bdp = self.rate * self.base_rtt;dash-spv/src/network/manager.rs:578:let high = (bdp * QUEUE_HIGH).max(QUEUE_FLOOR_BYTES);dash-spv/src/network/manager.rs:591:if queued > high {dash-spv/src/network/manager.rs:600:self.cap = self.cap.max(self.min_cap);dash-spv/src/network/manager.rs:698:global.min_cap = (MIN_CAP_BYTES * g.len() as u64) as f64;dash-spv/src/network/manager.rs:699:global.cap = global.cap.max(global.min_cap);dash-spv/src/network/manager.rs:1101:if grew || p.in_flight == 0 {dash-spv/src/network/manager.rs:1106:if let Some(last) = self.last_tick.filter(|_| any_grew) {
Double-checked
Manki tried to disprove this by reading the code and could not. observe() adds up to TIMEOUT_CHECK of link_up on any tick where any peer's counter grew. judge() treats up > p.timeout as a witnessed silence, and the monitor…
- Create an issue for this
There was a problem hiding this comment.
This is real, but this PR does not introduce it. On a bufferbloated link, one peer's bytes can keep arriving while another peer's reply waits behind our own backlog. That is the "queued behind others" symptom of #1228. dev kicks and bans that peer at the same timeout without looking at any other peer, and the judge never kicks earlier than dev does.
The fix is to keep each peer's queue short. #1371, further up this stack, sizes each peer's cap to TARGET_QUEUE_SECS (2 s) of its served rate, so the backlog in front of a reply stays far below the 10 s timeout.
There was a problem hiding this comment.
Agreed. Leaving the bufferbloat case to #1371, which further up the stack keeps each peer's queue short, is fine. Until #1371 lands, this PR still counts traffic from any one peer as uptime at dash-spv/src/network/manager.rs:1106. It then treats that uptime as proof against a silent peer at dash-spv/src/network/manager.rs:1170, so on a congested link a peer whose reply sits in our own queue can still be kicked and banned. TARGET_QUEUE_SECS is not in this checkout, so I can't check how #1371 behaves from here.
Statements of this reply, and what I checked of each:
- Not checked, the review model could not read the code that would show it: "
devkicks and bans that peer at the same timeout without looking at any other peer" - Not checked, the review model could not read the code that would show it: "the judge never kicks earlier than
devdoes"
I could not check every one of these statements. A maintainer has to judge the unchecked ones, and what the statements mean for this finding.
This is a blocking finding, so the thread stays open until someone other than the PR author with write access closes it. A PR author can close it only with the maintain role or a higher one.
| // The router sends a peer work until it reaches its cap or the link cap binds. | ||
| // Short of both, its rate shows how much it was asked for, not its bandwidth. | ||
| let bound = in_flight > 0 && (in_flight >= self.limiter.cap as u64 || link_full); | ||
| let cap = self.limiter.tick(bytes, in_flight, CAP_STEP_BYTES_PER_SEC); |
There was a problem hiding this comment.
Stalled ticks still lower the serving-rate samples used after recovery
What goes wrong: The serving average stops updating during a stall, but its input, self.limiter.rate, keeps decaying on those same ticks. Once the stall clears, that depressed input feeds back into the serving average used for routing and slow-peer swaps. The test checks rates only while the hold is active, not after delivery resumes.
How to fix it and 6 places read · confirmed with tools
How to fix it
Keep a separate serving-rate estimator that uses only non-stalled samples. Advance its byte baseline on skipped ticks so the first sample after recovery neither includes stalled time nor counts stalled bytes twice.
Checked in the code
On the commented line: Runs the limiter before checking !link_stalled
Updates self.rate on every limiter tick, including ticks with zero bytes
rust-dashcore/dash-spv/src/network/manager.rs
Lines 545 to 549 in 75128d3
Adds self.limiter.rate to the serving average
rust-dashcore/dash-spv/src/network/manager.rs
Lines 630 to 637 in 75128d3
Uses peer.serving_rate() to estimate queue time
rust-dashcore/dash-spv/src/network/broker.rs
Lines 461 to 465 in 75128d3
dash-spv/src/network/manager.rs:2281: Checksserving_rates(&net).await == heldonly during silence
Not settled
Manki tried to disprove this by reading the code and could not decide. ByteLimiter::tick updates rate on every tick (546), and PeerFlow::tick only checks the current link_stalled flag (631) before adding limiter.rate to… See dash-spv/src/network/manager.rs:454, dash-spv/src/network/manager.rs:486, dash-spv/src/network/manager.rs:489, dash-spv/src/network/manager.rs:633, dash-spv/src/network/manager.rs:1018, dash-spv/src/network/manager.rs:1020, dash-spv/src/network/manager.rs:546, dash-spv/src/network/manager.rs:628, dash-spv/src/network/manager.rs:631, dash-spv/src/network/manager.rs:634, dash-spv/src/network/manager.rs:1101, dash-spv/src/network/manager.rs:1131, dash-spv/src/network/manager.rs:1243.
- Create an issue for this
| self.link_stalled = held > 0 || waiting.any(|&(_, _, witnessed)| !witnessed); | ||
| // A culprit that already left is not spared, so its requests are still re-queued. | ||
| let mut kicked: HashSet<PeerId> = | ||
| culprits.into_keys().filter(|id| peers.iter().all(|p| p.id != *id)).collect(); |
There was a problem hiding this comment.
✨ Suggestion, not blocking · Correctness · Moderate
A peer that already disconnected can still be banned or consume the kick slot
Why: An expired request whose peer is already absent is added to the kick set for retry, but only the selected live candidate can be marked unwitnessed. This can ban a departed discovered peer's address without any uptime evidence. If the selected candidate leaves between the snapshot and removal, it also consumes the pacing slot even though the monitor did not evict it.
How to fix it and 7 places read
How to fix it
Return departed request carriers separately from the proposed live eviction. Requeue departed carriers without banning them, and apply a ban or advance last_kick only after PeerSet::remove confirms the monitor removed the selected connection.
Checked in the code
On the commented line: Adds absent carriers to kicked, while line 1195 derives unwitnessed only from kick
Sets self.last_kick = Some(now) before removal
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1184 to 1188 in 75128d3
Obtains the peers actually removed but line 1267 bans by iterating culprits instead
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1256 to 1260 in 75128d3
Handles PeerEvent::Disconnected(peer) independently of the monitor
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1439 to 1443 in 75128d3
dash-spv/src/network/peer_set.rs:109: Returns only matching connections still in the setdash-spv/src/network/manager.rs:1195:let unwitnessed = kick.filter(|(_, _, witnessed)| !witnessed).map(|(_, p, _)| p.id);dash-spv/src/network/manager.rs:1267:for peer in culprits.iter().filter(|&&peer| Some(peer) != unwitnessed) {
- Create an issue for this
|
@xdustinface Okey, two things before approving, so we can merge this soon and move on to the stack:
|
The stall judge matrix gave peers holding a registered request no bytes in flight and blamed them with a copy of the rules of `Broker::expire` written into the test, a state production never reaches. The peers now register their requests on a real `Broker`, owe bytes as the router's charge makes them, report streaming progress with `receiving` and are blamed by `expire`, as the timeout monitor does each second on the paused clock. The matrix also drops overlapping cases and keeps one case or one held and kicked pair per rule of the judge. The `Asks` role goes with them: a request sent between ticks is blamed from the tick before by the judge's own byte check, so its case pinned nothing more than a lone silent request.
When both deadlines of a request had passed, `Broker::expire` blamed it from its last progress, not its last answer. A lone peer that streamed part of an answer until second 49 and then stopped was blamed from 49, so the uptime its own bytes proved before that was ignored and the stall judge held it as a possible stall of our link until about 110 s instead of kicking it at the answer bound near 61 s. A request past its answer deadline is now blamed from its last answer whether or not its progress deadline also passed.
The stall judge matrix pinned most rules with a pair of cases, one held at a second and one kicked at the next. Each case now lists every kick with its second and whether it is banned, and the harness records the kicks tick by tick, so a kick one tick early or late fails a single case run to the later second. `link_stalled` is checked at the seconds the held cases checked it. The pairs fold into one case each, and the kept peers and the unbanned column go, since the schedule implies both.
`a_stall_of_our_link_leaves_the_serving_rates_alone` measured two peers, let them go silent and checked that their serving rates drop before the judge holds them and then stay put. `no_slow_peer_is_swapped_out_while_our_link_stalls` already builds that state, so it now checks the rates too, over a longer hold, and the separate test goes.
`HandshakingPeer` built its own `VersionMessage` and kept flags for the accepted connections, a ping after the handshake and the close. It now answers with the client's own `build_version` and the services the client needs, handles one connection at a time and counts only the connections the client closed. A failed handshake shows as the dial ban the client sets, and the swap after recovery shows in the slow peer's handle and the peer count.
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
⏸️ Review incomplete: The judge failed. Retry with /manki review.
About this review
- Reviewed
e790382 - How Manki reviews
Superseded by new review
|
✅ Review complete in 9m 55s Planner (5s) Review (behavior · full): 14 findings Judge: 2 kept · 12 dropped (3m 6s) Review metadataConfig:
Account limits:
Judge decisions:
Timing:
Last reviewed
|
There was a problem hiding this comment.
🔴 Changes requested: 1 blocker still open from an earlier review.
What blocks: The partial-reply deadline is fixed, and the judge test now runs a real Broker. One earlier blocker is still open: any peer's traffic still counts as uptime against a silent peer, so on a congested link a peer whose reply waits in our own queue can still be kicked and banned. A departed connection can also still be banned, and serving-rate sampling restarts while the limiter's rate is still low.
Still open from earlier reviews:
dash-spv/src/network/manager.rs:1107: Traffic from one peer can still cause healthy peers to be banned on a congested link (view thread)
Related work: open PRs and issues this PR may duplicate or fix. None of them blocks.
- This PR may fix #1234 dash-spv: a peer whose filter replies wait in our own backlog is kicked as stalled. Add
Closes #1234to the description if it does.
About this review
- Reviewed
e790382, round 10 - 861 changed lines read in 9m 55s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 2.3M in (1.6M from cache) · 64k out · about $4.80 at API prices, partly priced
- Runner: self-hosted · started after 14s · peak memory 4.1 GiB of 30.0 GiB
- How Manki reviews
…run 44708595407)
Part of #1228.
When the client's own link stalls, every peer goes quiet at once. The timeout monitor judged each peer alone, so one tick could kick the whole set, and peers whose timeouts started a second apart crossed them one at a time and each looked like a lone stall. In 12 testnet runs the set dropped to zero 8 times while the replacements delivered within about 2 s. With a single configured peer, a 30 s outage kicked it.
The monitor now leaves the decision to a
StallJudge, which adds up how long our link provably worked: every tick on which any peer received bytes counts. A silent peer is blamed once our link worked for more than one request timeout of its silence, however pauses and outages split that time, so they never count as proof against it. Bytes received from the silent peer itself count too, so a peer that keeps sending other data but never answers is still blamed. Otherwise the peer is held as a possible stall of our link until more thanLINK_STALL_TIMEOUTSrequest timeouts of its silence (60 s with the base timeout) passed without proof. Silent peers are kicked at most one per timeout, the one silent the longest first, so a stall of our link never takes the whole set at once. A peer kicked only because its hold ran out is not banned, since our link may have failed it. A peer that is really unreachable fails its redial and backs off.While some silent peer lacks that proof, our link counts as stalled. The flow controller then leaves those ticks out of a peer's serving rate, and neither it nor the supervisor names or swaps out an underserving peer. A tick that spares culprits but kicks nobody logs at
debug. A dashd test freezes dashd for 30 s mid-sync and checks that its only peer stays connected.PR Hygiene ·
e790382/skip-botsproceeds without the ones not yet reported/self-reviewedWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.Summary by CodeRabbit