Skip to content

fix(platform-wallet): report a note beyond the rebuilt tree as retryable while a scan is pending - #6481

Draft
lklimek wants to merge 1 commit into
fix/shielded-tree-consistencyfrom
fix/shielded-retryable-witness-after-rebuild
Draft

lklimek wants to merge 1 commit into
fix/shielded-tree-consistencyfrom
fix/shielded-retryable-witness-after-rebuild

Conversation

@lklimek

@lklimek lklimek commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

TL;DR

After the wallet repairs its shielded note tree, paying from a note the repair has not reached yet now returns the usual "try again after sync" error instead of a permanent storage error.

User story

As a wallet user, when I spend shielded funds right after my wallet repaired its note tree, I get an error that tells my app to retry after sync, so the payment succeeds once the rescan catches up.

Scenario

Actual behavior

#5565 lets the wallet rebuild its shielded commitment tree while keeping the notes it already knows. Until the rescan reaches a note again, the rebuilt tree is shorter than that note's position. Spending that note then fails with a generic store error ("note position N is not in the commitment tree (size M)"), which hosts treat as non-retryable. A note below the current tree size gets the retryable ShieldedMerkleWitnessUnavailable (FFI code 88), so results are inconsistent during the rescan.

Expected behavior

While a scan that will reach the note's position is still pending for its subwallet, the spend gets ShieldedMerkleWitnessUnavailable (code 88, retryable). A position that no pending scan will reach still returns the store error.

Detailed discussion

Builds on #5565 (stacked; reported there as an outside-diff review item).

  • witness_at_depth (wallet/shielded/file_store.rs) returns Ok(None) instead of Err for a position at or past the tree size when the tree was reset and the owning restored subwallet has not completed a scan since. The existing spend path maps Ok(None) to ShieldedMerkleWitnessUnavailable.
  • The store trait docs (store.rs) and the variant docs describe the rebuild case.
  • No new error variant and no FFI mapping change. The new branch never returns a Merkle path, so it cannot produce a spend with a wrong witness.

Testing

should_retry_a_retained_note_beyond_the_rebuilt_tree_until_the_scan_completes: a note beyond the emptied tree is retryable before the scan and gets a valid witness after it; a stale tail note gets ShieldedStoreError once the pool's confirmed end is reached; a missing position with no retained note keeps the store error. platform-wallet clippy (all targets, all features) clean; store, scan and spend-selection tests green.

Out of scope

None.

Known limitations

If syncs never complete, a note beyond the rebuilt tree stays retryable indefinitely (the same as any note waiting for its witness).

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thepastaclaw

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 450646c. Normal review starts when eligible; priority review starts as soon as a slot is available.

@lklimek
lklimek removed this pull request from stack #6483 December 3, 2026 09:41
@lklimek
lklimek added this pull request to stack #6485 December 3, 2026 09:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants