Skip to content

Commit bdd7217

Browse files
committed
Merge #15901: wallet: log on rescan completion
1b602f6 remove extraneous scope (andrewtoth) 6ad372a wallet: log on rescan completion (andrewtoth) Pull request description: Currently there is nothing logged when a rescan completes successfully. This leaves the last log message something like: ``` Still rescanning. At block 573037. Progress=0.998415 ``` It is unclear when the rescan actually finished. This adds a `Rescan completed.` message to make it more clear. ACKs for commit 1b602f: Empact: utACK bitcoin/bitcoin@1b602f6 meshcollider: utACK bitcoin/bitcoin@1b602f6 Tree-SHA512: 618d646a0f143c2372f1db91c14e7f677b39fb3a2957e887cbc349971c3e8953bc017e2028ac489368c20dbb9a7265c4c2d448c95de785366acfe0e576f1be66
2 parents 3356799 + 1b602f6 commit bdd7217

File tree

1 file changed

+74
-75
lines changed

1 file changed

+74
-75
lines changed

src/wallet/wallet.cpp

Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,7 @@ int64_t CWallet::RescanFromTime(int64_t startTime, const WalletRescanReserver& r
17711771
CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_block, const uint256& stop_block, const WalletRescanReserver& reserver, bool fUpdate)
17721772
{
17731773
int64_t nNow = GetTime();
1774+
int64_t start_time = GetTimeMillis();
17741775

17751776
assert(reserver.isReserved());
17761777

@@ -1779,90 +1780,90 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
17791780

17801781
WalletLogPrintf("Rescan started from block %s...\n", start_block.ToString());
17811782

1783+
fAbortRescan = false;
1784+
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
1785+
uint256 tip_hash;
1786+
// The way the 'block_height' is initialized is just a workaround for the gcc bug #47679 since version 4.6.0.
1787+
Optional<int> block_height = MakeOptional(false, int());
1788+
double progress_begin;
1789+
double progress_end;
17821790
{
1783-
fAbortRescan = false;
1784-
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
1785-
uint256 tip_hash;
1786-
// The way the 'block_height' is initialized is just a workaround for the gcc bug #47679 since version 4.6.0.
1787-
Optional<int> block_height = MakeOptional(false, int());
1788-
double progress_begin;
1789-
double progress_end;
1790-
{
1791-
auto locked_chain = chain().lock();
1792-
if (Optional<int> tip_height = locked_chain->getHeight()) {
1793-
tip_hash = locked_chain->getBlockHash(*tip_height);
1794-
}
1795-
block_height = locked_chain->getBlockHeight(block_hash);
1796-
progress_begin = chain().guessVerificationProgress(block_hash);
1797-
progress_end = chain().guessVerificationProgress(stop_block.IsNull() ? tip_hash : stop_block);
1798-
}
1799-
double progress_current = progress_begin;
1800-
while (block_height && !fAbortRescan && !chain().shutdownRequested()) {
1801-
if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
1802-
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100))));
1803-
}
1804-
if (GetTime() >= nNow + 60) {
1805-
nNow = GetTime();
1806-
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", *block_height, progress_current);
1807-
}
1791+
auto locked_chain = chain().lock();
1792+
if (Optional<int> tip_height = locked_chain->getHeight()) {
1793+
tip_hash = locked_chain->getBlockHash(*tip_height);
1794+
}
1795+
block_height = locked_chain->getBlockHeight(block_hash);
1796+
progress_begin = chain().guessVerificationProgress(block_hash);
1797+
progress_end = chain().guessVerificationProgress(stop_block.IsNull() ? tip_hash : stop_block);
1798+
}
1799+
double progress_current = progress_begin;
1800+
while (block_height && !fAbortRescan && !chain().shutdownRequested()) {
1801+
if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
1802+
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100))));
1803+
}
1804+
if (GetTime() >= nNow + 60) {
1805+
nNow = GetTime();
1806+
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", *block_height, progress_current);
1807+
}
18081808

1809-
CBlock block;
1810-
if (chain().findBlock(block_hash, &block) && !block.IsNull()) {
1811-
auto locked_chain = chain().lock();
1812-
LOCK(cs_wallet);
1813-
if (!locked_chain->getBlockHeight(block_hash)) {
1814-
// Abort scan if current block is no longer active, to prevent
1815-
// marking transactions as coming from the wrong block.
1816-
// TODO: This should return success instead of failure, see
1817-
// https://github.com/bitcoin/bitcoin/pull/14711#issuecomment-458342518
1818-
result.last_failed_block = block_hash;
1819-
result.status = ScanResult::FAILURE;
1820-
break;
1821-
}
1822-
for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) {
1823-
SyncTransaction(block.vtx[posInBlock], block_hash, posInBlock, fUpdate);
1824-
}
1825-
// scan succeeded, record block as most recent successfully scanned
1826-
result.last_scanned_block = block_hash;
1827-
result.last_scanned_height = *block_height;
1828-
} else {
1829-
// could not scan block, keep scanning but record this block as the most recent failure
1809+
CBlock block;
1810+
if (chain().findBlock(block_hash, &block) && !block.IsNull()) {
1811+
auto locked_chain = chain().lock();
1812+
LOCK(cs_wallet);
1813+
if (!locked_chain->getBlockHeight(block_hash)) {
1814+
// Abort scan if current block is no longer active, to prevent
1815+
// marking transactions as coming from the wrong block.
1816+
// TODO: This should return success instead of failure, see
1817+
// https://github.com/bitcoin/bitcoin/pull/14711#issuecomment-458342518
18301818
result.last_failed_block = block_hash;
18311819
result.status = ScanResult::FAILURE;
1820+
break;
1821+
}
1822+
for (size_t posInBlock = 0; posInBlock < block.vtx.size(); ++posInBlock) {
1823+
SyncTransaction(block.vtx[posInBlock], block_hash, posInBlock, fUpdate);
18321824
}
1833-
if (block_hash == stop_block) {
1825+
// scan succeeded, record block as most recent successfully scanned
1826+
result.last_scanned_block = block_hash;
1827+
result.last_scanned_height = *block_height;
1828+
} else {
1829+
// could not scan block, keep scanning but record this block as the most recent failure
1830+
result.last_failed_block = block_hash;
1831+
result.status = ScanResult::FAILURE;
1832+
}
1833+
if (block_hash == stop_block) {
1834+
break;
1835+
}
1836+
{
1837+
auto locked_chain = chain().lock();
1838+
Optional<int> tip_height = locked_chain->getHeight();
1839+
if (!tip_height || *tip_height <= block_height || !locked_chain->getBlockHeight(block_hash)) {
1840+
// break successfully when rescan has reached the tip, or
1841+
// previous block is no longer on the chain due to a reorg
18341842
break;
18351843
}
1836-
{
1837-
auto locked_chain = chain().lock();
1838-
Optional<int> tip_height = locked_chain->getHeight();
1839-
if (!tip_height || *tip_height <= block_height || !locked_chain->getBlockHeight(block_hash)) {
1840-
// break successfully when rescan has reached the tip, or
1841-
// previous block is no longer on the chain due to a reorg
1842-
break;
1843-
}
18441844

1845-
// increment block and verification progress
1846-
block_hash = locked_chain->getBlockHash(++*block_height);
1847-
progress_current = chain().guessVerificationProgress(block_hash);
1845+
// increment block and verification progress
1846+
block_hash = locked_chain->getBlockHash(++*block_height);
1847+
progress_current = chain().guessVerificationProgress(block_hash);
18481848

1849-
// handle updated tip hash
1850-
const uint256 prev_tip_hash = tip_hash;
1851-
tip_hash = locked_chain->getBlockHash(*tip_height);
1852-
if (stop_block.IsNull() && prev_tip_hash != tip_hash) {
1853-
// in case the tip has changed, update progress max
1854-
progress_end = chain().guessVerificationProgress(tip_hash);
1855-
}
1849+
// handle updated tip hash
1850+
const uint256 prev_tip_hash = tip_hash;
1851+
tip_hash = locked_chain->getBlockHash(*tip_height);
1852+
if (stop_block.IsNull() && prev_tip_hash != tip_hash) {
1853+
// in case the tip has changed, update progress max
1854+
progress_end = chain().guessVerificationProgress(tip_hash);
18561855
}
18571856
}
1858-
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), 100); // hide progress dialog in GUI
1859-
if (block_height && fAbortRescan) {
1860-
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", *block_height, progress_current);
1861-
result.status = ScanResult::USER_ABORT;
1862-
} else if (block_height && chain().shutdownRequested()) {
1863-
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", *block_height, progress_current);
1864-
result.status = ScanResult::USER_ABORT;
1865-
}
1857+
}
1858+
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), 100); // hide progress dialog in GUI
1859+
if (block_height && fAbortRescan) {
1860+
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", *block_height, progress_current);
1861+
result.status = ScanResult::USER_ABORT;
1862+
} else if (block_height && chain().shutdownRequested()) {
1863+
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", *block_height, progress_current);
1864+
result.status = ScanResult::USER_ABORT;
1865+
} else {
1866+
WalletLogPrintf("Rescan completed in %15dms\n", GetTimeMillis() - start_time);
18661867
}
18671868
return result;
18681869
}
@@ -4245,15 +4246,13 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
42454246
}
42464247
}
42474248

4248-
nStart = GetTimeMillis();
42494249
{
42504250
WalletRescanReserver reserver(walletInstance.get());
42514251
if (!reserver.reserve() || (ScanResult::SUCCESS != walletInstance->ScanForWalletTransactions(locked_chain->getBlockHash(rescan_height), {} /* stop block */, reserver, true /* update */).status)) {
42524252
chain.initError(_("Failed to rescan the wallet during initialization"));
42534253
return nullptr;
42544254
}
42554255
}
4256-
walletInstance->WalletLogPrintf("Rescan completed in %15dms\n", GetTimeMillis() - nStart);
42574256
walletInstance->ChainStateFlushed(locked_chain->getTipLocator());
42584257
walletInstance->database->IncrementUpdateCounter();
42594258

0 commit comments

Comments
 (0)