Skip to content

Commit

Permalink
Merge bitcoin#15730: rpc: Show scanning details in getwalletinfo (#3785)
Browse files Browse the repository at this point in the history
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 bitcoin#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#15730 (comment) and release notes.

Tree-SHA512: 8ee98f971c15f66ce8138fc92c55e51abc9faf01866a31ac7ce2ad766aa2bb88559eabee3b5815d645c84cdf1c19dc35ec03f31461e39bc5f6040edec0b87116

Co-authored-by: Wladimir J. van der Laan <[email protected]>
  • Loading branch information
UdjinM6 and laanwj committed Nov 3, 2020
1 parent 3ad4651 commit b3bbc00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2768,6 +2768,11 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
" }\n"
" ,...\n"
" ]\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"
"\nExamples:\n"
+ HelpExampleCli("getwalletinfo", "")
Expand Down Expand Up @@ -2821,6 +2826,14 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
}
obj.push_back(Pair("hdaccounts", accounts));
}
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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,8 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock
LOCK(cs_main);
gvp = GuessVerificationProgress(chainParams.TxData(), pindex);
}
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((gvp - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
m_scanning_progress = (gvp - dProgressStart) / (dProgressTip - dProgressStart);
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)(m_scanning_progress * 100))));
}
if (GetTime() >= nNow + 60) {
nNow = GetTime();
Expand Down
6 changes: 6 additions & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
private:
std::atomic<bool> fAbortRescan;
std::atomic<bool> fScanningWallet; //controlled by WalletRescanReserver
std::atomic<int64_t> m_scanning_start{0};
std::atomic<double> m_scanning_progress{0};
std::mutex mutexScanning;
friend class WalletRescanReserver;

Expand Down Expand Up @@ -977,6 +979,8 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
void AbortRescan() { fAbortRescan = true; }
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
Expand Down Expand Up @@ -1348,6 +1352,8 @@ class WalletRescanReserver
if (m_wallet->fScanningWallet) {
return false;
}
m_wallet->m_scanning_start = GetTimeMillis();
m_wallet->m_scanning_progress = 0;
m_wallet->fScanningWallet = true;
m_could_reserve = true;
return true;
Expand Down

0 comments on commit b3bbc00

Please sign in to comment.