Skip to content

feat(platform-wallet): expose classified connected SPV peers - #4050

Merged
QuantumExplorer merged 2 commits into
v4.1-devfrom
feat/spv-connected-peers
Jul 9, 2026
Merged

QuantumExplorer merged 2 commits into
v4.1-devfrom
feat/spv-connected-peers

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

SPV status screens (dashwallet-ios' SwiftDashSDK SPV Status, SwiftExampleApp) can show sync progress but not who the client is connected to. dash-spv pushes connected-peer addresses through NetworkEvent::PeersUpdated but offers no query for them, and nothing classifies a peer as an evonode / masternode / regular node.

What was done?

  • rs-platform-wallet: new spv/peers.rs. A PeerTracker event handler rides the SPV client's handler list and mirrors the latest PeersUpdated snapshot (cleared on stop and when the run loop exits). SpvRuntime::connected_peers() classifies each address against the masternode list engine's latest list: HighPerformance entry → Evonode, Regular → Masternode, absent → Normal, masternode list not yet synced → Unknown. Matching is by ip:port first, then bare IP.
  • rs-platform-wallet-ffi: platform_wallet_manager_spv_connected_peers returns a heap-owned [FFISpvPeerInfo] (address C string + SPV_PEER_NODE_TYPE_* constant) with a paired platform_wallet_manager_spv_connected_peers_free, following the ban-list array idiom.
  • swift-sdk: PlatformSpvPeerInfo / PlatformSpvPeerNodeType types, a one-shot connectedSpvPeers() query, and a @Published spvPeers mirror fed by the existing 1 Hz progress poll (equality-gated like its siblings).

Consumed by the dashwallet-ios SPV Status screen (companion PR on swift-sdk-integration).

How Has This Been Tested?

  • Unit tests in spv/peers.rs: classification (masternode / evonode / normal), unknown-when-list-absent, IP-only fallback match, and PeersUpdated snapshot replace + clear semantics — all pass.
  • cargo check / cargo clippy --all-targets / per-crate --all-features --tests clean for platform-wallet and platform-wallet-ffi; cargo fmt --all.
  • build_ios.sh --target sim rebuilt the simulator xcframework and SwiftExampleApp builds against the regenerated header.
  • End-to-end verification (live peers + badges on-screen) done via the dashwallet-ios companion branch.

Breaking Changes

None — additive FFI surface only.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added visibility into currently connected SPV peers.
    • Introduced peer classification labels for normal, masternode, evonode, and unknown peers.
    • Added a new Swift API and published state so apps can observe the live SPV peer list.
  • Bug Fixes
    • Peer updates now refresh only when the list changes, helping keep UI state in sync.
    • Empty or unavailable peer data is handled cleanly without breaking the app.

dash-spv pushes connected-peer addresses through
NetworkEvent::PeersUpdated but offers no query for them, so the SPV
status screens could not show who the client is talking to.

- rs-platform-wallet: a PeerTracker event handler mirrors the latest
  PeersUpdated snapshot; SpvRuntime::connected_peers() classifies each
  address against the masternode list engine (HighPerformance entry ->
  Evonode, Regular -> Masternode, absent -> Normal, list not yet
  synced -> Unknown), matching by ip:port then bare IP.
- rs-platform-wallet-ffi: platform_wallet_manager_spv_connected_peers
  returns a heap-owned [FFISpvPeerInfo] with a paired _free.
- swift-sdk: connectedSpvPeers() one-shot query plus a @published
  spvPeers mirror fed by the existing 1 Hz progress poll.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions github-actions Bot added this to the v4.1.0 milestone Jul 9, 2026
@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

Next review available in: 26 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 772a1161-3076-45ee-a4dc-863ebc45be7e

📥 Commits

Reviewing files that changed from the base of the PR and between 120ffc1 and e1eada0.

📒 Files selected for processing (2)
  • packages/rs-platform-wallet/src/spv/peers.rs
  • packages/rs-platform-wallet/src/spv/runtime.rs
📝 Walkthrough

Walkthrough

Adds peer tracking and masternode-based classification to the Rust SPV runtime, exposes the connected-peer list via new Rust FFI functions and structs, and adds corresponding Swift SDK types and a published spvPeers property updated during SPV progress polling.

Changes

SPV Connected Peers

Layer / File(s) Summary
Peer classification and tracking
packages/rs-platform-wallet/src/spv/peers.rs, packages/rs-platform-wallet/src/spv/mod.rs
Adds SpvPeerNodeType, SpvPeerInfo, PeerTracker event handler tracking connected peer address snapshots, and classify_peers resolving peers against a MasternodeList; module re-exports and unit tests included.
Runtime peer tracker wiring
packages/rs-platform-wallet/src/spv/runtime.rs
Adds peer_tracker field to SpvRuntime, registers it as an event handler on start, clears it on stop/run completion, and implements connected_peers() classifying the tracked snapshot against the latest masternode list.
Rust FFI exposure
packages/rs-platform-wallet-ffi/src/spv.rs
Adds SPV_PEER_NODE_TYPE_* constants, FFISpvPeerInfo struct, and platform_wallet_manager_spv_connected_peers/_free functions to retrieve and release peer data across the FFI boundary.
Swift SDK integration
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerSPV.swift, packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManager.swift
Adds PlatformSpvPeerNodeType, PlatformSpvPeerInfo, and connectedSpvPeers() FFI wrapper; adds published spvPeers property updated from the polling loop.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SwiftUI as SwiftUI Observer
  participant Manager as PlatformWalletManager
  participant FFI as Rust FFI Layer
  participant Runtime as SpvRuntime
  participant Tracker as PeerTracker

  Runtime->>Tracker: register as event handler
  Tracker->>Tracker: update snapshot on PeersUpdated
  Manager->>FFI: connectedSpvPeers()
  FFI->>Runtime: platform_wallet_manager_spv_connected_peers
  Runtime->>Tracker: snapshot()
  Runtime->>Runtime: classify_peers() against masternode list
  Runtime-->>FFI: Vec<SpvPeerInfo>
  FFI-->>Manager: FFISpvPeerInfo entries + count
  Manager->>Manager: map to [PlatformSpvPeerInfo]
  Manager->>SwiftUI: publish spvPeers
Loading

Suggested labels: ready for final review

Suggested reviewers: shumkov, lklimek

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: exposing classified connected SPV peers in platform-wallet.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 feat/spv-connected-peers

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@thepastaclaw

thepastaclaw commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete (commit e1eada0)

@thepastaclaw thepastaclaw 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.

Code Review

Both agent-reported issues are present in the checked-out PR. The bare-IP fallback can misclassify supported localhost/regtest peer configurations and should be fixed before merge; the concurrent stop race is also real but limited to a stale snapshot edge case.

Source: reviewers: codex-general gpt-5.5, codex-rust-quality gpt-5.5, codex-ffi-engineer gpt-5.5 completed; claude/opus general, rust-quality, and ffi-engineer failed due extra-usage quota; verifier: codex gpt-5.5 after claude/opus verifier quota failure.

🔴 1 blocking | 🟡 1 suggestion(s)

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/rs-platform-wallet/src/spv/peers.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/spv/peers.rs:118-121: Avoid classifying peers by bare IP on shared localhost setups
  The classifier falls back from an exact socket match to a bare-IP match, so any connected peer on the same IP as a masternode is reported as that masternode type even when its port is not in the masternode list. This is reachable in the existing Swift integration setup, which connects to a normal Core peer at `127.0.0.1:<coreP2P>` plus masternode peers on `127.0.0.1`; the Core peer misses `by_socket` and then matches `by_ip`, causing the new connected-peer API to report the normal peer as a masternode/evonode. Use exact `ip:port` matching for shared/local addresses, or otherwise disable the bare-IP fallback when the IP can host unrelated local peers.

In `packages/rs-platform-wallet/src/spv/runtime.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/spv/runtime.rs:269-285: Check the live client before copying the peer snapshot
  `connected_peers()` copies the tracker snapshot before checking whether `self.client` is still present. During a concurrent `stop()`, `stop()` removes the client under the write lock and clears the tracker afterward, so this method can copy old addresses, observe no client, and still return those stale peers classified as `Unknown`. Take the client read lock first and return an empty list when the client has already been stopped, matching the Rust doc comment and FFI contract.

…napshot

Review fixes for #4050:
- classify_peers matches exact ip:port only. The bare-IP fallback
  misclassified shared hosts — a localhost regtest/devnet stack running
  a masternode and an unrelated Core peer on different ports reported
  the Core peer as a masternode.
- connected_peers resolves the live client before copying the tracker
  snapshot, so a concurrent stop() can't yield stale peers classified
  Unknown after the client is gone.

Co-Authored-By: Claude Fable 5 <[email protected]>
QuantumExplorer added a commit that referenced this pull request Jul 9, 2026
…napshot

Review fixes for #4050:
- classify_peers matches exact ip:port only. The bare-IP fallback
  misclassified shared hosts — a localhost regtest/devnet stack running
  a masternode and an unrelated Core peer on different ports reported
  the Core peer as a masternode.
- connected_peers resolves the live client before copying the tracker
  snapshot, so a concurrent stop() can't yield stale peers classified
  Unknown after the client is gone.

Co-Authored-By: Claude Fable 5 <[email protected]>
@QuantumExplorer

Copy link
Copy Markdown
Member Author

Reviewed

@QuantumExplorer
QuantumExplorer merged commit 51d9cbf into v4.1-dev Jul 9, 2026
74 of 79 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/spv-connected-peers branch July 9, 2026 10:59
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.

2 participants