Skip to content

fix(dash-spv): rotate the slowest peer of a slow set - #1373

Draft
xdustinface wants to merge 1 commit into
fix/peer-diversityfrom
fix/peer-exploration
Draft

xdustinface wants to merge 1 commit into
fix/peer-diversityfrom
fix/peer-exploration

Conversation

@xdustinface

Copy link
Copy Markdown
Collaborator

When every peer is slow alike and each sits in its own network group, neither underserving_peer nor the crowded-group swap fires. A set can then serve at a fraction of a MB/s for many minutes while faster addresses go untried.

While work is queued and the link is not stalled, repair_round now rotates out the slowest measured peer if it serves below EXPLORE_FLOOR_BYTES_PER_SEC. Peers are judged by their 30 s serving_rate, so a newcomer is not judged while it ramps up. PeerDiscoverer remembers what each address served on its last connection and dials untried addresses first, then known ones fastest first. Exploration paces the rotations and backs off after repeated misses. Dials are staggered from a candidate queue, and Ban::MissingServices becomes Ban::Unusable, which also covers a peer that held work for REQUEST_TIMEOUT without answering any of it.

Stacked on #1372, and will be retargeted to dev when that one merges.

@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.48033% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.98%. Comparing base (707faf6) to head (9402114).

Files with missing lines Patch % Lines
dash-spv/src/network/manager.rs 96.28% 15 Missing ⚠️
dash-spv/src/network/discovery.rs 97.01% 2 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           fix/peer-diversity    #1373      +/-   ##
======================================================
+ Coverage               85.93%   85.98%   +0.05%     
======================================================
  Files                     268      268              
  Lines                   71266    71619     +353     
======================================================
+ Hits                    61240    61582     +342     
- Misses                  10026    10037      +11     
Flag Coverage Δ
core 82.80% <ø> (ø)
rpc 52.10% <ø> (ø)
spv 94.81% <96.48%> (+0.02%) ⬆️
wallet 83.53% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/network/bans.rs 95.23% <100.00%> (ø)
dash-spv/src/network/costs.rs 96.13% <100.00%> (+0.13%) ⬆️
dash-spv/src/network/peer.rs 92.38% <100.00%> (+0.24%) ⬆️
dash-spv/src/network/discovery.rs 94.65% <97.01%> (+0.90%) ⬆️
dash-spv/src/network/manager.rs 94.88% <96.28%> (+0.42%) ⬆️

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

@github-actions github-actions Bot removed the merge-conflict The PR conflicts with the target branch. label Nov 10, 2026
When every peer is slow alike and each sits in its own network group, neither `underserving_peer` nor the crowded-group swap fires, so a set can serve at a fraction of a MB/s for many minutes while faster addresses go untried.

- While work is queued and the link is not stalled, `repair_round` rotates out the slowest measured peer if it serves below `EXPLORE_FLOOR_BYTES_PER_SEC`.
- Rotation, the judgement of a newcomer, the candidate order and the per-address records use the 30 s `serving_rate`, so a peer is judged only once it has been bound for `SERVING_SAMPLE_TICKS`. A fast mainnet peer serves only 40 to 60% of its later rate in its first 15 s and 70 to 100% by 30 s, so a newcomer judged sooner looks slow while it ramps.
- `PeerDiscoverer` remembers what each address served on its last connection. Untried addresses come first, then the known ones fastest first, so a fast peer rotated out by mistake is the first known address dialed again. A rotation skips an address that served no faster than the slowest connected peer. Configured peers are never rotated or rated.
- `Exploration` paces rotations: the first once every peer is measured, never before the last newcomer is measured. Rotation runs at the fast pace of `EXPLORE_MIN_INTERVAL` only while the slowest peer serves below `EXPLORE_WORSE_FRACTION` (half) of the set's best, and an even set rotates once per `SWAP_COOLDOWN`. Fast and slow peers differ more than tenfold on mainnet and three to tenfold on testnet, while slow peers among themselves vary within about twofold.
- A newcomer is a hit only if it serves at least `EXPLORE_HIT_MARGIN` (twice) the rate of the peer it replaced and is no longer clearly worse than the set's best. From the second miss in a row the interval doubles up to `SWAP_COOLDOWN`, a hit makes it fast again, and a back-off ends when the set's best rate halves or doubles.
- `repair_round` keeps `want` dials in flight from a queue of up to `CONNECT_CHUNK` candidates, starting the next one whenever a dial fails or stalls past `DIAL_STAGGER`, and ends a swap round once its newcomer is admitted. A rotation that admitted nobody is no miss.
- `Ban::MissingServices` becomes `Ban::Unusable`, a ban for the session. It also covers a peer that leaves the set, by a kick, a swap or a disconnect, after holding work for `REQUEST_TIMEOUT` without answering any of it. A handshake that lost its round's race no longer ranks its address ahead of the untried ones.
- Each round that rotates no peer out logs why at `debug`, once per change of reason.
- The supervisor tests share `swapped_out`, which can also run the real `Supervisor::run` loop with rates that become known while it runs.
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