librustzcash icon indicating copy to clipboard operation
librustzcash copied to clipboard

zcash_client_sqlite: Off-by-one in `truncate_to_height`

Open str4d opened this issue 11 months ago • 0 comments

truncate_to_height removes chain-related wallet data above the given block_height. The trees are truncated to the state as of that height, but the checkpoint at that height is removed: https://github.com/zcash/librustzcash/blob/3dcac7a5ff11821c77f0c50a3a86c63cd27193da/zcash_client_sqlite/src/wallet.rs#L1908-L1914

This leaves a hole in the checkpoints: after the next block addition, a checkpoint gets added there, but we don't have one for the previous block.

In practice, other bugs and behaviours are conspiring to ensure that essentially no one encounters this bug:

  • We currently don't index backwards with confirmations by height, but by number of checkpoints (so we'd just skip over the hole).
  • The usual behaviour in our SDKs with a reorg (which heuristically is generally only one or two blocks) is to truncate by 10 blocks and then rescan; this means that there are enough surrounding checkpoints that one hole doesn't really matter.

str4d avatar Mar 12 '24 21:03 str4d