Skip to content

Commit 669794a

Browse files
committed
[Startup][Wallet] Don't continue rescanning the wallet if shutdown was requested.
1 parent e0e9498 commit 669794a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/init.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,10 @@ bool AppInit2()
17461746
uiInterface.InitMessage(_("Rescanning..."));
17471747
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight);
17481748
const int64_t nWalletRescanTime = GetTimeMillis();
1749-
pwalletMain->ScanForWalletTransactions(pindexRescan, true);
1749+
if (pwalletMain->ScanForWalletTransactions(pindexRescan, true, true) == -1) {
1750+
LogPrintf("Shutdown requested over the txs scan. Exiting.\n");
1751+
return false;
1752+
}
17501753
LogPrintf("Rescan completed in %15dms\n", GetTimeMillis() - nWalletRescanTime);
17511754
pwalletMain->SetBestChain(chainActive.GetLocator());
17521755
nWalletDBUpdated++;

src/wallet/wallet.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,9 @@ bool CWalletTx::WriteToDisk()
12641264
* Scan the block chain (starting in pindexStart) for transactions
12651265
* from or to us. If fUpdate is true, found transactions that already
12661266
* exist in the wallet will be updated.
1267+
* @returns -1 if process was cancelled or the number of tx added to the wallet.
12671268
*/
1268-
int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
1269+
int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate, bool fromStartup)
12691270
{
12701271
int ret = 0;
12711272
int64_t nNow = GetTime();
@@ -1290,6 +1291,12 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
12901291
if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0)
12911292
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
12921293

1294+
if (fromStartup) {
1295+
if (ShutdownRequested()) {
1296+
return -1;
1297+
}
1298+
}
1299+
12931300
CBlock block;
12941301
ReadBlockFromDisk(block, pindex);
12951302
for (CTransaction& tx : block.vtx) {

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
506506
void SyncTransaction(const CTransaction& tx, const CBlock* pblock);
507507
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);
508508
void EraseFromWallet(const uint256& hash);
509-
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
509+
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false, bool fromStartup = false);
510510
void ReacceptWalletTransactions();
511511
void ResendWalletTransactions();
512512
CAmount GetBalance() const;

0 commit comments

Comments
 (0)