Repository navigation
feat(platform-wallet): expose classified connected SPV peers - #4050
Conversation
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]>
|
Warning Review limit reached
Next review available in: 26 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds 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 ChangesSPV Connected Peers
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
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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 |
|
✅ Review complete (commit e1eada0) |
There was a problem hiding this comment.
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]>
…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]>
|
Reviewed |
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::PeersUpdatedbut offers no query for them, and nothing classifies a peer as an evonode / masternode / regular node.What was done?
spv/peers.rs. APeerTrackerevent handler rides the SPV client's handler list and mirrors the latestPeersUpdatedsnapshot (cleared on stop and when the run loop exits).SpvRuntime::connected_peers()classifies each address against the masternode list engine's latest list:HighPerformanceentry → Evonode,Regular→ Masternode, absent → Normal, masternode list not yet synced → Unknown. Matching is byip:portfirst, then bare IP.platform_wallet_manager_spv_connected_peersreturns a heap-owned[FFISpvPeerInfo](addressC string +SPV_PEER_NODE_TYPE_*constant) with a pairedplatform_wallet_manager_spv_connected_peers_free, following the ban-list array idiom.PlatformSpvPeerInfo/PlatformSpvPeerNodeTypetypes, a one-shotconnectedSpvPeers()query, and a@Published spvPeersmirror 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?
spv/peers.rs: classification (masternode / evonode / normal), unknown-when-list-absent, IP-only fallback match, andPeersUpdatedsnapshot replace + clear semantics — all pass.cargo check/cargo clippy --all-targets/ per-crate--all-features --testsclean forplatform-walletandplatform-wallet-ffi;cargo fmt --all.build_ios.sh --target simrebuilt the simulator xcframework and SwiftExampleApp builds against the regenerated header.Breaking Changes
None — additive FFI surface only.
Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit