Skip to content

Commit 599ff5a

Browse files
committed
wallet: avoid double TopUp() calls on descriptor wallets
Move TopUp() responsibility from the wallet class to each scriptpubkeyman. So each spkm can decide to call it or not after perform the basic checks for the new destination request. Reason: We were calling it twice in the following flows for descriptor wallets: A) CWallet::GetNewDestination: 1) Calls spk_man->TopUp() 2) Calls spk_man->GetNewDestination() --> which, after the basic script checks, calls TopUp() again. B) CWallet::GetReservedDestination: 1) Calls spk_man->TopUp() 2) Calls spk_man->GetReservedDestination() --> which calls to GetNewDestination (which calls to TopUp again).
1 parent bf3f05f commit 599ff5a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ util::Result<CTxDestination> LegacyScriptPubKeyMan::GetNewDestination(const Outp
2828
}
2929
assert(type != OutputType::BECH32M);
3030

31+
// Fill-up keypool if needed
32+
TopUp();
33+
3134
LOCK(cs_KeyStore);
3235

3336
// Generate a new key that is added to wallet
@@ -304,6 +307,9 @@ util::Result<CTxDestination> LegacyScriptPubKeyMan::GetReservedDestination(const
304307
return util::Error{_("Error: Keypool ran out, please call keypoolrefill first")};
305308
}
306309

310+
// Fill-up keypool if needed
311+
TopUp();
312+
307313
if (!ReserveKeyFromKeyPool(index, keypool, internal)) {
308314
return util::Error{_("Error: Keypool ran out, please call keypoolrefill first")};
309315
}

src/wallet/wallet.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,6 @@ util::Result<CTxDestination> CWallet::GetNewDestination(const OutputType type, c
23462346
return util::Error{strprintf(_("Error: No %s addresses available."), FormatOutputType(type))};
23472347
}
23482348

2349-
spk_man->TopUp();
23502349
auto op_dest = spk_man->GetNewDestination(type);
23512350
if (op_dest) {
23522351
SetAddressBook(*op_dest, label, "receive");
@@ -2440,10 +2439,7 @@ util::Result<CTxDestination> ReserveDestination::GetReservedDestination(bool int
24402439
return util::Error{strprintf(_("Error: No %s addresses available."), FormatOutputType(type))};
24412440
}
24422441

2443-
if (nIndex == -1)
2444-
{
2445-
m_spk_man->TopUp();
2446-
2442+
if (nIndex == -1) {
24472443
CKeyPool keypool;
24482444
auto op_address = m_spk_man->GetReservedDestination(type, internal, nIndex, keypool);
24492445
if (!op_address) return op_address;

0 commit comments

Comments
 (0)