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

Warning

Review limit reached

@ZocoLini, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 21a26d84-7a75-4d3b-980d-d2b4147fa879

📥 Commits

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

📒 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
📝 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 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.71429% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.49%. Comparing base (b0a909c) to head (bc68e0e).

Files with missing lines Patch % Lines
dash-spv/src/network/pool.rs 80.00% 2 Missing ⚠️
dash-spv/src/network/manager.rs 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #827      +/-   ##
==========================================
+ Coverage   73.44%   73.49%   +0.05%     
==========================================
  Files         324      324              
  Lines       72577    72583       +6     
==========================================
+ Hits        53306    53348      +42     
+ Misses      19271    19235      -36     
Flag Coverage Δ
core 76.94% <ø> (ø)
ffi 47.96% <ø> (-0.02%) ⬇️
rpc 20.00% <ø> (ø)
spv 90.49% <85.71%> (+0.22%) ⬆️
wallet 72.61% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/network/manager.rs 71.15% <90.90%> (+1.28%) ⬆️
dash-spv/src/network/pool.rs 91.35% <80.00%> (-1.55%) ⬇️

... and 5 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 thread dash-spv/src/network/pool.rs
@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label Jul 2, 2026

@xdustinface xdustinface left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This makes the client connect to 8 peers by default.. it's a bit overkill and takes up more connections slots form the network than needed. I think we should target more like 3-4 peers generally for SPV clients.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review CodeRabbit has approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants