Skip to content

Commit cca900e

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25104: wallet: Change log interval to use steady_clock
bdc6881 wallet: Change log interval to use `steady_clock` (w0xlt) Pull request description: This refactors the log interval variables to use `steady_clock` as it is best suitable for measuring intervals. ACKs for top commit: laanwj: This makes sense. Code review ACK bdc6881 dunxen: Code review ACK bdc6881 Tree-SHA512: 738b4aa45cef01df77102320f83096a0a7d0c63d7fcf098a8c0ab16b29453a87dc789c110105590e1e215d03499db1d889a94f336dcb385b6883c8364c9d39b7
2 parents 27d7b11 + bdc6881 commit cca900e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/wallet/wallet.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,8 +1707,10 @@ int64_t CWallet::RescanFromTime(int64_t startTime, const WalletRescanReserver& r
17071707
*/
17081708
CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate)
17091709
{
1710-
int64_t nNow = GetTime();
1711-
int64_t start_time = GetTimeMillis();
1710+
using Clock = std::chrono::steady_clock;
1711+
constexpr auto LOG_INTERVAL{60s};
1712+
auto current_time{Clock::now()};
1713+
auto start_time{Clock::now()};
17121714

17131715
assert(reserver.isReserved());
17141716

@@ -1735,8 +1737,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
17351737
if (block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
17361738
ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
17371739
}
1738-
if (GetTime() >= nNow + 60) {
1739-
nNow = GetTime();
1740+
if (Clock::now() >= current_time + LOG_INTERVAL) {
1741+
current_time = Clock::now();
17401742
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", block_height, progress_current);
17411743
}
17421744

@@ -1803,7 +1805,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
18031805
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", block_height, progress_current);
18041806
result.status = ScanResult::USER_ABORT;
18051807
} else {
1806-
WalletLogPrintf("Rescan completed in %15dms\n", GetTimeMillis() - start_time);
1808+
auto duration_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start_time);
1809+
WalletLogPrintf("Rescan completed in %15dms\n", duration_milliseconds.count());
18071810
}
18081811
return result;
18091812
}

0 commit comments

Comments
 (0)