mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
feat(wallet): TopUpKeyPool improvements (#5456)
- make progress calculations sane - show progress in GUI but only when you need 100+ new keys - make it stop on shutdown request - spam less in debug.log run tests, run `keypoolrefill` with `1100` (add 100 keys, no gui popup) and `10000` (100+ keys, progress bar) on testnet wallet, check logs, verify it can be interrupted on shutdown n/a - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
This commit is contained in:
parent
8ef7002679
commit
2c2f81675e
@ -7,6 +7,7 @@
|
||||
#include <coinjoin/client.h>
|
||||
#include <logging.h>
|
||||
#include <script/descriptor.h>
|
||||
#include <shutdown.h>
|
||||
#include <util/bip32.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
@ -1374,14 +1375,27 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize)
|
||||
{
|
||||
// don't create extra internal keys
|
||||
missingInternal = 0;
|
||||
} else {
|
||||
nTargetSize *= 2;
|
||||
}
|
||||
|
||||
const int64_t total_missing = missingInternal + missingExternal;
|
||||
if (total_missing == 0) return true;
|
||||
|
||||
constexpr int64_t PROGRESS_REPORT_INTERVAL = 1; // in seconds
|
||||
const bool should_show_progress = total_missing > 100;
|
||||
const std::string strMsg = _("Topping up keypool...").translated;
|
||||
|
||||
int64_t progress_report_time = GetTime();
|
||||
WalletLogPrintf("%s\n", strMsg);
|
||||
if (should_show_progress) {
|
||||
uiInterface.ShowProgress(strMsg, 0, false);
|
||||
}
|
||||
|
||||
bool fInternal = false;
|
||||
int64_t current_index{0};
|
||||
WalletBatch batch(m_storage.GetDatabase());
|
||||
for (int64_t i = missingInternal + missingExternal; i--;)
|
||||
{
|
||||
if (i < missingInternal) {
|
||||
|
||||
for (current_index = 0; current_index < total_missing; ++current_index) {
|
||||
if (current_index == missingExternal) {
|
||||
fInternal = true;
|
||||
}
|
||||
|
||||
@ -1389,15 +1403,20 @@ bool LegacyScriptPubKeyMan::TopUp(unsigned int kpSize)
|
||||
CPubKey pubkey(GenerateNewKey(batch, 0, fInternal));
|
||||
AddKeypoolPubkeyWithDB(pubkey, fInternal, batch);
|
||||
|
||||
if (missingInternal + missingExternal > 0) {
|
||||
WalletLogPrintf("keypool added %d keys (%d internal), size=%u (%u internal)\n",
|
||||
missingInternal + missingExternal, missingInternal,
|
||||
setInternalKeyPool.size() + setExternalKeyPool.size(), setInternalKeyPool.size());
|
||||
if (GetTime() >= progress_report_time + PROGRESS_REPORT_INTERVAL) {
|
||||
const double dProgress = 100.f * current_index / total_missing;
|
||||
progress_report_time = GetTime();
|
||||
WalletLogPrintf("Still topping up. At key %lld. Progress=%f\n", current_index, dProgress);
|
||||
if (should_show_progress) {
|
||||
uiInterface.ShowProgress(strMsg, static_cast<int>(dProgress), false);
|
||||
}
|
||||
}
|
||||
|
||||
double dProgress = 100.f * m_max_keypool_index / (nTargetSize + 1);
|
||||
std::string strMsg = strprintf(_("Loading wallet... (%3.2f %%)").translated, dProgress);
|
||||
uiInterface.InitMessage(strMsg);
|
||||
if (ShutdownRequested()) break;
|
||||
}
|
||||
WalletLogPrintf("Keypool added %d keys, size=%u (%u internal)\n",
|
||||
current_index + 1, setInternalKeyPool.size() + setExternalKeyPool.size(), setInternalKeyPool.size());
|
||||
if (should_show_progress) {
|
||||
uiInterface.ShowProgress("", 100, false);
|
||||
}
|
||||
}
|
||||
NotifyCanGetAddressesChanged();
|
||||
|
Loading…
Reference in New Issue
Block a user