Skip to content

Commit e6acd9f

Browse files
committed
Merge #17537: wallet: Cleanup and move opportunistic and superfluous TopUp()s
6e77a7b keypool: Add comment about TopUp and when to use it (Andrew Chow) ea50e34 keypool: Move opportunistic TopUps from LegacyScriptPubKeyMan to CWallet and ReserveDestination (Andrew Chow) bb2c8ce keypool: Remove superfluous topup from CWallet::GetNewChangeDestination (Andrew Chow) Pull request description: * The `TopUp()` in `CWallet::GetNewChangeDestination` is unnecessary as currently m_spk_man calls TopUp further down the call stack inside LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination). This also lets us prepare for future changes with multiple ScriptPubKeyMans in the wallet. * An opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::GetNewDestination` to `CWallet::GetNewDestination`. * Another opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::ReserveKeyFromKeyPool` Moving opportunistic TopUps ensures that ScriptPubKeyMans will always be topped up before requesting Destinations from them as we cannot always rely on future ScriptPubKeyMan implementaions topping up internally. See also: bitcoin/bitcoin#17373 (comment) ACKs for top commit: instagibbs: utACK bitcoin/bitcoin@6e77a7b only change is slight elaboration on comment ryanofsky: Code review ACK 6e77a7b. Only the comment changed since my previous review. Tree-SHA512: bdfc8d303842c3fb7c3d40af7abfa6d9dac4ef71a24922bb92229674ee89bfe3113ebb46d3903ac48ef99f0a7d6eaac33282495844f2b31f91b8df55084c421f
2 parents 890eac8 + 6e77a7b commit e6acd9f

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
bool LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
1515
{
1616
error.clear();
17-
TopUp();
1817

1918
// Generate a new key that is added to wallet
2019
CPubKey new_key;
@@ -1153,8 +1152,6 @@ bool LegacyScriptPubKeyMan::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& key
11531152
{
11541153
LOCK(cs_wallet);
11551154

1156-
TopUp();
1157-
11581155
bool fReturningInternal = fRequestedInternal;
11591156
fReturningInternal &= (IsHDEnabled() && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) || m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
11601157
bool use_split_keypool = set_pre_split_keypool.empty();

src/wallet/scriptpubkeyman.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ class ScriptPubKeyMan
160160
virtual void KeepDestination(int64_t index, const OutputType& type) {}
161161
virtual void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) {}
162162

163+
/** Fills internal address pool. Use within ScriptPubKeyMan implementations should be used sparingly and only
164+
* when something from the address pool is removed, excluding GetNewDestination and GetReservedDestination.
165+
* External wallet code is primarily responsible for topping up prior to fetching new addresses
166+
*/
163167
virtual bool TopUp(unsigned int size = 0) { return false; }
164168

165169
//! Mark unused addresses as being used

src/wallet/wallet.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,6 +3105,7 @@ bool CWallet::GetNewDestination(const OutputType type, const std::string label,
31053105
bool result = false;
31063106
auto spk_man = m_spk_man.get();
31073107
if (spk_man) {
3108+
spk_man->TopUp();
31083109
result = spk_man->GetNewDestination(type, dest, error);
31093110
}
31103111
if (result) {
@@ -3118,8 +3119,6 @@ bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& des
31183119
{
31193120
error.clear();
31203121

3121-
m_spk_man->TopUp();
3122-
31233122
ReserveDestination reservedest(this, type);
31243123
if (!reservedest.GetReservedDestination(dest, true)) {
31253124
error = "Error: Keypool ran out, please call keypoolrefill first";
@@ -3297,6 +3296,8 @@ bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool inter
32973296

32983297
if (nIndex == -1)
32993298
{
3299+
m_spk_man->TopUp();
3300+
33003301
CKeyPool keypool;
33013302
if (!m_spk_man->GetReservedDestination(type, internal, address, nIndex, keypool)) {
33023303
return false;

0 commit comments

Comments
 (0)