Skip to content

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

Merged
xdustinface merged 1 commit into
devfrom
fix/max-peers
Jul 5, 2026
Merged

xdustinface merged 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 are now enforced more consistently across discovery, maintenance, and DNS fallback.
    • Connection “top-up” logic now respects the same configured maximum instead of a single fixed target.
  • New Features
    • Peer networking now supports a configurable maximum peer count per instance.
    • Client default peer limit is now 3 when not overridden (instead of 8).

@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 28d202e9-32d3-4be6-b080-4cbc8a618d1f

📥 Commits

Reviewing files that changed from the base of the PR and between c922c89 and 741aa39.

📒 Files selected for processing (7)
  • dash-spv/src/client/config.rs
  • dash-spv/src/client/config_test.rs
  • 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
🚧 Files skipped from review as they are similar to previous changes (5)
  • dash-spv/src/client/config.rs
  • dash-spv/src/network/tests.rs
  • dash-spv/src/network/manager.rs
  • dash-spv/tests/peer_test.rs
  • dash-spv/src/network/pool.rs

📝 Walkthrough

Walkthrough

Replaces the fixed peer-limit constant with per-instance max_peers values in the pool and manager, updates the client default to 3, and adjusts related tests to use explicit capacities.

Changes

Configurable peer limit

Layer / File(s) Summary
PeerPool capacity field and checks
dash-spv/src/network/constants.rs, dash-spv/src/network/pool.rs
Removes TARGET_PEERS, adds max_peers to PeerPool, changes the constructor to new(max_peers: usize), and updates admission and capacity checks plus the default constructor and pool tests.
PeerNetworkManager max_peers wiring
dash-spv/src/network/manager.rs
Adds max_peers to PeerNetworkManager, derives it from config, uses it in discovery and maintenance/fallback limits, copies it on clone, and initializes the test manager with 8.
Client default and expectation updates
dash-spv/src/client/config.rs, dash-spv/src/client/config_test.rs
Changes the default ClientConfig::max_peers value from 8 to 3 and updates the default-config test expectation.
Explicit capacity test updates
dash-spv/src/network/tests.rs, dash-spv/tests/peer_test.rs
Updates peer-limit tests to construct PeerPool with explicit capacity and align the limit comment with the new constructor shape.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 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 summarizes the main change: replacing TARGET_PEERS with existing max_peers configuration fields 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 86.95652% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.40%. Comparing base (b0a909c) to head (741aa39).

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.40%   -0.05%     
==========================================
  Files         324      324              
  Lines       72577    72583       +6     
==========================================
- Hits        53306    53277      -29     
- Misses      19271    19306      +35     
Flag Coverage Δ
core 76.94% <ø> (ø)
ffi 47.17% <ø> (-0.81%) ⬇️
rpc 20.00% <ø> (ø)
spv 90.52% <86.95%> (+0.24%) ⬆️
wallet 72.61% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/client/config.rs 94.49% <100.00%> (ø)
dash-spv/src/client/config_test.rs 100.00% <100.00%> (ø)
dash-spv/src/network/manager.rs 71.15% <90.90%> (+1.28%) ⬆️
dash-spv/src/network/pool.rs 92.97% <80.00%> (+0.07%) ⬆️

... and 20 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 Resolved
@ZocoLini
ZocoLini force-pushed the fix/max-peers branch 2 times, most recently from 9f14e05 to bc68e0e Compare July 2, 2026 14:52
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 2, 2026
@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.

@ZocoLini

ZocoLini commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

done

@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/client/config.rs`:
- Line 89: ClientConfig::default() currently changed max_peers to 3, which
conflicts with the existing expected default of 8 in the config tests and
surrounding network assumptions. Update the default back in
ClientConfig::default if 8 is the intended behavior; otherwise, keep 3 and make
sure all affected tests, docs, and any code that relies on the default peer
capacity are updated consistently.
🪄 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: 96a2eb97-1572-4675-bfee-c97656143acf

📥 Commits

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

📒 Files selected for processing (6)
  • dash-spv/src/client/config.rs
  • 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
🚧 Files skipped from review as they are similar to previous changes (4)
  • dash-spv/tests/peer_test.rs
  • dash-spv/src/network/tests.rs
  • dash-spv/src/network/manager.rs
  • dash-spv/src/network/pool.rs

Comment thread dash-spv/src/client/config.rs Resolved
@github-actions github-actions Bot removed the ready-for-review CodeRabbit has approved this PR label Jul 3, 2026
@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label Jul 3, 2026
@xdustinface
xdustinface merged commit a1b9848 into dev Jul 5, 2026
38 checks passed
@xdustinface
xdustinface deleted the fix/max-peers branch July 5, 2026 13:35
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