Repository navigation
fix(dash-spv): hedge all filter batches held by silent peers - #1532
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
|
✅ Review complete in 13m 44s Planner (4s) Review (behavior · full): 7 findings Judge (5m 36s) Posted: 3 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
|
Bots are done — your move: post |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1532 +/- ##
==========================================
- Coverage 87.64% 87.63% -0.02%
==========================================
Files 270 270
Lines 71891 71973 +82
==========================================
+ Hits 63009 63073 +64
- Misses 8882 8900 +18
|
There was a problem hiding this comment.
✅ Approved. 3 suggestions, none of which block.
What this does: When peers stop delivering filter batches, the client used to ask a working peer for only one of their batches per tick. Now each tick it asks for every stuck batch the working peer has room for, plus the lowest one regardless of room, so filter sync recovers faster.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Run a filter-syncing client on testnet with several peers and peer_speed and dash_spv::network debug logging enabled.
- Freeze one peer mid filter sync, for example by blocking its traffic with a firewall rule. Expect several
hedged filter batchlines in the same tick, not one per tick. - Keep that peer frozen. Expect each of its batches to be hedged once, not repeatedly every tick.
- Let a healthy peer serve its own batches normally. Expect none of its batches to be hedged while it keeps answering.
- Freeze a peer while a lower filter batch is still queued. Expect no hedge of batches above the queued one.
- Freeze every peer at once. Expect no hedges, since no peer is answering.
About this review
- Reviewed
0d96916, round 1 - 143 changed lines read in 13m 44s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 4.8M in (3.8M from cache) · 97k out · about $6.67 at API prices
- Runner: self-hosted · started after 3m 26s · peak memory 3.5 GiB of 30.0 GiB
- How Manki reviews
| // Sent even while our link looks stalled: two frozen peers look the same, and | ||
| // another peer may be idle only because the batch they owe blocks the store. | ||
| if let Some(height) = broker.hedge_filters(&handles).await { | ||
| while let Some(height) = broker.hedge_filters(&handles).await { |
There was a problem hiding this comment.
✨ Suggestion, not blocking · Reliability · Quick fix
A failed hedge write ends the tick even when other copies are eligible
Why: If a selected peer disconnects or its write fails during a hedge burst, hedge_filters returns the same None as it does when there is no work. The controller stops the burst even if another peer can take that copy or the remaining eligible batches.
How to fix it and 5 places read
How to fix it
Distinguish a failed write from an exhausted candidate list. On failure, exclude that connection for the rest of the bounded pass, clear its failed reservation if it is still present, and continue selecting among the remaining peers.
Checked in the code
On the commented line: Treats every None as the end of the batch pass
- Records the destination with
o.hedge_to(peer)before the write - Converts every send error to
Nonewithpeer.send(&msg).await.ok().map(|()| height)
rust-dashcore/dash-spv/src/network/broker.rs
Lines 454 to 461 in 0d96916
Handles write errors and a five-second WRITE_TIMEOUT
rust-dashcore/dash-spv/src/network/peer.rs
Lines 344 to 348 in 0d96916
Cancels the failing connection with self.token.cancel()
rust-dashcore/dash-spv/src/network/peer.rs
Lines 352 to 356 in 0d96916
- Create an issue for this
- Dismiss this finding
| let others = answering.into_iter().filter(|p| p.id() != o.peer && !p.is_closed()); | ||
| let peer = choose_peer(others, MsgClass::Headers)?; | ||
| o.hedge_to(peer) | ||
| let mut batches: Vec<&mut OnWire> = reqs |
There was a problem hiding this comment.
✨ Suggestion, not blocking · Performance · Moderate
Each successful hedge repeats an unbounded registry scan and sort
Why: A large filter backlog can monopolize the flow controller: each copy takes the shared request lock, scans the whole registry, and allocates and sorts the same on-wire batch list again. The public enqueue API accepts arbitrarily many distinct request keys, and the new drain loop multiplies that cost by the number of successful hedges before returning to flow control.
How to fix it and 6 places read
How to fix it
Build the ordered candidate list once per pass and process a bounded number of candidates or sends per tick. Revalidate each candidate and its destination before sending, and do not hold the registry lock during sorting or socket I/O.
Checked in the code
Exposes async fn enqueue(&self, height: u32, msg: NetworkMessage) to library callers
rust-dashcore/dash-spv/src/network/mod.rs
Lines 110 to 114 in 0d96916
Inserts distinct keys with reqs.insert(key, ReqState::Queued(0))
rust-dashcore/dash-spv/src/network/broker.rs
Lines 112 to 116 in 0d96916
Takes self.requests.lock().await before collecting on-wire batches from the whole registry
rust-dashcore/dash-spv/src/network/broker.rs
Lines 418 to 422 in 0d96916
dash-spv/src/network/broker.rs:429: Runsbatches.sort_unstable_by_key(|o| o.height)for every copydash-spv/src/network/manager.rs:724: Repeats the operation withwhile let Some(height)without a per-tick work limit
- Create an issue for this
- Dismiss this finding
| let answering = ConnectedPeer::for_test(conn(3, 0)).await; | ||
| let peers = [holders[0].handle(), holders[1].handle(), answering.handle()]; | ||
| for (n, peer) in holders.iter().enumerate() { | ||
| peer.set_cap(1 << 30); |
There was a problem hiding this comment.
✨ Suggestion, not blocking · Testing · Larger change
The regression tests set connection and flow state by hand
Why: The broker test sets peer caps directly and calls receiving without delivering bytes. The controller test admits synthetic connections and enqueues directly into its private broker. Reverting broker.rs:440 to last_answer fails the receiving case and reverting manager.rs:724 to if let fails the burst assertion, but neither test checks the real path that produces the connection and receive state.
How to fix it and 7 places read · breaks a repository rule
How to fix it
Use the existing loopback handshake harness to start the manager and enqueue through NetworkManager. Drive cap changes and partial receives through loopback traffic, then assert on the filter requests observed by the answering peer.
Repository rule
This PR breaks a required rule of AGENTS.md: 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 commented line: Forces a cap with peer.set_cap(1 << 30)
Simulates receive progress by calling broker.receiving(...) directly
rust-dashcore/dash-spv/src/network/broker.rs
Lines 1038 to 1042 in 0d96916
And line 1056 overwrite the destination cap with answering.set_cap(...)
rust-dashcore/dash-spv/src/network/broker.rs
Lines 1052 to 1059 in 0d96916
Inserts a test peer with net.state.connected.admit(...)
rust-dashcore/dash-spv/src/network/manager.rs
Lines 2370 to 2374 in 0d96916
dash-spv/src/network/manager.rs:2375: Bypasses the network manager withnet.state.broker.enqueue(...)dash-spv/src/network/peer.rs:437: Describesfor_testas a connectionwith no reader running
- Create an issue for this
- Dismiss this finding
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
`Broker::hedge_filters` only ever copied the lowest filter batch on the wire, and the flow controller called it once per 250 ms tick. The next batch could only get a copy after the previous copy was delivered, so the batches of silent peers were repaid one round trip at a time, rounded up to the next tick, while the peer left answering sat idle in between. When two frozen peers owed a dozen or more batches, the request timeout dropped one of them before the store caught up. Every batch whose peer is silent for `HEDGE_AFTER` is now eligible, in height order. The lowest batch on the wire keeps its rule: a copy once its peer answered nothing, past any cap, since it holds back the store. A higher batch needs its peer to have sent no bytes at all, so a peer midway through a big block keeps its batches, and it only goes to a peer with room in its cap, so the answering peer is kept busy up to what the flow controller sizes it for and is not flooded. The flow controller hedges until nothing more is eligible in a tick. Batches above a lower one still queued are left alone, as before for the lowest. Closes #1530
0d96916 to
5555f01
Compare
|
✅ Review complete in 11m 45s Planner (5s) Review (behavior · full): 7 findings Judge (4m 37s) Posted: 4 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
Last reviewed
|
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
✅ Approved. 1 suggestion, which doesn't block.
What this does: When peers stop answering, the client used to ask a helper peer for only one missing filter batch per tick. It now asks an idle peer for several stuck batches at once, up to that peer's capacity.
1 suggestion · not blocking
✨ Higher filter batches can be copied while their original peer is streaming a reply
Suggestion, not blocking · Performance · Moderate · dash-spv/src/network/broker.rs:440
Why: A peer that starts streaming a large reply just before the two-second hedge deadline can still look silent to the hedger until the next one-second timeout sample. The hedger can fill the answering peer's spare capacity with duplicate higher batches during that gap, even though the original peer is already sending bytes.
rust-dashcore/dash-spv/src/network/broker.rs
Lines 438 to 442 in 5555f01
How to fix it
Use a per-connection receive timestamp updated when bytes are read for higher-batch eligibility. Keep the request-age guard so an idle peer is not treated as stalled on its first request, and keep the separate completed-answer rule for the lowest batch.
Checked in the code
Uses o.last_answer for the lowest height and o.last_progress for higher heights
rust-dashcore/dash-spv/src/network/broker.rs
Lines 436 to 440 in 5555f01
Records streaming peers only when the timeout monitor samples growth and sees p.partial
rust-dashcore/dash-spv/src/network/manager.rs
Lines 1120 to 1124 in 5555f01
Can issue multiple copies before the timeout monitor takes its next sample
rust-dashcore/dash-spv/src/network/manager.rs
Lines 760 to 764 in 5555f01
dash-spv/src/network/broker.rs:443:&& silent_since.elapsed() >= HEDGE_AFTER
- Create an issue for this
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Run filter sync against several peers, for example with the CLI on testnet with --data-dir set and peer_speed and dash_spv::network debug logs on.
- Freeze two peers that hold filter batches, for example by blocking their traffic with a firewall rule, while a third peer is idle. Expect several
hedged filter batchlines in the same tick, not one per 250 ms. - Keep the frozen peers blocked. Expect the idle peer to receive no more batch copies than its cap allows, apart from the lowest batch, which goes out past the cap.
- Let a frozen peer resume while it still holds a large batch in progress. Expect only its lowest batch to be hedged, not the batches behind it.
- Requeue a lower filter batch while higher ones are stuck, for example by dropping a peer. Expect no batch above the queued one to be hedged until it goes out.
- Edge case: freeze all peers at once so the link looks stalled. Expect hedges only to peers that are idle, and none once no peer is answering.
- Edge case: disconnect the peer that received a hedge. Expect its batches to be hedged again to another answering peer on a later tick.
About this review
- Reviewed
5555f01, round 2 - 143 changed lines read in 11m 45s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 4.2M in (3.2M from cache) · 78k out · about $5.95 at API prices
- Runner: self-hosted · started after 8s · peak memory 3.8 GiB of 30.0 GiB
- How Manki reviews
…run 45857312667)
When peers froze during filter sync, only the lowest filter batch they owed got a second copy from another peer, and the next copy waited for the previous one to arrive, at most one per 250 ms flow tick. The peer left answering sat idle in between, so two frozen peers owing a dozen batches or more were repaid too slowly and the request timeout dropped one of them. This is the
test_filter_sync_passes_frozen_peersflake on CI.Now every batch whose peer is silent gets a copy, lowest first, and the flow controller sends all of them in one tick. Only the lowest batch may go past the answering peer's cap. A higher batch needs its peer to have sent no bytes at all, so a peer midway through a big block keeps its batches.
With the answering dashd slowed to CI speed, the test failed 10 of 48 runs on
devand none of 48 with this change.Closes #1530
PR Hygiene ·
5555f01/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