Skip to content

Commit b02fc0b

Browse files
committed
fix: counting calculation of internal keys for Descriptor Wallets
KeypoolCountInternalKeys is not working as expected if there is more than one ScriptPubKeyManager
1 parent e84e3d9 commit b02fc0b

File tree

5 files changed

+4
-24
lines changed

5 files changed

+4
-24
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,8 +2558,9 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
25582558
obj.pushKV("timefirstkey", spk_man->GetTimeFirstKey());
25592559
obj.pushKV("keypoololdest", spk_man->GetOldestKeyPoolTime());
25602560
}
2561-
obj.pushKV("keypoolsize", (int64_t)pwallet->KeypoolCountExternalKeys());
2562-
obj.pushKV("keypoolsize_hd_internal", (int64_t)(pwallet->KeypoolCountInternalKeys()));
2561+
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
2562+
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
2563+
obj.pushKV("keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize));
25632564
obj.pushKV("keys_left", pwallet->nKeysLeftSinceAutoBackup);
25642565
if (pwallet->IsCrypted())
25652566
obj.pushKV("unlocked_until", pwallet->nRelockTime);

src/wallet/scriptpubkeyman.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,12 +673,6 @@ size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys() const
673673
return setExternalKeyPool.size();
674674
}
675675

676-
size_t LegacyScriptPubKeyMan::KeypoolCountInternalKeys() const
677-
{
678-
LOCK(cs_KeyStore); // setInternalKeyPool
679-
return setInternalKeyPool.size();
680-
}
681-
682676
unsigned int LegacyScriptPubKeyMan::GetKeyPoolSize() const
683677
{
684678
LOCK(cs_KeyStore);

src/wallet/scriptpubkeyman.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ class ScriptPubKeyMan
192192
virtual int64_t GetOldestKeyPoolTime() const { return GetTime(); }
193193

194194
virtual size_t KeypoolCountExternalKeys() const { return 0; }
195-
virtual size_t KeypoolCountInternalKeys() const { return 0; }
196195
virtual unsigned int GetKeyPoolSize() const { return 0; }
197196

198197
virtual int64_t GetTimeFirstKey() const { return 0; }
@@ -344,7 +343,6 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
344343

345344
int64_t GetOldestKeyPoolTime() const override;
346345
size_t KeypoolCountExternalKeys() const override;
347-
size_t KeypoolCountInternalKeys() const override;
348346

349347
unsigned int GetKeyPoolSize() const override;
350348

src/wallet/wallet.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4006,18 +4006,6 @@ size_t CWallet::KeypoolCountExternalKeys() const
40064006
return count;
40074007
}
40084008

4009-
size_t CWallet::KeypoolCountInternalKeys() const
4010-
{
4011-
AssertLockHeld(cs_wallet);
4012-
4013-
unsigned int count = 0;
4014-
for (auto spk_man : GetActiveScriptPubKeyMans()) {
4015-
count += spk_man->KeypoolCountInternalKeys();
4016-
}
4017-
4018-
return count;
4019-
}
4020-
40214009
unsigned int CWallet::GetKeyPoolSize() const
40224010
{
40234011
AssertLockHeld(cs_wallet);
@@ -4864,7 +4852,7 @@ std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain& chain, interfaces::C
48644852

48654853
{
48664854
walletInstance->WalletLogPrintf("setExternalKeyPool.size() = %u\n", walletInstance->KeypoolCountExternalKeys());
4867-
walletInstance->WalletLogPrintf("setInternalKeyPool.size() = %u\n", walletInstance->KeypoolCountInternalKeys());
4855+
walletInstance->WalletLogPrintf("GetKeyPoolSize() = %u\n", walletInstance->GetKeyPoolSize());
48684856
walletInstance->WalletLogPrintf("mapWallet.size() = %u\n", walletInstance->mapWallet.size());
48694857
walletInstance->WalletLogPrintf("m_address_book.size() = %u\n", walletInstance->m_address_book.size());
48704858
for (auto spk_man : walletInstance->GetAllScriptPubKeyMans()) {

src/wallet/wallet.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
11271127
CAmount m_default_max_tx_fee{DEFAULT_TRANSACTION_MAXFEE};
11281128

11291129
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1130-
size_t KeypoolCountInternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
11311130
bool TopUpKeyPool(unsigned int kpSize = 0);
11321131

11331132
int64_t GetOldestKeyPoolTime() const;

0 commit comments

Comments
 (0)