diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -186,6 +186,13 @@ virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination &addr) {} + /** + * Fills internal address pool. Use within ScriptPubKeyMan implementations + * should be used sparingly and only when something from the address pool is + * removed, excluding GetNewDestination and GetReservedDestination. External + * wallet code is primarily responsible for topping up prior to fetching new + * addresses + */ virtual bool TopUp(unsigned int size = 0) { return false; } //! Mark unused addresses as being used diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -16,7 +16,6 @@ CTxDestination &dest, std::string &error) { error.clear(); - TopUp(); // Generate a new key that is added to wallet CPubKey new_key; @@ -1151,8 +1150,6 @@ { LOCK(cs_wallet); - TopUp(); - bool fReturningInternal = fRequestedInternal; fReturningInternal &= (IsHDEnabled() && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) || diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3472,6 +3472,7 @@ bool result = false; auto spk_man = m_spk_man.get(); if (spk_man) { + spk_man->TopUp(); result = spk_man->GetNewDestination(type, dest, error); } if (result) { @@ -3486,8 +3487,6 @@ std::string &error) { error.clear(); - m_spk_man->TopUp(); - ReserveDestination reservedest(this, type); if (!reservedest.GetReservedDestination(dest, true)) { error = "Error: Keypool ran out, please call keypoolrefill first"; @@ -3680,6 +3679,8 @@ } if (nIndex == -1) { + m_spk_man->TopUp(); + CKeyPool keypool; if (!m_spk_man->GetReservedDestination(type, internal, address, nIndex, keypool)) {