Skip to content

platform-wallet: one identity top-up from Platform addresses for any identity, with Rust choosing the inputs and the lifecycle gate taken after signing #5925

Open

Description

@romchornyi

Expected Behavior

A host tops up an identity from Platform addresses with one call: the identity id, the account and the amount. Rust decides whether the wallet manages the identity, picks the funding inputs, and holds the wallet's lifecycle gate only around the liveness check, the broadcast and the bookkeeping, as the gate's contract says.

Current Behavior

After #5860 the operation has three shapes that the host has to get right:

  1. Two entry points for one operation. top_up_from_addresses (managed identity) and top_up_external_identity_from_addresses (any other identity) differ in where the Identity comes from (the identity manager, top_up_from_addresses.rs#L79-L103, vs Identity::fetch, #L174-L192) and in whether the managed balance is written back, which the managed path already does conditionally (#L135). The FFI (identity_top_up.rs#L111, #L211) and Swift (ManagedPlatformWallet.swift#L773, #L797) export both, so each app decides "is this identity mine?" on its own. Apps already define it differently from the SDK (for example "the current identity" rather than "an identity the wallet manages"), and a managed identity sent through the external path keeps a stale cached balance until the next sync.
  2. The host selects the funding inputs. Both exports take caller-built input rows, so apps copy Rust's input-order and fee-source rules and a headroom constant. The sibling operation, shielding from addresses, takes an account and an amount and lets Rust select (platform_wallet.rs#L224). While the host picks inputs, Rust has nothing to reserve, so the limit documented at top_up_from_addresses.rs#L311-L322 (two concurrent spends from one address can be signed with the same nonce) cannot be closed.
  3. The lifecycle gate spans the whole top-up. top_up_identity_with takes the payment guard and then awaits the identity fetch, the nonce fetch, the host's signer, the broadcast and the result wait; the FFI passes no wait timeout. The gate's contract (generation.rs#L444-L451) says operations awaiting an external signer take it only after the signature returns, so an open signing prompt cannot stall teardown. Removing a wallet while its top-up waits on the signer or on Platform therefore waits for the whole operation, and the write-preferring lock queues every later payment of that wallet behind the removal. should_hold_a_wallets_removal_until_its_top_up_returns pins this as intended; it was agreed on feat(platform-wallet)!: top up an identity the wallet does not manage from Platform addresses #5860 to close a window where a retained handle could broadcast after removal.

Possible Solution

Steps to Reproduce

Read-only finding from an architecture review of #5860; no runtime reproduction. Item 3 is what should_hold_a_wallets_removal_until_its_top_up_returns asserts.

Context

Hosts (Dash Wallet iOS, Android) each rebuild the managed/external decision and the input selection. Related: #5860 (introduces the external export), #5924 (Core → someone else's identity), dashpay/dashwallet-ios#1358 (the iOS route that calls it).

Your Environment

platform feat/platform-wallet-external-identity-top-up at 2ce86e8430 (#5860 head), based on v5.2-dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions