Skip to content

platform-wallet: an asset-lock build is not excluded from wallet removal, so a lock can be broadcast for a wallet that is gone #5516

Open

Description

@romchornyi

Expected Behavior

Removing a wallet (teardown_guard) and building + broadcasting an asset lock for it exclude each other, as they do for payments (payment_guard): either the lock is tracked, persisted and broadcast while the wallet exists, or nothing reaches the broadcaster.

Current Behavior

AssetLockManager::broadcast_funded_asset_lock_with_operation builds the lock, stores the funding pools, tracks the lock (track_asset_lock), queues its row and broadcasts it without holding the generation's payment_guard (build.rs). A removal that interleaves anywhere in that sequence leaves one of:

  1. Removed before tracking. track_asset_lock inserts nothing and returns an empty changeset, and the lock is still broadcast: funds on chain with no row to resume them from. On the wallet-drain path the same empty changeset is dropped.
  2. Removed after tracking, before or during the broadcast. The lock is broadcast, and its Built row is queued to a persister whose wallet data is gone.
  3. Removed during the funding-pool store. The pool rows are written for a wallet the host has deleted.
  4. Removed and re-created under the same id between the build and tracking. The lock is tracked into the new generation, whose reservations and in-broadcast fences know nothing of its inputs.

A one-shot "did tracking insert?" check only narrows case 1, and would make WalletNotFound mean both "nothing was sent" and "sent, then the row update failed".

Possible Solution

Give AssetLockManager access to the wallet's generation and hold payment_guard across the liveness check, tracking, the row persist and the broadcast, as the payment paths do. Lock order: the guard is taken before the wallet-manager lock. The guard must be taken after any external signing returns (see payment_guard's docs) so an open signer prompt cannot stall a teardown.

Steps to Reproduce

Not reproduced in an app; a race found in review. Shape: remove a wallet while an asset lock for it is being built (identity registration, top-up, shield, wallet drain).

Context

Raised by CodeRabbit on #5476 (an existing gap, not introduced there). Related: #5460, #5476.

Your Environment

platform v5.1-dev with #5476 (3e5d167cb1).

Activity

  1. added
    bug
    on Oct 21, 2026
  2. HashEngineering commented on Dec 2, 2026

    @HashEngineering
    Collaborator

    Three more cases of this class came up while reviewing #5931. They're left for this issue, not that PR:

    1. A resume can broadcast after the wallet is removed. resume_asset_lock_with checks the wallet's generation when it starts, then awaits the proof probe and the transport. Its broadcasts don't hold the wallet's lifecycle guard or check the generation again, so a removal that finishes during those awaits doesn't stop the send. On v5.2-dev the generic resume has no generation check at all.
    2. Abandoned-lock cleanup can delete a row that a replacement wallet already restored. When an unbound top-up's row can't be made durable before sending, the cleanup in build.rs deletes the row first and only then checks whether the wallet was replaced. If another flush committed the row, and the wallet was removed, reloaded and started resuming the lock in the meantime, the deletion loses the recorded recipient. A restart then recovers the lock from the chain without it (code 89), and the user has to assign it again.
    3. A failed identity lookup decides "held" from a later read of the row. In feat(platform-wallet): top up someone else's identity from the Core balance #5931's existing-lock top-up, the error branch checks whether a row exists after the lookup. A teardown during the lookup can turn a known lock into a retryable NotSent. Separately, a lock recorded for another identity can be reported as held. PastaClaw suggests one outcome boundary in AssetLockManager: it carries what the operation already knows about dispatch and names a lock as held only while it can still serve the intended payment.

    The fix for all three is the same: hold the wallet's lifecycle across the operation, or check the generation again right before each dispatch and deletion.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions