Skip to content

fix(wallet): read masternode owner/voting addresses from the live pool - #922

Merged
QuantumExplorer merged 2 commits into
developfrom
fix/masternode-keys-persisted-pool
Aug 7, 2026
Merged

QuantumExplorer merged 2 commits into
developfrom
fix/masternode-keys-persisted-pool

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

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 from SwiftDashSDKHost.derivationWallet() — documented in-place as a "throwaway key-wallet stack" built fresh from the mnemonic via addWallet, for path-based key derivation. That instance has never processed a transaction, so its provider pools sit at the freshly-created DEFAULT_SPECIAL_GAP_LIMIT (5) depth forever. Index ≥ 5 returned nil.

Both consumers of that lookup are address joins — MasternodeKeyUsage.resolve (overview counts + detail rows) and MasternodesScreen.indexByAddress (ownership labels) — and both continue past an index whose address is nil. 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 PlatformWalletManager via accountAddressPools(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

  • dashpay scheme builds clean (arm64 simulator); installed to the QA simulator.
  • Evidence gathered from the affected wallet's own SwiftData store: provider voting = 25 addresses / 17 used / max index 24, provider owner = 25 / 20 / 24 — versus the 5 the screen was reporting.
  • Not yet visually confirmed on-device: the simulator is PIN-gated, so I couldn't drive it to the screen. Expected after unlocking: Owner ≈ 21 keys / 20 used and Voting ≈ 25 / 17, and Masternodes ownership labels resolving for nodes previously shown as not-in-wallet.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved masternode owner and voting address discovery using the wallet’s current address pools.
    • Expanded address scanning to cover the full available derivation range instead of limiting checks to 20 addresses.
    • Added fallback scanning when live wallet address data is unavailable.
    • Improved masternode provider key handling while keeping derived private keys isolated from the active wallet.
    • Prevented unsupported key types and unavailable address pools from producing invalid results.

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]>
@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8541ebcf-c655-46d3-a14b-0a73c0b608b0

📥 Commits

Reviewing files that changed from the base of the PR and between b721e3a and 90f7494.

📒 Files selected for processing (3)
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swift
  • DashWallet/Sources/UI/Menu/Tools/MasternodesScreen.swift
🚧 Files skipped from review as they are similar to previous changes (2)
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swift

📝 Walkthrough

Walkthrough

The 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.

Changes

Live masternode address scanning

Layer / File(s) Summary
Snapshot live provider addresses
DashWallet/Sources/UI/Menu/Tools/Masternode Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift
MasternodeProviderKeyDeriver derives private keys from a throwaway wallet, caches live owner and voting addresses, and exposes highestAddressIndex. It probes the derivation wallet when live provider data is unavailable.
Scan the complete live pool
DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swift, DashWallet/Sources/UI/Menu/Tools/MasternodesScreen.swift
Owner and voting address scans use the available pool depth. WalletKeysOverviewModel uses fallbackScanWindow when depth is unavailable, while MasternodesViewModel scans no addresses when the upper bound is unavailable.

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

🚥 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 and concisely describes the main change: reading masternode owner and voting addresses from the live pool.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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/masternode-keys-persisted-pool

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 value

Rename masterPath to satisfy SwiftLint.

SwiftLint reports inclusive_language for masterPath. Rename the private property and its uses, for example, to derivationPath.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4d58887 and b721e3a.

📒 Files selected for processing (3)
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swift
  • DashWallet/Sources/UI/Menu/Tools/MasternodesScreen.swift

@QuantumExplorer QuantumExplorer changed the title fix(masternode-keys): read owner/voting addresses from the live pool fix(wallet): read masternode owner/voting addresses from the live pool Aug 7, 2026
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]>
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.

1 participant