Skip to content

feat(platform-wallet): return the proved block height with a withdrawal's remaining balance - #6027

Draft
Claudius-Maginificent wants to merge 11 commits into
feat/mn-key-referencefrom
feat/mn-withdrawal-height
Draft

Claudius-Maginificent wants to merge 11 commits into
feat/mn-key-referencefrom
feat/mn-withdrawal-height

Conversation

@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator

TL;DR: After a masternode or identity credit withdrawal, the wallet now also gets the block height at which the remaining balance was proved, so it can tell that balance apart from an older balance read.

User story

As a wallet app developer, I want a withdrawal to return the proved block height together with the remaining balance, to achieve correct ordering against balances read elsewhere (a refresh that answered from an older block must not overwrite it).

Scenario

Base flow

The user withdraws credits from a masternode or an identity while the app also refreshes balances in the background.

Actual behavior

The withdrawal returns only the remaining balance. The app cannot tell whether it is newer than a balance a concurrent refresh read.

Expected behavior

The withdrawal returns WithdrawalOutcome { remaining_credits, proved_at }, with proved_at taken from the result proof's metadata.

Detailed discussion

Issue being fixed or feature implemented

Stacked atop #6026 (feat/mn-key-reference), part of the stack over #5889.

What was done?

  • New WithdrawalOutcome { remaining_credits, proved_at: BlockTime } (wallet/identity/types/withdrawal_outcome.rs), built from the result proof's response metadata. There is no height without a proved balance.
  • PlatformWallet::masternode_withdraw, TrackedMasternodes::withdraw and IdentityWallet::withdraw_credits_with_signer return it. The masternode path waits with wait_for_affected_state_with_metadata; the identity path uses withdraw_with_metadata. When an outcome counts as unconfirmed is unchanged.
  • The FFI keeps its balance out-parameter and fills it from remaining_credits; C signatures are unchanged.

How Has This Been Tested?

Existing withdrawal tests updated; workspace callers swept; clippy also run on rs-unified-sdk-ffi and rs-unified-sdk-jni (host target). Not executed: a live testnet withdrawal, the Android cross-build.

Breaking Changes

Public Rust API (not consensus): PlatformWallet::masternode_withdraw, TrackedMasternodes::withdraw and IdentityWallet::withdraw_credits_with_signer return WithdrawalOutcome instead of the bare balance. No FFI change.

Deferred

  • A test that withdraw_credits_with_signer propagates proved_at needs an rs-sdk mock hook for state-transition result proofs (marked TODO in code).
  • The WithdrawalOutcome name serves a crate-wide need (a proved balance with its height) under a withdrawal-only name; renaming or generalising it is a follow-up.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • 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
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

https://claude.ai/code/session_01WunYYk4eUkHuGstPtj83j4

🤖 Co-authored by Claudius the Magnificent AI Agent

@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@thepastaclaw

thepastaclaw commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 7cf6be2. Normal review starts when eligible; priority review starts as soon as a slot is available.

lklimek and others added 9 commits December 1, 2026 08:39
…its height

Add SpvRuntime::current_masternode_list, returning a CurrentMasternodeList
(the list's known height and its summaries from one snapshot) only while
the list follows the chain, through the existing while_following_the_chain
gate. CurrentMasternodeList::key_reference gives the list-known keys of a
node, or None when the node is not on the list. The crate-private
current_masternode_list_summaries is now a projection of it; its callers
see the same results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…ternodeListUnavailable

SpvRuntime::current_masternode_list returns
Err(PlatformWalletError::MasternodeListUnavailable) instead of None while
the list does not follow the chain or SPV restarted during the read, the
error #5889's callers already map that case to. The crate-private
current_masternode_list_summaries keeps returning None in that case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…e and describe its dash-spv follow-up in words

CurrentMasternodeList is exported from `masternode` only, like
MasternodeListSummary and MasternodeKeyReference. The TODO on
current_masternode_list names the dependency in words, as no upstream
issue exists yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…m the list and its Platform identities

Add PlatformWalletManager::fetch_masternode_key_reference: the current
masternode list's fields joined with the owner and payout key hashes of
the node's owner identity and the operator payout key hash of its
operator identity, for any node, tracked or not. Nothing is persisted.
It fails with MasternodeListUnavailable while the list does not follow
the chain; a node absent from the list but with an owner identity
(retired, credits still claimable) gets its list fields None; Ok(None)
when neither the list nor Platform knows the node.

Fix the tracked-node refresh with the same rule: it took any key of the
purpose, so after a payout address change it could keep a disabled
TRANSFER key depending on key-id order. One helper now picks the enabled
ECDSA_HASH160 key. The refresh also reads the list only while it follows
the chain, so a stale list no longer overwrites the cached entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…entity disables it

Reproduction tests: they fail until learn_owner_identity and
learn_operator_identity stop keeping a previously learned key when the
fetched identity has no enabled key of that purpose.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ched identity disables it

The tracked-node refresh kept the last known owner and operator payout
key hashes when the freshly fetched identity had no enabled key for them.
Drive disables every owner TRANSFER key when the payout is no sole P2PKH
output, and the operator TRANSFER key when the operator payout is
removed, so the kept key was stale. A fetched identity now sets the key
hashes to its enabled keys; a failed or empty fetch still leaves the
snapshot as it was.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…ut of tracked reads

Once the owner identity has been read, its keys are the current ones:
TrackedMasternode::key_reference and record no longer fall back to the
registered payout script (or owner key) when the identity holds no
enabled key for it, so a retired payout key no longer comes back. Before
that read, the registration is still used.

Add CurrentMasternodeList::entry and use it for the per-node lookups in
key_reference and the tracked refresh. Fold the learn tests that
re-asserted the enabled-key ordering into the learn regression tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
lklimek and others added 2 commits December 2, 2026 16:10
…al's remaining balance

Add WithdrawalOutcome { remaining_credits, proved_at: BlockTime }, built
from the result proof's response metadata, so a host can tell a
withdrawal's proved balance from an older balance read.

PlatformWallet::masternode_withdraw, TrackedMasternodes::withdraw and
IdentityWallet::withdraw_credits_with_signer return it instead of the bare
balance; the masternode path waits with
wait_for_affected_state_with_metadata, the identity path uses
withdraw_with_metadata. When an outcome is unconfirmed is unchanged.

These public Rust signatures change (not consensus). The FFI keeps its
balance out-parameter and reads remaining_credits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
@lklimek
lklimek force-pushed the feat/mn-withdrawal-height branch from 3612e42 to 7cf6be2 Compare December 3, 2026 07:11

This branch has not been deployed

No deployments
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.

3 participants