Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,155 Lines • ▼ Show 20 Lines | |||||
* @pre Caller needs to make sure start_block (and the optional stop_block) are | * @pre Caller needs to make sure start_block (and the optional stop_block) are | ||||
* on the main chain after to the addition of any new keys you want to detect | * on the main chain after to the addition of any new keys you want to detect | ||||
* transactions for. | * transactions for. | ||||
*/ | */ | ||||
CWallet::ScanResult CWallet::ScanForWalletTransactions( | CWallet::ScanResult CWallet::ScanForWalletTransactions( | ||||
const BlockHash &start_block, const BlockHash &stop_block, | const BlockHash &start_block, const BlockHash &stop_block, | ||||
const WalletRescanReserver &reserver, bool fUpdate) { | const WalletRescanReserver &reserver, bool fUpdate) { | ||||
int64_t nNow = GetTime(); | int64_t nNow = GetTime(); | ||||
int64_t start_time = GetTimeMillis(); | |||||
assert(reserver.isReserved()); | assert(reserver.isReserved()); | ||||
BlockHash block_hash = start_block; | BlockHash block_hash = start_block; | ||||
ScanResult result; | ScanResult result; | ||||
WalletLogPrintf("Rescan started from block %s...\n", | WalletLogPrintf("Rescan started from block %s...\n", | ||||
start_block.ToString()); | start_block.ToString()); | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | WalletLogPrintf("Rescan started from block %s...\n", | ||||
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", | WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", | ||||
*block_height, progress_current); | *block_height, progress_current); | ||||
result.status = ScanResult::USER_ABORT; | result.status = ScanResult::USER_ABORT; | ||||
} else if (block_height && chain().shutdownRequested()) { | } else if (block_height && chain().shutdownRequested()) { | ||||
WalletLogPrintf("Rescan interrupted by shutdown request at block " | WalletLogPrintf("Rescan interrupted by shutdown request at block " | ||||
"%d. Progress=%f\n", | "%d. Progress=%f\n", | ||||
*block_height, progress_current); | *block_height, progress_current); | ||||
result.status = ScanResult::USER_ABORT; | result.status = ScanResult::USER_ABORT; | ||||
} else { | |||||
WalletLogPrintf("Rescan completed in %15dms\n", | |||||
GetTimeMillis() - start_time); | |||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
void CWallet::ReacceptWalletTransactions( | void CWallet::ReacceptWalletTransactions( | ||||
interfaces::Chain::Lock &locked_chain) { | interfaces::Chain::Lock &locked_chain) { | ||||
▲ Show 20 Lines • Show All 2,737 Lines • ▼ Show 20 Lines | if (tip_height && *tip_height != rescan_height) { | ||||
if (Optional<int> first_block = | if (Optional<int> first_block = | ||||
locked_chain->findFirstBlockWithTimeAndHeight( | locked_chain->findFirstBlockWithTimeAndHeight( | ||||
walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW, | walletInstance->nTimeFirstKey - TIMESTAMP_WINDOW, | ||||
rescan_height, nullptr)) { | rescan_height, nullptr)) { | ||||
rescan_height = *first_block; | rescan_height = *first_block; | ||||
} | } | ||||
} | } | ||||
nStart = GetTimeMillis(); | |||||
{ | { | ||||
WalletRescanReserver reserver(walletInstance.get()); | WalletRescanReserver reserver(walletInstance.get()); | ||||
if (!reserver.reserve() || | if (!reserver.reserve() || | ||||
(ScanResult::SUCCESS != | (ScanResult::SUCCESS != | ||||
walletInstance | walletInstance | ||||
->ScanForWalletTransactions( | ->ScanForWalletTransactions( | ||||
locked_chain->getBlockHash(rescan_height), BlockHash(), | locked_chain->getBlockHash(rescan_height), BlockHash(), | ||||
reserver, true /* update */) | reserver, true /* update */) | ||||
.status)) { | .status)) { | ||||
chain.initError( | chain.initError( | ||||
_("Failed to rescan the wallet during initialization") | _("Failed to rescan the wallet during initialization") | ||||
.translated); | .translated); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
walletInstance->WalletLogPrintf("Rescan completed in %15dms\n", | |||||
GetTimeMillis() - nStart); | |||||
walletInstance->ChainStateFlushed(locked_chain->getTipLocator()); | walletInstance->ChainStateFlushed(locked_chain->getTipLocator()); | ||||
walletInstance->database->IncrementUpdateCounter(); | walletInstance->database->IncrementUpdateCounter(); | ||||
// Restore wallet transaction metadata after -zapwallettxes=1 | // Restore wallet transaction metadata after -zapwallettxes=1 | ||||
if (gArgs.GetBoolArg("-zapwallettxes", false) && | if (gArgs.GetBoolArg("-zapwallettxes", false) && | ||||
gArgs.GetArg("-zapwallettxes", "1") != "2") { | gArgs.GetArg("-zapwallettxes", "1") != "2") { | ||||
WalletBatch batch(*walletInstance->database); | WalletBatch batch(*walletInstance->database); | ||||
▲ Show 20 Lines • Show All 377 Lines • Show Last 20 Lines |