Skip to content

fix(dash-spv): replaced TARGET_PEERS with already existing max_peers config fields#827

Open
ZocoLini wants to merge 1 commit into
devfrom
fix/max-peers
Open

fix(dash-spv): replaced TARGET_PEERS with already existing max_peers config fields#827
ZocoLini wants to merge 1 commit into
devfrom
fix/max-peers

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Peer connection limits now use the configured maximum more consistently across peer discovery, maintenance, and fallback behavior.
    • Pool capacity handling now respects the same limit throughout connection checks and peer acceptance.
  • New Features
    • Peer networking now supports a configurable maximum peer count instead of relying on a single fixed value.
    • Default peer pool initialization now uses an explicit capacity setting.

@ZocoLini ZocoLini requested a review from xdustinface June 29, 2026 09:41
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Removes the fixed TARGET_PEERS compile-time constant and replaces all usages with a runtime-configurable max_peers field. PeerPool::new now accepts max_peers: usize, stores it, and uses it for capacity checks. PeerNetworkManager derives max_peers from config and passes it through to the pool and all peer-count comparisons.

Configurable peer limit

Layer / File(s) Summary
PeerPool max_peers field and capacity logic
dash-spv/src/network/constants.rs, dash-spv/src/network/pool.rs
Removes TARGET_PEERS constant and its import. PeerPool gains a max_peers: usize field; constructor changes to new(max_peers: usize); add_peer, needs_more_peers, and can_accept_peers compare against self.max_peers. Default uses Self::new(8).
PeerNetworkManager max_peers wiring
dash-spv/src/network/manager.rs
PeerNetworkManager adds max_peers: usize field, derived from config.max_peers.max(1) in new. Startup DNS discovery, maintenance_tick, dns_fallback_tick, Clone, and new_for_test all switch from TARGET_PEERS to self.max_peers.
Test updates
dash-spv/src/network/pool.rs, dash-spv/src/network/tests.rs, dash-spv/tests/peer_test.rs
All pool construction calls in tests updated to PeerPool::new(8) with comments adjusted to reflect explicit capacity.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

ready-for-review

Poem

🐇 A constant once carved into stone,
Now flows from config, all its own.
max_peers hops field to field with grace,
No hardcoded number holds its place.
The pool fills up on runtime's say—
A configurable warren, hip hooray! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing the fixed TARGET_PEERS constant with configurable max_peers settings in dash-spv.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/max-peers

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

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.18%. Comparing base (ddb59d9) to head (0f139db).

Files with missing lines Patch % Lines
dash-spv/src/network/pool.rs 77.77% 2 Missing ⚠️
dash-spv/src/network/manager.rs 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #827      +/-   ##
==========================================
- Coverage   73.18%   73.18%   -0.01%     
==========================================
  Files         323      323              
  Lines       72295    72300       +5     
==========================================
+ Hits        52911    52913       +2     
- Misses      19384    19387       +3     
Flag Coverage Δ
core 76.94% <ø> (ø)
ffi 47.71% <ø> (-0.02%) ⬇️
rpc 20.00% <ø> (ø)
spv 90.34% <85.00%> (-0.01%) ⬇️
wallet 71.81% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/network/manager.rs 71.57% <90.90%> (+0.12%) ⬆️
dash-spv/src/network/pool.rs 92.93% <77.77%> (+0.03%) ⬆️

... and 2 files with indirect coverage changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dash-spv/src/network/pool.rs`:
- Around line 24-28: PeerPool::new currently allows max_peers to be zero, which
makes the pool permanently behave as full and breaks add_peer, needs_more_peers,
and can_accept_peers. Update the PeerPool::new constructor to enforce the
invariant that max_peers is at least 1, mirroring the clamping already done in
manager.rs, so callers of PeerPool::new cannot create an unusable pool.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 61770d09-2eec-422d-b7ed-1eb571ba9c76

📥 Commits

Reviewing files that changed from the base of the PR and between ddb59d9 and 0f139db.

📒 Files selected for processing (5)
  • dash-spv/src/network/constants.rs
  • dash-spv/src/network/manager.rs
  • dash-spv/src/network/pool.rs
  • dash-spv/src/network/tests.rs
  • dash-spv/tests/peer_test.rs
💤 Files with no reviewable changes (1)
  • dash-spv/src/network/constants.rs

Comment on lines +24 to +28
pub fn new(max_peers: usize) -> Self {
Self {
peers: Arc::new(RwLock::new(HashMap::new())),
connecting: Arc::new(RwLock::new(HashSet::new())),
max_peers,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Enforce the max_peers >= 1 invariant in PeerPool::new.

Line 121 in dash-spv/src/network/manager.rs already clamps the config to at least 1, but the public pool constructor does not. PeerPool::new(0) now creates a pool that can never accept a peer because add_peer, needs_more_peers, and can_accept_peers all immediately behave as if the pool is full.

Suggested fix
 pub fn new(max_peers: usize) -> Self {
     Self {
         peers: Arc::new(RwLock::new(HashMap::new())),
         connecting: Arc::new(RwLock::new(HashSet::new())),
-        max_peers,
+        max_peers: max_peers.max(1),
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn new(max_peers: usize) -> Self {
Self {
peers: Arc::new(RwLock::new(HashMap::new())),
connecting: Arc::new(RwLock::new(HashSet::new())),
max_peers,
pub fn new(max_peers: usize) -> Self {
Self {
peers: Arc::new(RwLock::new(HashMap::new())),
connecting: Arc::new(RwLock::new(HashSet::new())),
max_peers: max_peers.max(1),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dash-spv/src/network/pool.rs` around lines 24 - 28, PeerPool::new currently
allows max_peers to be zero, which makes the pool permanently behave as full and
breaks add_peer, needs_more_peers, and can_accept_peers. Update the
PeerPool::new constructor to enforce the invariant that max_peers is at least 1,
mirroring the clamping already done in manager.rs, so callers of PeerPool::new
cannot create an unusable pool.

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