From 2ee811e6930cf76ea51e6826fe437ed888688adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Wed, 3 Apr 2019 16:57:24 +0100 Subject: [PATCH 1/4] wallet: Track scanning duration --- src/wallet/wallet.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 900af75f4f..fa9a13bebb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -596,6 +596,7 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific private: std::atomic fAbortRescan{false}; std::atomic fScanningWallet{false}; // controlled by WalletRescanReserver + std::atomic m_scanning_start{0}; std::mutex mutexScanning; friend class WalletRescanReserver; @@ -820,6 +821,7 @@ public: void AbortRescan() { fAbortRescan = true; } bool IsAbortingRescan() { return fAbortRescan; } bool IsScanning() { return fScanningWallet; } + int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; } /** * keystore implementation @@ -1241,6 +1243,7 @@ public: if (m_wallet->fScanningWallet) { return false; } + m_wallet->m_scanning_start = GetTimeMillis(); m_wallet->fScanningWallet = true; m_could_reserve = true; return true; From 90e27abe37cc84c7b206f20d28aafe32e71e7209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Wed, 3 Apr 2019 17:05:52 +0100 Subject: [PATCH 2/4] wallet: Track current scanning progress --- src/wallet/wallet.cpp | 3 ++- src/wallet/wallet.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4ab94f0c2c..1a34706133 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1798,8 +1798,9 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc } double progress_current = progress_begin; while (block_height && !fAbortRescan && !chain().shutdownRequested()) { + m_scanning_progress = (progress_current - progress_begin) / (progress_end - progress_begin); if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) { - ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100)))); + ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100)))); } if (GetTime() >= nNow + 60) { nNow = GetTime(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index fa9a13bebb..aa6ce058e6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -597,6 +597,7 @@ private: std::atomic fAbortRescan{false}; std::atomic fScanningWallet{false}; // controlled by WalletRescanReserver std::atomic m_scanning_start{0}; + std::atomic m_scanning_progress{0}; std::mutex mutexScanning; friend class WalletRescanReserver; @@ -822,6 +823,7 @@ public: bool IsAbortingRescan() { return fAbortRescan; } bool IsScanning() { return fScanningWallet; } int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; } + double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; } /** * keystore implementation @@ -1244,6 +1246,7 @@ public: return false; } m_wallet->m_scanning_start = GetTimeMillis(); + m_wallet->m_scanning_progress = 0; m_wallet->fScanningWallet = true; m_could_reserve = true; return true; From d3e8458365ab29017241bc43204fe81cb7fd8530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Wed, 3 Apr 2019 16:56:58 +0100 Subject: [PATCH 3/4] rpc: Show scanning details in getwalletinfo --- src/wallet/rpcwallet.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5a22508c4b..cc70a3c498 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2402,6 +2402,11 @@ static UniValue getwalletinfo(const JSONRPCRequest& request) " \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n" " \"hdseedid\": \"\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n" " \"private_keys_enabled\": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)\n" + " \"scanning\": (json object) current scanning details, or false if no scan is in progress\n" + " {\n" + " \"duration\" : xxxx (numeric) elapsed seconds since scan start\n" + " \"progress\" : x.xxxx, (numeric) scanning progress percentage [0.0, 1.0]\n" + " }\n" "}\n" }, RPCExamples{ @@ -2441,6 +2446,14 @@ static UniValue getwalletinfo(const JSONRPCRequest& request) obj.pushKV("hdseedid", seed_id.GetHex()); } obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); + if (pwallet->IsScanning()) { + UniValue scanning(UniValue::VOBJ); + scanning.pushKV("duration", pwallet->ScanningDuration() / 1000); + scanning.pushKV("progress", pwallet->ScanningProgress()); + obj.pushKV("scanning", scanning); + } else { + obj.pushKV("scanning", false); + } return obj; } From b6c748f84909212dce73e4b77aa125ed1e108a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Fri, 26 Apr 2019 15:16:38 +0100 Subject: [PATCH 4/4] doc: Add release notes for 15730 --- doc/release-notes-15730.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/release-notes-15730.md diff --git a/doc/release-notes-15730.md b/doc/release-notes-15730.md new file mode 100644 index 0000000000..7a4a60b1ee --- /dev/null +++ b/doc/release-notes-15730.md @@ -0,0 +1,5 @@ +RPC changes +----------- +The RPC `getwalletinfo` response now includes the `scanning` key with an object +if there is a scanning in progress or `false` otherwise. Currently the object +has the scanning duration and progress.