Skip to content

Commit a5e73ff

Browse files
MacroFakePastaPastaPasta
authored andcommitted
Merge 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
1 parent a245e52 commit a5e73ff

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
@@ -1939,8 +1939,10 @@ int64_t CWallet::RescanFromTime(int64_t startTime, const WalletRescanReserver& r
19391939
*/
19401940
CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_block, int start_height, std::optional<int> max_height, const WalletRescanReserver& reserver, bool fUpdate)
19411941
{
1942-
int64_t nNow = GetTime();
1943-
int64_t start_time = GetTimeMillis();
1942+
using Clock = std::chrono::steady_clock;
1943+
constexpr auto LOG_INTERVAL{60s};
1944+
auto current_time{Clock::now()};
1945+
auto start_time{Clock::now()};
19441946

19451947
assert(reserver.isReserved());
19461948

@@ -1967,8 +1969,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
19671969
if (block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
19681970
ShowProgress(strprintf("%s " + _("Rescanning...").translated, GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
19691971
}
1970-
if (GetTime() >= nNow + 60) {
1971-
nNow = GetTime();
1972+
if (Clock::now() >= current_time + LOG_INTERVAL) {
1973+
current_time = Clock::now();
19721974
WalletLogPrintf("Still rescanning. At block %d. Progress=%f\n", block_height, progress_current);
19731975
}
19741976

@@ -2035,7 +2037,8 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
20352037
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", block_height, progress_current);
20362038
result.status = ScanResult::USER_ABORT;
20372039
} else {
2038-
WalletLogPrintf("Rescan completed in %15dms\n", GetTimeMillis() - start_time);
2040+
auto duration_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start_time);
2041+
WalletLogPrintf("Rescan completed in %15dms\n", duration_milliseconds.count());
20392042
}
20402043
return result;
20412044
}

0 commit comments

Comments
 (0)