mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
wallet: take use of FastWalletRescanFilter
Can be reviewed with `--ignore-all-space`.
This commit is contained in:
parent
70b3513904
commit
935c6c4b23
1 changed files with 47 additions and 30 deletions
|
@ -1814,7 +1814,11 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
|
||||||
uint256 block_hash = start_block;
|
uint256 block_hash = start_block;
|
||||||
ScanResult result;
|
ScanResult result;
|
||||||
|
|
||||||
WalletLogPrintf("Rescan started from block %s...\n", start_block.ToString());
|
std::unique_ptr<FastWalletRescanFilter> fast_rescan_filter;
|
||||||
|
if (!IsLegacy() && chain().hasBlockFilterIndex(BlockFilterType::BASIC)) fast_rescan_filter = std::make_unique<FastWalletRescanFilter>(*this);
|
||||||
|
|
||||||
|
WalletLogPrintf("Rescan started from block %s... (%s)\n", start_block.ToString(),
|
||||||
|
fast_rescan_filter ? "fast variant using block filters" : "slow variant inspecting all blocks");
|
||||||
|
|
||||||
fAbortRescan = false;
|
fAbortRescan = false;
|
||||||
ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), 0); // show rescan progress in GUI as dialog or on splashscreen, if rescan required on startup (e.g. due to corruption)
|
ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), 0); // show rescan progress in GUI as dialog or on splashscreen, if rescan required on startup (e.g. due to corruption)
|
||||||
|
@ -1841,9 +1845,16 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
|
||||||
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", block_height, progress_current);
|
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", block_height, progress_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read block data
|
bool fetch_block{true};
|
||||||
CBlock block;
|
if (fast_rescan_filter) {
|
||||||
chain().findBlock(block_hash, FoundBlock().data(block));
|
fast_rescan_filter->UpdateIfNeeded();
|
||||||
|
auto matches_block{fast_rescan_filter->MatchesBlock(block_hash)};
|
||||||
|
if (matches_block.has_value() && !*matches_block) {
|
||||||
|
result.last_scanned_block = block_hash;
|
||||||
|
result.last_scanned_height = block_height;
|
||||||
|
fetch_block = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Find next block separately from reading data above, because reading
|
// Find next block separately from reading data above, because reading
|
||||||
// is slow and there might be a reorg while it is read.
|
// is slow and there might be a reorg while it is read.
|
||||||
|
@ -1852,6 +1863,11 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
|
||||||
uint256 next_block_hash;
|
uint256 next_block_hash;
|
||||||
chain().findBlock(block_hash, FoundBlock().inActiveChain(block_still_active).nextBlock(FoundBlock().inActiveChain(next_block).hash(next_block_hash)));
|
chain().findBlock(block_hash, FoundBlock().inActiveChain(block_still_active).nextBlock(FoundBlock().inActiveChain(next_block).hash(next_block_hash)));
|
||||||
|
|
||||||
|
if (fetch_block) {
|
||||||
|
// Read block data
|
||||||
|
CBlock block;
|
||||||
|
chain().findBlock(block_hash, FoundBlock().data(block));
|
||||||
|
|
||||||
if (!block.IsNull()) {
|
if (!block.IsNull()) {
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
if (!block_still_active) {
|
if (!block_still_active) {
|
||||||
|
@ -1882,6 +1898,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
|
||||||
result.last_failed_block = block_hash;
|
result.last_failed_block = block_hash;
|
||||||
result.status = ScanResult::FAILURE;
|
result.status = ScanResult::FAILURE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (max_height && block_height >= *max_height) {
|
if (max_height && block_height >= *max_height) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue