You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
platform-wallet: after a shielded Clear that resets the tree but fails to purge, the next scan resumes from the old watermark into the emptied tree #6184
After a shielded Clear that emptied the commitment tree but could not purge the ledger, the next note scan rebuilds the tree from position 0, or refuses to run until a Clear has gone through.
Current Behavior
NetworkShieldedCoordinator::clear (packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs) resets the commitment tree and then calls purge_all_subwallets. When the reset lands and the purge fails, each subwallet keeps its sync watermark (last_synced_index), while tree_size() is 0. The host is told the Clear failed and keeps its own rows, so a later bind restores the same watermark from them as well (restore_balance_metadata takes the maximum).
sync_notes_across (packages/rs-platform-wallet/src/wallet/shielded/sync.rs) starts from the smallest watermark, rounded down to a chunk, and appends every fetched commitment whose global position is not below the tree size it read at the start:
let global_pos = batch.start_index + i asu64;if global_pos < tree_size {continue;}
store.append_commitment(&cmx_bytes,true)
With a tree of 0 leaves and a watermark of N, the commitment at global position N is appended as leaf 0. The tree then holds leaves at the wrong positions, and a witness built for a kept note does not resolve to a root Platform recorded.
Found by reading the code on v5.1-dev (3b4117c64d) while fixing #5988. Not reproduced in a test: it needs a storage failure between the two steps of one Clear, and a pool with notes behind the watermark.
Possible Solution
In the scan, never start past the tree: clamp the start to tree_size (rounded down to a chunk), so a tree behind the watermark is filled from where it ends.
Or have the failed Clear rewind the watermarks it keeps, and have the restore from host rows not raise them again until a Clear has succeeded.
Bind a wallet and complete a shielded scan, so its watermark is N > 0.
Run Clear so that reset_commitment_tree succeeds and purge_all_subwallets fails (for example the shielded_pending_spends delete fails).
Run a shielded sync.
The first commitment it appends is the one at global position N (rounded down to a chunk), at tree position 0.
Context
Left out of the fix for #5988, which only stops the balance from being reported as known after such a Clear. Clear returns the error to the host, and a Clear that then succeeds empties the tree and the watermarks together, so the state lasts until the user clears again.
Activity