Skip to content

platform-wallet: deferred contact-crypto drain is not bound to the wallet generation it started on #5641

Open

Description

@romchornyi

Expected Behavior

A deferred contact-crypto drain runs against one wallet generation. If that generation is removed or replaced while the drain is in flight, the drain stops before it registers anything in the replacement.

Current Behavior

drain_pending_contact_crypto_verified keys every step on wallet_id, not on a generation:

  • it reads the queue from the wallet currently registered under that id;
  • it verifies the provider against the same wallet;
  • after awaiting provider derivation and contact fetches, register_contact_account and register_external_contact_account write to whichever wallet is registered under the id at that moment.

No generation lifecycle guard is taken first. Callers:

If a wallet is removed and re-registered under the same id while a drain is awaiting the provider, the drain finishes in the new generation. The payment paths reject the stale core handle only afterwards.

The impact is limited. A wallet can be re-registered under the same id only if it has the same root key (compute_wallet_id), so the accounts the drain installs are the ones the new generation would derive itself, and a registration that already exists is a no-op. The concern is lifecycle discipline: an operation that started on one generation should not write into another.

Possible Solution

Pass the originating generation into the drain, as the payment paths now do with their Option<&Arc<WalletGeneration>>. Then:

  • re-check it is current before each registration and stop when it is not; or
  • take the generation's lifecycle guard around each registration, not across the provider work, so a teardown never waits on a slow host resolver.

Steps to Reproduce

Needs a test hook: block the contact-crypto provider inside a drain, remove the wallet, register it again from the same seed, then release the provider. The new generation receives contact-account registrations from the old drain.

Context

Raised by the review bot on #5465. It is not specific to that PR: every caller listed above has the same ordering on v5.1-dev.

Your Environment

platform v5.1-dev @ 13c8b0a; #5465 @ dfbeb7d.

🤖 Generated with Claude Code

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions