From b76b028b3a84d58318a9f6433f0d3ff95468ac6b Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 22 Sep 2023 15:04:51 +0000 Subject: [PATCH] zcash_client_sqlite: Set chain tip to truncation height when truncating We don't know at truncation time what the latest chain tip is; the chain might have reorged to a shorter heavier chain, or the reorg depth might only be a few blocks. `WalletDb::chain_height` uses the scan queue as its source of truth, so the `Verify` range we add during truncation (to prioritise determining whether the rewind was sufficient) can't extend beyond the block height we know to exist. The next call to `WalletDb::update_chain_tip` will add additional ranges beyond this height, which might include a `Verify` range that ends up merging with the one added during truncation. --- zcash_client_sqlite/src/wallet.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 69fa9e6e3b..70f52d97bf 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -105,8 +105,8 @@ use zcash_client_backend::{ use crate::wallet::commitment_tree::SqliteShardStore; use crate::{ error::SqliteClientError, SqlTransaction, WalletCommitmentTrees, WalletDb, PRUNING_DEPTH, + SAPLING_TABLES_PREFIX, }; -use crate::{SAPLING_TABLES_PREFIX, VERIFY_LOOKAHEAD}; use self::scanning::{parse_priority_code, replace_queue_entries}; @@ -1281,8 +1281,8 @@ pub(crate) fn truncate_to_height( named_params![":end_height": u32::from(block_height + 1)], )?; - // Prioritize the range starting at the height we just rewound to for verification - let query_range = block_height..(block_height + VERIFY_LOOKAHEAD); + // Prioritize the height we just rewound to for verification. + let query_range = block_height..(block_height + 1); let scan_range = ScanRange::from_parts(query_range.clone(), ScanPriority::Verify); replace_queue_entries::( conn, @@ -2192,6 +2192,7 @@ mod tests { st.wallet_mut() .truncate_to_height(mined_height - 1) .unwrap(); + assert_eq!(st.wallet().chain_height().unwrap(), Some(mined_height - 1)); // The wallet should still have zero transparent balance. check_balance(&st, 0, NonNegativeAmount::ZERO);