Skip to content

swift-sdk: shielded spend wrappers on v5.1-dev run without native-operation admission, so Clear, wallet deletion or shutdown can overlap a payment #6060

Done

Description

@QuantumExplorer

What happens

On v5.1-dev, the Swift wrappers that start a shielded payment call their FFI export from Task.detached without admitNativeOp / finishNativeOp:

shieldedShield, shieldedShieldToRecipient, shieldedTransfer, shieldedUnshield, shieldedWithdraw, shieldedFundFromAssetLock, shieldedIdentityCreateFromPool, shieldedShieldFromIdentity, shieldedIdentityTopUpFromPool.

clearShielded() also does not check ensureSyncNativeOpAllowed. So while one of these payments runs (its proof alone takes tens of seconds):

  • clearShielded() or deleteWallet(...) from another scene sharing the manager can run, and Clear can purge a signed retry record or note reservation the payment has just saved, while the payment still goes on to broadcast;
  • shutdown() does not wait for the payment before destroying the handle.

Rust's shield_guard serializes payments against each other, but these paths do not hold the guards teardown uses.

Where it showed up

Review of #6051, which adds app screens for shieldedShieldFromIdentity and shieldedIdentityTopUpFromPool (thread: #6051). The gap is in the wrappers and applies to every shielded payment the app already exposes, so it is tracked here.

Existing fix to follow

#5863 on v5.2-dev (commit aba2e7bb4a) does this for shieldedShieldFromIdentityToRecipient: the call is admitted from before the detached task until the result is delivered, clearShielded() calls ensureSyncNativeOpAllowed, and an injectable native-call seam lets tests pause a payment in flight. The same pattern should cover every wrapper listed above, with tests for Clear, deletion and shutdown during a paused payment.

Activity

  1. QuantumExplorer commented on Nov 22, 2026

    @QuantumExplorer
    MemberAuthor

    One more item for the same wrapper follow-up, from the #6051 review: shieldedIdentityDebitRecoveryRecords runs its FFI call from Task.detached, and the export's block_on_worker parks that thread while the coordinator waits for the store lock with no deadline (a scan holds the write lock across its network batches). Reopening or refreshing a screen that reads the records during a slow scan can therefore stack parked threads. localShieldedBalanceSnapshot already bounds its native lock wait (100 ms) and admits as a native operation; the recovery read should do the same. SwiftExampleApp now coalesces these reads (#6051), which limits but does not remove it.

  2. QuantumExplorer commented on Nov 23, 2026

    @QuantumExplorer
    MemberAuthor

    One more consequence to cover here, from the review of #6183.

    A shielded Clear that runs while an identity top-up (type 22) or a private document create (type 29) waits for its result purges the spend's activity row. When the result then arrives, the handler finds no stored row, falls back to the Pending row it captured before the broadcast, writes it back as Confirmed and returns success (write_activity_status in rs-platform-wallet/src/wallet/shielded/operations.rs, the stored.as_ref().unwrap_or(entry) fallback). If the note scan had failed that row on proof before the Clear (#6151), that proof is gone with the row, so the protection #6183 adds does not apply.

    The fallback is shared by every note spend's result handler and predates #6183. The fix belongs with the admission work: hold shared operation admission in the Rust entry points (shielded_identity_top_up_from_pool, create_private_document_entry, the private contact payment) through settlement, as the token transfer does, so Clear waits for the result. A test should run Clear between the scan failing the row and the snapshot settling.

  3. QuantumExplorer commented on Nov 24, 2026

    @QuantumExplorer
    MemberAuthor

    #6179 admits the payment wrappers listed here except one, and closes this issue when it merges. What it leaves open, and where each item is tracked:

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions