Skip to content

A shielded Clear that resets the tree but fails to purge leaves the balance reported as known #5988

Done

Description

@llbartekll

Expected Behavior

After a shielded Clear has reset the commitment tree, no account's local balance is reported as established until a scan or a restore covers the new tree.

Current Behavior

NetworkShieldedCoordinator::clear resets the tree and then calls purge_all_subwallets. When the reset succeeds and the purge fails, the notes, watermarks and scan provenance stay in the store; Clear then clears hydration and returns the error.

local_balance_snapshot returns RestoreIncomplete for an unhydrated wallet only when an account's source is not ScannedThisSession. An account that completed a scan in this session therefore still reads Ready with its pre-Clear amount, against an emptied tree.

The same sequence is on v5.1-dev. With #5982 the balance emitter compares states, sees no change and sends nothing, so hosts keep showing the amount as known.

Possible Solution

On the failure path, invalidate scan provenance that predates the tree reset, while keeping the notes and the pending spend records. Cover it with a failed-Clear test that starts from an account with a completed scan.

Steps to Reproduce (for bugs)

  1. Bind a wallet and complete a shielded scan, so the account's source is ScannedThisSession.
  2. Run Clear so that the tree reset succeeds and purge_all_subwallets fails (for example the shielded_pending_spends delete fails).
  3. Read local_balance_snapshot for the wallet.
  4. It returns Ready with the pre-Clear amount.

Found in review of #5982 and confirmed by reading packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs. Not reproduced in a test yet.

Context

Deferred from #5982: #5982 (comment). It needs a storage failure between the two steps of one Clear, and Clear already returns that error to the host, so it was left out of that pull request.

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

    bugplatform-wallet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions