Repository navigation
fix(dash-spv): sample the serving rate while backlogged - #1564
Conversation
A peer's serving rate, which routing reads first and `underserving_peer` compares, was sampled only while the peer was bound to its cap. A burst lifts the cap far above what the peer sustains afterwards, so a peer working through a backlog below that cap went unsampled until the cap decayed to the backlog. In a mainnet run a peer serving 2 to 3 MB/s that stalled kept a serving rate near 2.5 MB/s for over a minute this way. The serving rate is now sampled whenever the peer serves all it can, the condition that already moves its served rate and cap. A peer at its cap is still sampled as before.
|
This pull request is a draft, so Manki does not review it automatically. Marking it ready for review starts automatic reviews. Until then, someone with write access to this repository can tick a box below: Review this draft reviews the current commit once, Deeper review does so with more effort, and Review every push reviews it now and again after each push. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 9 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
CI does not run on this PR while it is a draft. Someone with write access can start it here:
Marking the PR ready for review also starts CI. CI started for 397fc26: Continuous integration, Pre-commit Checks, Sanitizer. |
|
✅ Review complete in 7m 12s Planner (5s) Review (behavior · full): 7 findings Judge (2m 12s) Posted: 2 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.
✅ Approved. 2 suggestions, none of which block.
- Check approval
What this does: A peer's serving speed was only measured while it was at its full byte allowance. A peer that slowed down after a burst could go unmeasured and was never swapped out.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Run the tests with the dashd environment loaded, for example with just dash-spv::test.
- Run
cargo test -p dash-spv --lib a_backlogged_peer_is_measured_below_its_cap. Expect it to pass, with a serving rate between 100 KB/s and 500 KB/s. - Run
cargo test -p dash-spv --lib only_a_peer_serving_all_it_can_is_condemned. Expect the tip case to returnNoneand the slow-peer case to returnSome(1). - Run the
a_slow_peer_is_swapped_out_again_afterandno_slow_peer_is_swapped_out_while_our_link_stallstests. Expect swaps at the same times as before. - Sync testnet with
cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir>andRUST_LOG=peer_speed=debug. Expect a peer that slows down mid-sync to be logged as serving below the best and to be swapped out. - Edge case: at the chain tip with only small replies, expect no peer to be swapped out for being far away.
Checked and left out: 1 finding
Not finished checking · 1 possible problem
- A fast peer that is never backlogged may get a serving rate taken only from idle-to-busy ticks, which reads low ·
dash-spv/src/network/manager.rs:596
The mechanism is in the code. After an idle stretch, a request of at least MIN_CAP_BYTES (688,000 bytes) makes the second clause ofserving_alltrue while the rate is still near 0, and line 599 then samples that low rate.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
397fc26, round 1 - 39 changed lines read in 7m 12s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 2.0M in (1.6M from cache) · 62k out · about $3.19 at API prices
- Runner: self-hosted · started after 7s · peak memory 2.7 GiB of 30.0 GiB
- How Manki reviews
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1564 +/- ##
=======================================
Coverage 87.79% 87.79%
=======================================
Files 270 270
Lines 72494 72514 +20
=======================================
+ Hits 63645 63667 +22
+ Misses 8849 8847 -2
|
The backlog test repeated the rate to bytes conversion and the tick loop of `Served::bulk` only to hold a fixed backlog in flight. `Served::bulk` now takes a function from the current cap to the bytes in flight, and the existing callers pass the cap through.
`PeerFlow::tick` judged whether the peer served all it can before `ByteLimiter::tick` updated the rate that judgement reads, and the limiter judged it again after. On the tick a backlog starts or ends the two disagreed, so the serving rate averaged one tick fewer or more than the served rate and the cap. `ByteLimiter::tick` now returns its own judgement with the cap, and a stall of our link counts as not serving all. `PeerFlow::tick` samples on exactly that.
|
✅ Review complete in 13m 14s Planner (5s) Review (behavior · full): 3 findings Judge (6m 58s) Posted: 1 finding Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.
✅ Approved. 1 suggestion, which doesn't block.
- Check approval
What this does: The client measures how fast each peer serves in order to replace slow ones. Peers with a backlog below an inflated byte limit were never measured.
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 filters enabled and peer_speed debug logging on, for example RUST_LOG=peer_speed=debug,dash_spv::network=debug.
- Sync filters from several peers for over a minute. Expect
peer_speedlines with non-zeroservedvalues for busy peers. - Throttle one peer's link, for example with a firewall rate limit, after it has run fast. Expect a debug line naming it as serving below the best peer's rate, followed by a supervisor swap line.
- Let sync reach the chain tip with small header replies only. Expect no peer to be reported as slow just for being far away.
- Cut the client's network for about 20 seconds during bulk filter sync. Expect no slow-peer verdicts or swaps during the outage, and expect caps to resume after it.
Checked and left out: 1 finding
Not proven, so not listed · 1 warning
- Backlog samples are taken only while the 1 s rate is low, so a far peer's serving rate is biased down ·
dash-spv/src/network/manager.rs:596
A check of the code could not confirm it.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
5f8fd30, round 2 - 73 changed lines read in 13m 14s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 2.4M in (1.8M from cache) · 51k out · about $3.24 at API prices
- Runner: self-hosted · started after 18s · peak memory 1.9 GiB of 30.0 GiB
- How Manki reviews
`feed` takes the bytes each peer should have in flight as a function of its cap, and `feeders` connects peers without measuring them, so a test can drive a peer through the real flow controller with work below its cap.
The backlog regression drove private `PeerFlow::tick` with a made-up in-flight count. It now feeds a loopback peer through the running flow controller: a 2 tick burst at 20 MB/s lifts its cap to 5 MB over 768 KB in flight, then it serves that backlog at 100 KB/s, and the test reads the serving rate the controller publishes. With the old gate the rate is first published 27 ticks later, so the test fails on it. `Served::bulk` loses the in-flight function it only took for the old test.
|
✅ Review complete in 8m 16s Planner (4s) Review (behavior · full): 4 findings Judge (3m 12s) Posted: 2 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.
✅ Approved. 1 suggestion, which doesn't block.
- Check approval
What this does: A peer's speed used to be measured only while it sat at its in-flight cap. A peer whose cap stayed high after a fast burst could keep a slow backlog and never be measured or judged slow.
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 filters enabled and peer_speed debug logging on, so the per-peer served and cap lines are visible.
- Sync from scratch with several peers. Expect every peer's
capto grow from the initial value and sync to complete. - Watch the logs for a peer whose delivery drops sharply after a fast start. Expect a
serving at ... vs best ...debug line for it while its cap is still above its in-flight bytes. - Keep syncing after that line. Expect
swapped out slowfor that peer no sooner than the 60 s swap cooldown allows. - Cut the host's network for about 20 s mid-sync, then restore it. Expect no
swapped out slowline caused by the outage, and sync to resume. - Let sync reach the tip and stay idle for a few minutes. Expect no peer to be flagged slow from small tip replies.
Checked and left out: 1 finding
Not proven, so not listed · 1 warning
- Backlog ticks pull a fast peer's serving rate down to its round-trip and think time ·
dash-spv/src/network/manager.rs:596
A check of the code could not confirm it.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
bfeaadd, round 3 - 96 changed lines read in 8m 16s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 2.7M in (2.1M from cache) · 59k out · about $3.51 at API prices
- Runner: self-hosted · started after 9s · peak memory 2.6 GiB of 30.0 GiB
- How Manki reviews
The backlog test only read the rate after 120 qualifying ticks, when the cap had already decayed to the outstanding work. It now measures a peer first, lifts its cap with a burst and slows it down, then stops at the first tick its published rate moves and asserts the cap is still above its bytes in flight at that tick. With the fix that tick comes 9 ticks into the slowdown with a 6.7 MB cap over 2 MB in flight. With the old gate it comes only after the cap has fallen to 1.8 MB, so the test fails on it. `measured_peers` takes back the connecting step, since no test connects peers without measuring them now.
|
✅ Review complete in 6m 49s Planner (5s) Review (behavior · full): 2 findings Judge (3m 24s) Posted: 0 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
Last reviewed
|
There was a problem hiding this comment.
Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.
✅ Approved.
- Check approval
What this does: The client measures how fast each peer serves so it can replace slow ones. A peer that slowed down after a burst kept its old measured speed for a while.
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 filters enabled, and with peer_speed debug logging turned on.
- Sync from scratch with several peers. Expect
peer_speedlines whoseservedand cap values settle per peer, and sync that completes. - Throttle one peer's connection mid-sync, for example with
tcon its address. Expect its measured rate to drop within seconds, and a log line saying a replacement is worth probing for. - Let sync reach the chain tip and idle for several minutes. Expect no peer to be flagged as slow from small header or inventory replies alone.
- Cut the client's network for about 30 seconds during filter sync, then restore it. Expect no swap and no rate drop caused by the outage, and sync to resume.
Checked and left out: 1 finding
Not proven, so not listed · 1 warning
- Below-cap sampling counts reply waits but can skip the replies ·
dash-spv/src/network/manager.rs:596
A check of the code could not confirm it.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
3672672, round 4 - 92 changed lines read in 6m 49s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 2.4M in (1.8M from cache) · 54k out · about $3.35 at API prices
- Runner: self-hosted · started after 25s · peak memory 2.7 GiB of 30.0 GiB
- How Manki reviews
|
/self-reviewed |
|
Policy satisfied — this can merge. |
…run 46939073466)
A peer's serving rate, which routing reads first and
underserving_peercompares, was sampled only while the peer was bound to its cap. A burst lifts the cap far above what the peer sustains afterwards, so a peer working through a backlog below that cap went unsampled until the cap decayed to the backlog. Meanwhile its serving rate kept the value from before, or stayed unmeasured.The serving rate is now sampled whenever the peer serves all it can, the condition that already moves its served rate and cap. A peer at its cap is sampled as before. The docs that said "while bandwidth bound" are updated.
Split out of #1375, which keeps the routing half. The two changes are independent.
PR Hygiene ·
3672672When every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.