Skip to content

Commit c5ffe8d

Browse files
committed
Merge #15730: rpc: Show scanning details in getwalletinfo
b6c748f doc: Add release notes for 15730 (João Barbosa) d3e8458 rpc: Show scanning details in getwalletinfo (João Barbosa) 90e27ab wallet: Track current scanning progress (João Barbosa) 2ee811e wallet: Track scanning duration (João Barbosa) Pull request description: Closes #15724. ACKs for commit b6c748: MarcoFalke: re-utACK b6c748f (Only change since my last review is rebase, adding release notes, and returning false instead of null) laanwj: utACK b6c748f jonatack: ACK b6c748f, only changes appear to be rebase for bitcoin/bitcoin#15730 (comment) and release notes. Tree-SHA512: 8ee98f971c15f66ce8138fc92c55e51abc9faf01866a31ac7ce2ad766aa2bb88559eabee3b5815d645c84cdf1c19dc35ec03f31461e39bc5f6040edec0b87116
2 parents a3d2d6b + b6c748f commit c5ffe8d

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

doc/release-notes-15730.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RPC changes
2+
-----------
3+
The RPC `getwalletinfo` response now includes the `scanning` key with an object
4+
if there is a scanning in progress or `false` otherwise. Currently the object
5+
has the scanning duration and progress.

src/wallet/rpcwallet.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,11 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
24622462
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
24632463
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
24642464
" \"private_keys_enabled\": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)\n"
2465+
" \"scanning\": (json object) current scanning details, or false if no scan is in progress\n"
2466+
" {\n"
2467+
" \"duration\" : xxxx (numeric) elapsed seconds since scan start\n"
2468+
" \"progress\" : x.xxxx, (numeric) scanning progress percentage [0.0, 1.0]\n"
2469+
" }\n"
24652470
"}\n"
24662471
},
24672472
RPCExamples{
@@ -2505,6 +2510,14 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
25052510
obj.pushKV("hdseedid", seed_id.GetHex());
25062511
}
25072512
obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
2513+
if (pwallet->IsScanning()) {
2514+
UniValue scanning(UniValue::VOBJ);
2515+
scanning.pushKV("duration", pwallet->ScanningDuration() / 1000);
2516+
scanning.pushKV("progress", pwallet->ScanningProgress());
2517+
obj.pushKV("scanning", scanning);
2518+
} else {
2519+
obj.pushKV("scanning", false);
2520+
}
25082521
return obj;
25092522
}
25102523

src/wallet/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,8 +1786,9 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
17861786
}
17871787
double progress_current = progress_begin;
17881788
while (block_height && !fAbortRescan && !chain().shutdownRequested()) {
1789+
m_scanning_progress = (progress_current - progress_begin) / (progress_end - progress_begin);
17891790
if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
1790-
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100))));
1791+
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
17911792
}
17921793
if (GetTime() >= nNow + 60) {
17931794
nNow = GetTime();

src/wallet/wallet.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
596596
private:
597597
std::atomic<bool> fAbortRescan{false};
598598
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
599+
std::atomic<int64_t> m_scanning_start{0};
600+
std::atomic<double> m_scanning_progress{0};
599601
std::mutex mutexScanning;
600602
friend class WalletRescanReserver;
601603

@@ -820,6 +822,8 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
820822
void AbortRescan() { fAbortRescan = true; }
821823
bool IsAbortingRescan() { return fAbortRescan; }
822824
bool IsScanning() { return fScanningWallet; }
825+
int64_t ScanningDuration() const { return fScanningWallet ? GetTimeMillis() - m_scanning_start : 0; }
826+
double ScanningProgress() const { return fScanningWallet ? (double) m_scanning_progress : 0; }
823827

824828
/**
825829
* keystore implementation
@@ -1241,6 +1245,8 @@ class WalletRescanReserver
12411245
if (m_wallet->fScanningWallet) {
12421246
return false;
12431247
}
1248+
m_wallet->m_scanning_start = GetTimeMillis();
1249+
m_wallet->m_scanning_progress = 0;
12441250
m_wallet->fScanningWallet = true;
12451251
m_could_reserve = true;
12461252
return true;

0 commit comments

Comments
 (0)