0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

wallet: Use steady clock to measure scanning duration

This commit is contained in:
MarcoFalke 2023-04-03 10:37:44 +02:00
parent fa97621804
commit fa2c099cec
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View file

@ -112,7 +112,7 @@ static RPCHelpMan getwalletinfo()
obj.pushKV("avoid_reuse", pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)); obj.pushKV("avoid_reuse", pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE));
if (pwallet->IsScanning()) { if (pwallet->IsScanning()) {
UniValue scanning(UniValue::VOBJ); UniValue scanning(UniValue::VOBJ);
scanning.pushKV("duration", pwallet->ScanningDuration() / 1000); scanning.pushKV("duration", Ticks<std::chrono::seconds>(pwallet->ScanningDuration()));
scanning.pushKV("progress", pwallet->ScanningProgress()); scanning.pushKV("progress", pwallet->ScanningProgress());
obj.pushKV("scanning", scanning); obj.pushKV("scanning", scanning);
} else { } else {

View file

@ -244,7 +244,7 @@ private:
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
std::atomic<bool> m_attaching_chain{false}; std::atomic<bool> m_attaching_chain{false};
std::atomic<bool> m_scanning_with_passphrase{false}; std::atomic<bool> m_scanning_with_passphrase{false};
std::atomic<int64_t> m_scanning_start{0}; std::atomic<SteadyClock::time_point> m_scanning_start{SteadyClock::time_point{}};
std::atomic<double> m_scanning_progress{0}; std::atomic<double> m_scanning_progress{0};
friend class WalletRescanReserver; friend class WalletRescanReserver;
@ -465,7 +465,7 @@ public:
bool IsAbortingRescan() const { return fAbortRescan; } bool IsAbortingRescan() const { return fAbortRescan; }
bool IsScanning() const { return fScanningWallet; } bool IsScanning() const { return fScanningWallet; }
bool IsScanningWithPassphrase() const { return m_scanning_with_passphrase; } bool IsScanningWithPassphrase() const { return m_scanning_with_passphrase; }
int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; } SteadyClock::duration ScanningDuration() const { return fScanningWallet ? SteadyClock::now() - m_scanning_start.load() : SteadyClock::duration{}; }
double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; } double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
//! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo //! Upgrade stored CKeyMetadata objects to store key origin info as KeyOriginInfo
@ -971,7 +971,7 @@ public:
return false; return false;
} }
m_wallet.m_scanning_with_passphrase.exchange(with_passphrase); m_wallet.m_scanning_with_passphrase.exchange(with_passphrase);
m_wallet.m_scanning_start = GetTimeMillis(); m_wallet.m_scanning_start = SteadyClock::now();
m_wallet.m_scanning_progress = 0; m_wallet.m_scanning_progress = 0;
m_could_reserve = true; m_could_reserve = true;
return true; return true;