Repository navigation
fix(wallet): read masternode owner/voting addresses from the live pool - #922
Conversation
The Masternode Keys screens capped Owner and Voting at 5 keys while Operator showed 20, on a wallet whose live pools hold 25 entries with 20/17 marked used. `MasternodeProviderKeyDeriver.address(at:)` resolved addresses from `SwiftDashSDKHost.derivationWallet()` — a throwaway key-wallet stack built from the mnemonic purely for private-key derivation. That instance never processes transactions, so its provider pools sit at the freshly-created `DEFAULT_SPECIAL_GAP_LIMIT` (5) depth forever, and every index past 4 resolved to nil. Both consumers of that address lookup are address JOINS (the overview's `MasternodeKeyUsage` and `MasternodesScreen`'s ownership labels), and each skips an index whose address is nil — so masternodes whose owner/voting key sits deeper than #4 were silently invisible. Operator and Evonode escaped it because Rust resolves their indexes directly on the aggregation row rather than joining on an address. Now the addresses come from the running `PlatformWalletManager` (`accountAddressPools`) — the pool SPV extends as ProRegTx / ProUpRegTx matches mark deeper indexes used, and the same data the Storage Explorer renders. The whole pool is snapshotted once per deriver, so per-index lookups became dictionary hits instead of an FFI call each. The fixed 20-index scan windows are replaced by the live pool's actual depth (the 20 remains only as a fallback when it can't be read), since a pool that grows past 20 would otherwise hit the same silent cap. Private-key derivation (`wif` / `privateKeyHex`) still uses the derivation wallet — it needs the mnemonic and derives at any index. Co-Authored-By: Claude Fable 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe masternode key deriver now caches owner and voting addresses from live wallet pools. Address consumers scan the full available pool and use a fallback window when pool depth is unavailable. ChangesLive masternode address scanning
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
DashWallet/Sources/UI/Menu/Tools/Masternode Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift (1)
195-195: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename
masterPathto satisfy SwiftLint.SwiftLint reports
inclusive_languageformasterPath. Rename the private property and its uses, for example, toderivationPath.Proposed fix
- private let masterPath: String + private let derivationPath: String ... - self.masterPath = path + self.derivationPath = path ... - return try? account.derivePrivateKeyWIF(wallet: wallet, masterPath: masterPath, index: index) + return try? account.derivePrivateKeyWIF(wallet: wallet, masterPath: derivationPath, index: index)As per coding guidelines, follow SwiftFormat/SwiftLint for Swift files.
🤖 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 `@DashWallet/Sources/UI/Menu/Tools/Masternode` Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift at line 195, Rename the private property masterPath in DerivationPathKeysModel to derivationPath and update every reference to it consistently, preserving the existing behavior while satisfying SwiftLint’s inclusive_language rule.Sources: Coding guidelines, Linters/SAST tools
🤖 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 `@DashWallet/Sources/UI/Menu/Tools/Masternode`
Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift:
- Around line 257-269: The live-pool branch in
DerivationPathKeysModel.loadLiveAddresses must provide a usable fallback address
source instead of returning an empty dictionary; update
DerivationPathKeysModel.address(at:) to resolve from that source during fallback
scanning. Apply the fallback-aware resolver at
WalletKeysOverviewModel.swift:144-148 and MasternodesScreen.swift:70-72, while
preserving normal live-pool resolution.
---
Nitpick comments:
In `@DashWallet/Sources/UI/Menu/Tools/Masternode`
Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift:
- Line 195: Rename the private property masterPath in DerivationPathKeysModel to
derivationPath and update every reference to it consistently, preserving the
existing behavior while satisfying SwiftLint’s inclusive_language rule.
🪄 Autofix
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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: be217c65-1c05-4d8e-b081-ec19b1caa30f
📒 Files selected for processing (3)
DashWallet/Sources/UI/Menu/Tools/Masternode Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swiftDashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swiftDashWallet/Sources/UI/Menu/Tools/MasternodesScreen.swift
Review follow-up. The fallback window was inert: when the live-pool read returned an empty map, `highestAddressIndex` was nil, so the loops fell back to a fixed 20-index scan in which `address(at:)` returned nil for every index — a fallback that could not restore a single label. Now the deriver falls back to the derivation wallet's own provider pool when the running wallet can't vend the account (e.g. a just-imported wallet whose registration hasn't completed). That pool is only gap-limit deep, which is exactly the shallowness the live read exists to avoid, so it is documented as degraded rather than equivalent — but it resolves real addresses instead of nothing. With bounds always derived from a real snapshot, the phantom `fallbackScanWindow` constants are removed from both call sites; an unreadable pool now yields an empty range, which is the honest behaviour: no pool means no addresses to join against. Also renames the private `masterPath` property to `accountRootPath` (SwiftLint `inclusive_language`, default-enabled and not disabled in `.swiftlint.yml`). The SDK's own `masterPath:` argument label is external API and unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
The symptom
Masternode Keys showed Owner 5 keys / 5 used and Voting 5 keys / 2 used, while Operator showed 20/17 — on a wallet whose live pools actually hold 25 owner and 25 voting addresses with 20 and 17 marked used.
Root cause
MasternodeProviderKeyDeriver.address(at:)resolved addresses fromSwiftDashSDKHost.derivationWallet()— documented in-place as a "throwaway key-wallet stack" built fresh from the mnemonic viaaddWallet, for path-based key derivation. That instance has never processed a transaction, so its provider pools sit at the freshly-createdDEFAULT_SPECIAL_GAP_LIMIT(5) depth forever. Index ≥ 5 returnednil.Both consumers of that lookup are address joins —
MasternodeKeyUsage.resolve(overview counts + detail rows) andMasternodesScreen.indexByAddress(ownership labels) — and bothcontinuepast an index whose address isnil. So any masternode whose owner/voting key sits deeper than #4 was silently invisible.Operator and Evonode Operator were never affected because Rust resolves their indexes directly on the aggregation row (
operatorKeyIndex/platformKeyIndex) instead of joining on an address.The numbers line up exactly: the live voting pool has #0–#2 unused and #3+ used, so a 5-deep throwaway pool yields precisely the observed "5 keys / 2 used".
Fix
Addresses now come from the running
PlatformWalletManagerviaaccountAddressPools(for:balance:)— the pool SPV extends as ProRegTx/ProUpRegTx matches mark deeper indexes used, and the same data the Storage Explorer renders. The pool is snapshotted once per deriver, so per-index lookups became dictionary hits rather than an FFI call each.The fixed 20-index scan windows in both joins are replaced by the live pool's actual depth (
highestAddressIndex), with the 20 kept only as a fallback when that can't be read — a pool grown past 20 would otherwise hit the same silent cap one size up.Private-key derivation (
wif/privateKeyHex) still uses the derivation wallet: it needs the mnemonic and derives correctly at any index, pool depth being irrelevant there.Verification
dashpayscheme builds clean (arm64 simulator); installed to the QA simulator.Masternodesownership labels resolving for nodes previously shown as not-in-wallet.🤖 Generated with Claude Code
Summary by CodeRabbit