Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,810 Lines • ▼ Show 20 Lines | CBlockIndex *CWallet::ScanForWalletTransactions( | ||||
{ | { | ||||
fAbortRescan = false; | fAbortRescan = false; | ||||
// Show rescan progress in GUI as dialog or on splashscreen, if -rescan | // Show rescan progress in GUI as dialog or on splashscreen, if -rescan | ||||
// on startup. | // on startup. | ||||
ShowProgress(_("Rescanning..."), 0); | ShowProgress(_("Rescanning..."), 0); | ||||
CBlockIndex *tip = nullptr; | CBlockIndex *tip = nullptr; | ||||
double dProgressStart; | double progress_begin; | ||||
double dProgressTip; | double progress_end; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
tip = chainActive.Tip(); | progress_begin = | ||||
dProgressStart = | |||||
GuessVerificationProgress(chainParams.TxData(), pindex); | GuessVerificationProgress(chainParams.TxData(), pindex); | ||||
dProgressTip = GuessVerificationProgress(chainParams.TxData(), tip); | if (pindexStop == nullptr) { | ||||
tip = chainActive.Tip(); | |||||
progress_end = | |||||
GuessVerificationProgress(chainParams.TxData(), tip); | |||||
} else { | |||||
progress_end = | |||||
GuessVerificationProgress(chainParams.TxData(), pindexStop); | |||||
} | |||||
} | } | ||||
double gvp = dProgressStart; | double progress_current = progress_begin; | ||||
while (pindex && !fAbortRescan && !ShutdownRequested()) { | while (pindex && !fAbortRescan && !ShutdownRequested()) { | ||||
if (pindex->nHeight % 100 == 0 && | if (pindex->nHeight % 100 == 0 && | ||||
dProgressTip - dProgressStart > 0.0) { | progress_end - progress_begin > 0.0) { | ||||
ShowProgress( | ShowProgress( | ||||
_("Rescanning..."), | _("Rescanning..."), | ||||
std::max( | std::max( | ||||
1, std::min(99, (int)((gvp - dProgressStart) / | 1, | ||||
(dProgressTip - dProgressStart) * | std::min(99, (int)((progress_current - progress_begin) / | ||||
(progress_end - progress_begin) * | |||||
100)))); | 100)))); | ||||
} | } | ||||
if (GetTime() >= nNow + 60) { | if (GetTime() >= nNow + 60) { | ||||
nNow = GetTime(); | nNow = GetTime(); | ||||
LogPrintf("Still rescanning. At block %d. Progress=%f\n", | LogPrintf("Still rescanning. At block %d. Progress=%f\n", | ||||
pindex->nHeight, gvp); | pindex->nHeight, progress_current); | ||||
} | } | ||||
CBlock block; | CBlock block; | ||||
if (ReadBlockFromDisk(block, pindex, chainParams.GetConsensus())) { | if (ReadBlockFromDisk(block, pindex, chainParams.GetConsensus())) { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
if (pindex && !chainActive.Contains(pindex)) { | if (pindex && !chainActive.Contains(pindex)) { | ||||
// Abort scan if current block is no longer active, to | // Abort scan if current block is no longer active, to | ||||
// prevent marking transactions as coming from the wrong | // prevent marking transactions as coming from the wrong | ||||
Show All 10 Lines | if (pindex) { | ||||
ret = pindex; | ret = pindex; | ||||
} | } | ||||
if (pindex == pindexStop) { | if (pindex == pindexStop) { | ||||
break; | break; | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
pindex = chainActive.Next(pindex); | pindex = chainActive.Next(pindex); | ||||
gvp = GuessVerificationProgress(chainParams.TxData(), pindex); | progress_current = | ||||
if (tip != chainActive.Tip()) { | GuessVerificationProgress(chainParams.TxData(), pindex); | ||||
if (pindexStop == nullptr && tip != chainActive.Tip()) { | |||||
tip = chainActive.Tip(); | tip = chainActive.Tip(); | ||||
// in case the tip has changed, update progress max | // in case the tip has changed, update progress max | ||||
dProgressTip = | progress_end = | ||||
GuessVerificationProgress(chainParams.TxData(), tip); | GuessVerificationProgress(chainParams.TxData(), tip); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (pindex && fAbortRescan) { | if (pindex && fAbortRescan) { | ||||
LogPrintf("Rescan aborted at block %d. Progress=%f\n", | LogPrintf("Rescan aborted at block %d. Progress=%f\n", | ||||
pindex->nHeight, gvp); | pindex->nHeight, progress_current); | ||||
} else if (pindex && ShutdownRequested()) { | } else if (pindex && ShutdownRequested()) { | ||||
LogPrintf("Rescan interrupted by shutdown request at block %d. " | LogPrintf("Rescan interrupted by shutdown request at block %d. " | ||||
"Progress=%f\n", | "Progress=%f\n", | ||||
pindex->nHeight, gvp); | pindex->nHeight, progress_current); | ||||
} | } | ||||
// Hide progress dialog in GUI. | // Hide progress dialog in GUI. | ||||
ShowProgress(_("Rescanning..."), 100); | ShowProgress(_("Rescanning..."), 100); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,882 Lines • Show Last 20 Lines |