mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-23 23:27:21 +01:00
Merge bitcoin/bitcoin#23348: rpc, wallet: Do not return "keypoololdest" for blank descriptor wallets
ee03c782ba
wallet: Make GetOldestKeyPoolTime return nullopt for blank wallets (Hennadii Stepanov)3e4f069d23
wallet, refactor: Make GetOldestKeyPoolTime return type std::optional (Hennadii Stepanov) Pull request description: The "keypoololdest" field in the `getwalletinfo` RPC response should be used for legacy wallets only. Th current implementation (04437ee721
) assumes that `CWallet::GetOldestKeyPoolTime()` always return `0` for descriptor wallets. This assumption is wrong for _blank_ descriptor wallets, when `m_spk_managers` is empty. As a result: ``` $ src/bitcoin-cli -signet -rpcwallet=211024-d-DPK getwalletinfo { "walletname": "211024-d-DPK", "walletversion": 169900, "format": "sqlite", "balance": 0.00000000, "unconfirmed_balance": 0.00000000, "immature_balance": 0.00000000, "txcount": 0, "keypoololdest": 9223372036854775807, "keypoolsize": 0, "keypoolsize_hd_internal": 0, "paytxfee": 0.00000000, "private_keys_enabled": false, "avoid_reuse": false, "scanning": false, "descriptors": true } ``` This PR fixes this issue with direct checking of the `WALLET_FLAG_DESCRIPTORS` flag. ACKs for top commit: lsilva01: re-ACKee03c78
stratospher: ACKee03c78
. meshcollider: Code review ACKee03c782ba
Tree-SHA512: 9852f9f8ed5c08c07507274d7714f039bbfda66da6df65cf98f67bf11a600167d0f7f872680c95775399477f4df9ba9fce80ec0cbe0adb7f2bb33c3bd65b15df
This commit is contained in:
commit
a42923ce21
5 changed files with 20 additions and 16 deletions
|
@ -2522,7 +2522,6 @@ static RPCHelpMan getwalletinfo()
|
||||||
|
|
||||||
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
|
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
|
||||||
const auto bal = GetBalance(*pwallet);
|
const auto bal = GetBalance(*pwallet);
|
||||||
int64_t kp_oldest = pwallet->GetOldestKeyPoolTime();
|
|
||||||
obj.pushKV("walletname", pwallet->GetName());
|
obj.pushKV("walletname", pwallet->GetName());
|
||||||
obj.pushKV("walletversion", pwallet->GetVersion());
|
obj.pushKV("walletversion", pwallet->GetVersion());
|
||||||
obj.pushKV("format", pwallet->GetDatabase().Format());
|
obj.pushKV("format", pwallet->GetDatabase().Format());
|
||||||
|
@ -2530,8 +2529,9 @@ static RPCHelpMan getwalletinfo()
|
||||||
obj.pushKV("unconfirmed_balance", ValueFromAmount(bal.m_mine_untrusted_pending));
|
obj.pushKV("unconfirmed_balance", ValueFromAmount(bal.m_mine_untrusted_pending));
|
||||||
obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature));
|
obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature));
|
||||||
obj.pushKV("txcount", (int)pwallet->mapWallet.size());
|
obj.pushKV("txcount", (int)pwallet->mapWallet.size());
|
||||||
if (kp_oldest > 0) {
|
const auto kp_oldest = pwallet->GetOldestKeyPoolTime();
|
||||||
obj.pushKV("keypoololdest", kp_oldest);
|
if (kp_oldest.has_value()) {
|
||||||
|
obj.pushKV("keypoololdest", kp_oldest.value());
|
||||||
}
|
}
|
||||||
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
|
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
|
||||||
|
|
||||||
|
|
|
@ -528,7 +528,7 @@ static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, Walle
|
||||||
return keypool.nTime;
|
return keypool.nTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t LegacyScriptPubKeyMan::GetOldestKeyPoolTime() const
|
std::optional<int64_t> LegacyScriptPubKeyMan::GetOldestKeyPoolTime() const
|
||||||
{
|
{
|
||||||
LOCK(cs_KeyStore);
|
LOCK(cs_KeyStore);
|
||||||
|
|
||||||
|
@ -1970,11 +1970,10 @@ bool DescriptorScriptPubKeyMan::HavePrivateKeys() const
|
||||||
return m_map_keys.size() > 0 || m_map_crypted_keys.size() > 0;
|
return m_map_keys.size() > 0 || m_map_crypted_keys.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const
|
std::optional<int64_t> DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() const
|
||||||
{
|
{
|
||||||
// This is only used for getwalletinfo output and isn't relevant to descriptor wallets.
|
// This is only used for getwalletinfo output and isn't relevant to descriptor wallets.
|
||||||
// The magic number 0 indicates that it shouldn't be displayed so that's what we return.
|
return std::nullopt;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <boost/signals2/signal.hpp>
|
#include <boost/signals2/signal.hpp>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
enum class OutputType;
|
enum class OutputType;
|
||||||
|
@ -203,7 +204,7 @@ public:
|
||||||
//! The action to do when the DB needs rewrite
|
//! The action to do when the DB needs rewrite
|
||||||
virtual void RewriteDB() {}
|
virtual void RewriteDB() {}
|
||||||
|
|
||||||
virtual int64_t GetOldestKeyPoolTime() const { return GetTime(); }
|
virtual std::optional<int64_t> GetOldestKeyPoolTime() const { return GetTime(); }
|
||||||
|
|
||||||
virtual unsigned int GetKeyPoolSize() const { return 0; }
|
virtual unsigned int GetKeyPoolSize() const { return 0; }
|
||||||
|
|
||||||
|
@ -371,7 +372,7 @@ public:
|
||||||
|
|
||||||
void RewriteDB() override;
|
void RewriteDB() override;
|
||||||
|
|
||||||
int64_t GetOldestKeyPoolTime() const override;
|
std::optional<int64_t> GetOldestKeyPoolTime() const override;
|
||||||
size_t KeypoolCountExternalKeys() const;
|
size_t KeypoolCountExternalKeys() const;
|
||||||
unsigned int GetKeyPoolSize() const override;
|
unsigned int GetKeyPoolSize() const override;
|
||||||
|
|
||||||
|
@ -577,7 +578,7 @@ public:
|
||||||
|
|
||||||
bool HavePrivateKeys() const override;
|
bool HavePrivateKeys() const override;
|
||||||
|
|
||||||
int64_t GetOldestKeyPoolTime() const override;
|
std::optional<int64_t> GetOldestKeyPoolTime() const override;
|
||||||
unsigned int GetKeyPoolSize() const override;
|
unsigned int GetKeyPoolSize() const override;
|
||||||
|
|
||||||
int64_t GetTimeFirstKey() const override;
|
int64_t GetTimeFirstKey() const override;
|
||||||
|
|
|
@ -2169,14 +2169,18 @@ bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& des
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t CWallet::GetOldestKeyPoolTime() const
|
std::optional<int64_t> CWallet::GetOldestKeyPoolTime() const
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
int64_t oldestKey = std::numeric_limits<int64_t>::max();
|
if (m_spk_managers.empty()) {
|
||||||
for (const auto& spk_man_pair : m_spk_managers) {
|
return std::nullopt;
|
||||||
oldestKey = std::min(oldestKey, spk_man_pair.second->GetOldestKeyPoolTime());
|
|
||||||
}
|
}
|
||||||
return oldestKey;
|
|
||||||
|
std::optional<int64_t> oldest_key{std::numeric_limits<int64_t>::max()};
|
||||||
|
for (const auto& spk_man_pair : m_spk_managers) {
|
||||||
|
oldest_key = std::min(oldest_key, spk_man_pair.second->GetOldestKeyPoolTime());
|
||||||
|
}
|
||||||
|
return oldest_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWallet::MarkDestinationsDirty(const std::set<CTxDestination>& destinations) {
|
void CWallet::MarkDestinationsDirty(const std::set<CTxDestination>& destinations) {
|
||||||
|
|
|
@ -632,7 +632,7 @@ public:
|
||||||
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
bool TopUpKeyPool(unsigned int kpSize = 0);
|
bool TopUpKeyPool(unsigned int kpSize = 0);
|
||||||
|
|
||||||
int64_t GetOldestKeyPoolTime() const;
|
std::optional<int64_t> GetOldestKeyPoolTime() const;
|
||||||
|
|
||||||
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue