fix(rpc): rescan already-scanned range when z_importkey re-imports a known key with rescan=yes#581
fix(rpc): rescan already-scanned range when z_importkey re-imports a known key with rescan=yes#581oxarbitrage wants to merge 1 commit into
Conversation
Handoff from zcash/integration-tests #76: the
|
8ed6618 to
e451c24
Compare
…known key with rescan=yes
e451c24 to
3e96317
Compare
|
Confirmed: rebuilt |
|
Interop status update: the Root cause is on the integration-tests side: after the Once #161 merges I'll re-trigger this PR's interop so it builds |
Closes #578.
Follow-up to #579 (merged), which made key imports scan going forward without a restart. #578 is the other half: re-importing an already-known key with
rescan="yes"did nothing (z_importkeyshort-circuits onis_new_key). New keys are already covered by the backend'sadd_accountre-queue; this wires up the existing-key path.What changed (one file,
import_key.rs): when the key is already known andrescan="yes",truncate_to_height(start_height - 1)so the sync engine re-scansstart_height..=tipand finds notes in blocks scanned before this key was known.(An earlier revision used the account-scoped
rewind_to_chain_state, but it corrupts the wallet DB on a deep rewind — it doesn't snap the truncation target to a checkpoint shared by the Sapling and Orchard trees. Caught by the integration-tests #76 reproducer.truncate_to_heightsnaps to a shared checkpoint, so it's cross-pool-safe.)Behavior notes:
start_height..=tip(re-scanning requires rewinding the note-commitment trees — heavier than zcashd's additive rescan).truncate_to_heightsnaps down to a shared checkpoint, so the rescan may start slightly belowstart_height. Astart_heightbelow the wallet's tree state fails cleanly withRequestedRewindInvalid— rescanning below existing tree state isn't supported (beyond Rescan already-scanned ranges when a key/account is imported with an earlier birthday #578's "birthday in an already-scanned range" scope).Testing: builds / clippy / fmt clean, unit tests pass. E2E regtest in zcash/integration-tests#76 — all three rescan-on-import scenarios pass against this branch (
truncate_to_heightrevision): therescan="yes"rewind surfaces a previously-missed note, a fresh early-birthday import finds a historical note (#579), and a spend from an imported key still fails (tracked separately). Note the rewind can only target the lastCOINBASE_MATURITYblocks (the truncation floor), which the test respects.ZIT-Revision: export-import-key-test