Skip to content

Commit

Permalink
wallet: use SetBestBlock when saving progress during rescan
Browse files Browse the repository at this point in the history
Instead of writing the best block record directly during a rescan, use
SetBestBlock. This is safe because progress is only saved in a
rescan when doing a rescan on loading. cs_wallet is held the entire time
so new blocks or reorgs will not cause the best block record to be
changed unexpectedly.
  • Loading branch information
achow101 committed Jan 31, 2025
1 parent 94d62a2 commit 56b2575
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1991,13 +1991,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
result.last_scanned_height = block_height;

if (save_progress && next_interval) {
CBlockLocator loc = m_chain->getActiveChainLocator(block_hash);

if (!loc.IsNull()) {
WalletLogPrintf("Saving scan progress %d.\n", block_height);
WalletBatch batch(GetDatabase());
batch.WriteBestBlock(BestBlock{loc, block_hash, block_height});
}
WalletLogPrintf("Saving scan progress %d.\n", block_height);
SetBestBlock(block_height, block_hash);
}
} else {
// could not scan block, keep scanning but record this block as the most recent failure
Expand Down

0 comments on commit 56b2575

Please sign in to comment.