Repository navigation
Description
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:
- Two entry points for one operation.
top_up_from_addresses(managed identity) andtop_up_external_identity_from_addresses(any other identity) differ in where theIdentitycomes from (the identity manager, top_up_from_addresses.rs#L79-L103, vsIdentity::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. - 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.
- The lifecycle gate spans the whole top-up.
top_up_identity_withtakes 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_returnspins 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
- One Rust operation,
top_up_identity_from_addresses(identity_id, account, amount), with a preflight likeshielded_shield_preflight: fetch the identity from Platform, write the managed balance back when the wallet holds that identity, never add an identity to the manager. One FFI export and one Swift and Kotlin method; the two current exports are deprecated, then removed. - Rust selects and reserves the inputs, as shielding from addresses does.
- Take the gate after signing, across liveness check → broadcast → bookkeeping, as the contact-request send does (contact_requests.rs#L7492). A wallet removed during signing is then refused at the liveness check. This reverses the agreement on feat(platform-wallet)!: top up an identity the wallet does not manage from Platform addresses #5860 and needs a maintainer's decision: the alternative is to keep the gate wide and document that removal waits for an open signing prompt.
- platform-wallet: top up someone else's identity from Core, with the recipient recorded on the asset lock before broadcast #5924 (Core → someone else's identity) should use the same single entry point, so the managed/external choice is made in Rust for both funding sources.
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.
Activity