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.
This commit is contained in:
parent
513abf8b97
commit
b76b028b3a
|
@ -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<P: consensus::Parameters>(
|
|||
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::<SqliteClientError>(
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue