Skip to content

Commit ea50e34

Browse files
committed
keypool: Move opportunistic TopUps from LegacyScriptPubKeyMan to CWallet and ReserveDestination
An opportunistic TopUp is moved from LegacyScriptPubKeyMan::GetNewDestination to CWallet::GetNewDestination. Another opportunistic TopUp is moved from LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination) to ReserveDestination::GetReservedDestination. 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. As such, it is also unnecessary to keep the TopUp calls in the LegacyScriptPubKeyMan functions so they are moved. This does not change behavior as TopUp calls are moved up the call stack.
1 parent bb2c8ce commit ea50e34

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
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;
@@ -1147,8 +1146,6 @@ bool LegacyScriptPubKeyMan::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& key
11471146
{
11481147
LOCK(cs_wallet);
11491148

1150-
TopUp();
1151-
11521149
bool fReturningInternal = fRequestedInternal;
11531150
fReturningInternal &= (IsHDEnabled() && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) || m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
11541151
bool use_split_keypool = set_pre_split_keypool.empty();

src/wallet/wallet.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,7 @@ bool CWallet::GetNewDestination(const OutputType type, const std::string label,
31093109
bool result = false;
31103110
auto spk_man = m_spk_man.get();
31113111
if (spk_man) {
3112+
spk_man->TopUp();
31123113
result = spk_man->GetNewDestination(type, dest, error);
31133114
}
31143115
if (result) {
@@ -3302,6 +3303,8 @@ bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool inter
33023303

33033304
if (nIndex == -1)
33043305
{
3306+
m_spk_man->TopUp();
3307+
33053308
CKeyPool keypool;
33063309
if (!m_spk_man->GetReservedDestination(type, internal, nIndex, keypool)) {
33073310
return false;

0 commit comments

Comments
 (0)