Uh oh!
There was an error while loading. Please reload this page.
refactor: remove current_sync_peer from network manager - #511
Conversation
📝 WalkthroughWalkthroughThe PR refactors Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## v0.42-dev #511 +/- ##
=============================================
+ Coverage 66.13% 66.18% +0.04%
=============================================
Files 311 311 Lines 64757 64717 -40 =============================================
+ Hits 42829 42832 +3 + Misses 21928 21885 -43
|
bbaf01d to
36be3ddCompareThis PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
f2fe73b to
d6f2108Compare36be3dd to
22e4161CompareThis PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
22e4161 to
e5f3bc6CompareQuantumExplorer
commented
Mar 17, 2026
Review from ClaudeIssue 1: |
Simplify peer selection in `send_to_single_peer` by removing the sticky sync peer tracking. Peers are now selected directly based on message type requirements and the round-robin counter.
d6f2108 to
5da971fCompareThere was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
dash-spv/src/network/manager.rs (1)
986-1021: Add regression tests for the new single-peer selection behavior.Please add unit tests for: (1) excluding
headers2_disabledpeers in single-peer headers flow, and (2) round-robin across capability-filtered peer subsets.As per coding guidelines,
**/*.rs: Write unit tests for new functionality in Rust code.Also applies to: 1070-1084
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dash-spv/src/network/manager.rs` around lines 986 - 1021, Add unit tests exercising send_to_single_peer to cover (1) that peers with headers2_disabled are excluded from the single-peer headers flow by simulating peers returned by Pool::peer_with_service and ensuring NetworkMessage::GetHeaders2 is not sent to those peers, and (2) that next_peer performs round-robin across capability-filtered subsets by creating multiple peers with the same service flags and asserting subsequent send_to_single_peer calls cycle through their addresses; use the existing Pool::get_all_peers, Pool::peer_with_service, send_to_single_peer, next_peer and send_message_to_peer hooks to inject fake peers/messages and verify selection behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@dash-spv/src/network/manager.rs`:
- Around line 998-1000: The code marks NetworkMessage::GetHeaders2 as optional
(returns Some((ServiceFlags::NODE_HEADERS_COMPRESSED, false))) which allows
selecting peers without headers2 support and then attempting to send GetHeaders2
later; either make GetHeaders2 required by flipping the tuple to
Some((ServiceFlags::NODE_HEADERS_COMPRESSED, true)) so peer selection only
chooses peers advertising NODE_HEADERS_COMPRESSED, or add downgrade logic at the
send site that checks the chosen peer's service flags and sends a plain
GetHeaders when NODE_HEADERS_COMPRESSED is not present (ensure the send path
that currently emits GetHeaders2 consults the peer's flags first).
- Around line 1004-1015: The current preferred_service branch directly uses
pool.peer_with_service(...) which bypasses the round-robin helper and won't
exclude headers2_disabled peers; replace that direct selection with a filtered
round-robin selection similar to send_distributed: query the available peers
supporting the given flags (e.g. pool.peers_with_service(flags) or equivalent),
filter out headers2_disabled peers, if the filtered list is empty handle the
required=true case by logging and returning NetworkError::ProtocolError,
otherwise call next_peer(&filtered_peers) to pick the address/peer and log the
selection; keep existing behavior for the None => self.next_peer(&peers) branch.
---
Nitpick comments:
In `@dash-spv/src/network/manager.rs`:
- Around line 986-1021: Add unit tests exercising send_to_single_peer to cover
(1) that peers with headers2_disabled are excluded from the single-peer headers
flow by simulating peers returned by Pool::peer_with_service and ensuring
NetworkMessage::GetHeaders2 is not sent to those peers, and (2) that next_peer
performs round-robin across capability-filtered subsets by creating multiple
peers with the same service flags and asserting subsequent send_to_single_peer
calls cycle through their addresses; use the existing Pool::get_all_peers,
Pool::peer_with_service, send_to_single_peer, next_peer and send_message_to_peer
hooks to inject fake peers/messages and verify selection behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1e08ee24-f489-46db-811a-719fc2a7ff83
📒 Files selected for processing (1)
dash-spv/src/network/manager.rs
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Simplify peer selection in
send_to_single_peerby removing the sticky sync peer tracking. Peers are now selected directly based on message type requirements and the round-robin counter.Based on:
PeerPoolhelpers #509Summary by CodeRabbit
Release Notes