Skip to content

Commit

Permalink
zcash_client_sqlite: Set chain tip to truncation height when truncating
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
str4d committed Sep 22, 2023
1 parent 513abf8 commit b76b028
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions zcash_client_sqlite/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b76b028

Please sign in to comment.