mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
Merge bitcoin/bitcoin#32977: wallet: Remove wallet version and several legacy related functions
60d1042b9awallet: Remove unused `WalletFeature` enums (woltx)66de58208awallet: Remove `CWallet::nWalletVersion` and related functions (woltx)7cda3d0f5bwallet: Remove `IsFeatureSupported()` and `CanSupportFeature()` (woltx)ba01585229wallet: `MigrateToDescriptor` no longer calls `CanSupportFeature` (woltx)63acee2797wallet: Remove `GetClosestWalletFeature()` (woltx)e27da3150bwallet: Remove `GetVersion()` (woltx) Pull request description: This PR incorporates the suggestion provided by PRabahy and pablomartin4btc in https://github.com/bitcoin/bitcoin/pull/32944 of removing `CWallet::nWalletVersion` and several related functions, such as `SetMinVersion()`, `GetVersion()`, `GetClosestWalletFeature()`, `IsFeatureSupported()`, `CanSupportFeature()`, etc ... This field is no longer used in the descriptor wallet and there is still a lot of code related to it, so the changes here provide a good cleanup in the wallet code. Built on top of https://github.com/bitcoin/bitcoin/pull/32944 ACKs for top commit: maflcko: review ACK60d1042b9a🐾 achow101: ACK60d1042b9apablomartin4btc: ACK60d1042b9aTree-SHA512: 1a7ad8e15d57df8f66545776e7d178a2cd5312c87769a29770588375e3de5f24247aab9919acf004ed3eca16d08ba595b5f1c7b2b3eef7752e89d9c295624583
This commit is contained in:
@@ -40,7 +40,7 @@ static RPCHelpMan getwalletinfo()
|
||||
{
|
||||
{
|
||||
{RPCResult::Type::STR, "walletname", "the wallet name"},
|
||||
{RPCResult::Type::NUM, "walletversion", "the wallet version"},
|
||||
{RPCResult::Type::NUM, "walletversion", "(DEPRECATED) only related to unsupported legacy wallet, returns the latest version 169900 for backwards compatibility"},
|
||||
{RPCResult::Type::STR, "format", "the database format (only sqlite)"},
|
||||
{RPCResult::Type::NUM, "txcount", "the total number of transactions in the wallet"},
|
||||
{RPCResult::Type::NUM, "keypoolsize", "how many new keys are pre-generated (only counts external keys)"},
|
||||
@@ -82,16 +82,16 @@ static RPCHelpMan getwalletinfo()
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
|
||||
const int latest_legacy_wallet_minversion{169900};
|
||||
|
||||
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
|
||||
obj.pushKV("walletname", pwallet->GetName());
|
||||
obj.pushKV("walletversion", pwallet->GetVersion());
|
||||
obj.pushKV("walletversion", latest_legacy_wallet_minversion);
|
||||
obj.pushKV("format", pwallet->GetDatabase().Format());
|
||||
obj.pushKV("txcount", (int)pwallet->mapWallet.size());
|
||||
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
|
||||
obj.pushKV("keypoolsize_hd_internal", pwallet->GetKeyPoolSize() - kpExternalSize);
|
||||
|
||||
if (pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) {
|
||||
obj.pushKV("keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize));
|
||||
}
|
||||
if (pwallet->IsCrypted()) {
|
||||
obj.pushKV("unlocked_until", pwallet->nRelockTime);
|
||||
}
|
||||
|
||||
@@ -624,10 +624,13 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
|
||||
for (const auto& chain_pair : m_inactive_hd_chains) {
|
||||
chains.push_back(chain_pair.second);
|
||||
}
|
||||
|
||||
bool can_support_hd_split_feature = m_hd_chain.nVersion >= CHDChain::VERSION_HD_CHAIN_SPLIT;
|
||||
|
||||
for (const CHDChain& chain : chains) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
// Skip if doing internal chain and split chain is not supported
|
||||
if (chain.seed_id.IsNull() || (i == 1 && !m_storage.CanSupportFeature(FEATURE_HD_SPLIT))) {
|
||||
if (chain.seed_id.IsNull() || (i == 1 && !can_support_hd_split_feature)) {
|
||||
continue;
|
||||
}
|
||||
// Get the master xprv
|
||||
|
||||
@@ -47,8 +47,6 @@ public:
|
||||
virtual WalletDatabase& GetDatabase() const = 0;
|
||||
virtual bool IsWalletFlagSet(uint64_t) const = 0;
|
||||
virtual void UnsetBlankWalletFlag(WalletBatch&) = 0;
|
||||
virtual bool CanSupportFeature(enum WalletFeature) const = 0;
|
||||
virtual void SetMinVersion(enum WalletFeature, WalletBatch* = nullptr) = 0;
|
||||
//! Pass the encryption key to cb().
|
||||
virtual bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const = 0;
|
||||
virtual bool HasEncryptionKeys() const = 0;
|
||||
|
||||
@@ -492,7 +492,6 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
|
||||
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateMockableWalletDatabase());
|
||||
LOCK(wallet->cs_wallet);
|
||||
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||
wallet->SetMinVersion(FEATURE_LATEST);
|
||||
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
||||
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, ""));
|
||||
}
|
||||
|
||||
@@ -639,23 +639,6 @@ void CWallet::SetLastBlockProcessed(int block_height, uint256 block_hash)
|
||||
WriteBestBlock();
|
||||
}
|
||||
|
||||
void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in)
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
if (nWalletVersion >= nVersion)
|
||||
return;
|
||||
WalletLogPrintf("Setting minversion to %d\n", nVersion);
|
||||
nWalletVersion = nVersion;
|
||||
|
||||
{
|
||||
WalletBatch* batch = batch_in ? batch_in : new WalletBatch(GetDatabase());
|
||||
if (nWalletVersion > 40000)
|
||||
batch->WriteMinVersion(nWalletVersion);
|
||||
if (!batch_in)
|
||||
delete batch;
|
||||
}
|
||||
}
|
||||
|
||||
std::set<Txid> CWallet::GetConflicts(const Txid& txid) const
|
||||
{
|
||||
std::set<Txid> result;
|
||||
@@ -821,9 +804,6 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
}
|
||||
}
|
||||
|
||||
// Encryption was introduced in version 0.4.0
|
||||
SetMinVersion(FEATURE_WALLETCRYPT, encrypted_batch);
|
||||
|
||||
if (!encrypted_batch->TxnCommit()) {
|
||||
delete encrypted_batch;
|
||||
encrypted_batch = nullptr;
|
||||
@@ -2871,9 +2851,6 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
||||
{
|
||||
LOCK(walletInstance->cs_wallet);
|
||||
|
||||
// ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key
|
||||
walletInstance->SetMinVersion(FEATURE_LATEST);
|
||||
|
||||
// Init with passed flags.
|
||||
// Always set the cache upgrade flag as this feature is supported from the beginning.
|
||||
walletInstance->InitWalletFlags(wallet_creation_flags | WALLET_FLAG_LAST_HARDENED_XPUB_CACHED);
|
||||
|
||||
@@ -321,9 +321,6 @@ private:
|
||||
std::atomic<double> m_scanning_progress{0};
|
||||
friend class WalletRescanReserver;
|
||||
|
||||
//! the current wallet version: clients below this version are not able to load the wallet
|
||||
int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
|
||||
|
||||
/** The next scheduled rebroadcast of wallet transactions. */
|
||||
NodeClock::time_point m_next_resend{GetDefaultNextResend()};
|
||||
/** Whether this wallet will submit newly created transactions to the node's mempool and
|
||||
@@ -556,9 +553,6 @@ public:
|
||||
int GetTxBlocksToMaturity(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
bool IsTxImmatureCoinBase(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
//! check whether we support the named feature
|
||||
bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return IsFeatureSupported(nWalletVersion, wf); }
|
||||
|
||||
bool IsSpent(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
// Whether this or any known scriptPubKey with the same single key has been spent.
|
||||
@@ -588,8 +582,6 @@ public:
|
||||
//! Upgrade DescriptorCaches
|
||||
void UpgradeDescriptorCache() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; return true; }
|
||||
|
||||
//! Marks destination as previously spent.
|
||||
void LoadAddressPreviouslySpent(const CTxDestination& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
//! Appends payment request to destination.
|
||||
@@ -825,12 +817,6 @@ public:
|
||||
|
||||
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
//! signify that a particular wallet feature is now used.
|
||||
void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr) override;
|
||||
|
||||
//! get the current wallet format (the oldest client version guaranteed to understand this wallet)
|
||||
int GetVersion() const { LOCK(cs_wallet); return nWalletVersion; }
|
||||
|
||||
//! Get wallet transactions that conflict with given transaction (spend same outputs)
|
||||
std::set<Txid> GetConflicts(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||
|
||||
|
||||
@@ -199,11 +199,6 @@ bool WalletBatch::WriteOrderPosNext(int64_t nOrderPosNext)
|
||||
return WriteIC(DBKeys::ORDERPOSNEXT, nOrderPosNext);
|
||||
}
|
||||
|
||||
bool WalletBatch::WriteMinVersion(int nVersion)
|
||||
{
|
||||
return WriteIC(DBKeys::MINVERSION, nVersion);
|
||||
}
|
||||
|
||||
bool WalletBatch::WriteActiveScriptPubKeyMan(uint8_t type, const uint256& id, bool internal)
|
||||
{
|
||||
std::string key = internal ? DBKeys::ACTIVEINTERNALSPK : DBKeys::ACTIVEEXTERNALSPK;
|
||||
@@ -442,19 +437,6 @@ bool LoadHDChain(CWallet* pwallet, DataStream& ssValue, std::string& strErr)
|
||||
return true;
|
||||
}
|
||||
|
||||
static DBErrors LoadMinVersion(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
|
||||
{
|
||||
AssertLockHeld(pwallet->cs_wallet);
|
||||
int nMinVersion = 0;
|
||||
if (batch.Read(DBKeys::MINVERSION, nMinVersion)) {
|
||||
pwallet->WalletLogPrintf("Wallet file version = %d\n", nMinVersion);
|
||||
if (nMinVersion > FEATURE_LATEST)
|
||||
return DBErrors::TOO_NEW;
|
||||
pwallet->LoadMinVersion(nMinVersion);
|
||||
}
|
||||
return DBErrors::LOAD_OK;
|
||||
}
|
||||
|
||||
static DBErrors LoadWalletFlags(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
|
||||
{
|
||||
AssertLockHeld(pwallet->cs_wallet);
|
||||
@@ -1137,8 +1119,6 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
|
||||
if (has_last_client) pwallet->WalletLogPrintf("Last client version = %d\n", last_client);
|
||||
|
||||
try {
|
||||
if ((result = LoadMinVersion(pwallet, *m_batch)) != DBErrors::LOAD_OK) return result;
|
||||
|
||||
// Load wallet flags, so they are known when processing other records.
|
||||
// The FLAGS key is absent during wallet creation.
|
||||
if ((result = LoadWalletFlags(pwallet, *m_batch)) != DBErrors::LOAD_OK) return result;
|
||||
|
||||
@@ -241,8 +241,6 @@ public:
|
||||
|
||||
bool WriteOrderPosNext(int64_t nOrderPosNext);
|
||||
|
||||
bool WriteMinVersion(int nVersion);
|
||||
|
||||
bool WriteDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const CPrivKey& privkey);
|
||||
bool WriteCryptedDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const std::vector<unsigned char>& secret);
|
||||
bool WriteDescriptor(const uint256& desc_id, const WalletDescriptor& descriptor);
|
||||
|
||||
@@ -31,7 +31,6 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag
|
||||
{
|
||||
LOCK(wallet_instance->cs_wallet);
|
||||
|
||||
wallet_instance->SetMinVersion(FEATURE_LATEST);
|
||||
wallet_instance->InitWalletFlags(wallet_creation_flags);
|
||||
|
||||
Assert(wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
|
||||
|
||||
@@ -32,20 +32,6 @@ fs::path GetWalletDir()
|
||||
return path;
|
||||
}
|
||||
|
||||
bool IsFeatureSupported(int wallet_version, int feature_version)
|
||||
{
|
||||
return wallet_version >= feature_version;
|
||||
}
|
||||
|
||||
WalletFeature GetClosestWalletFeature(int version)
|
||||
{
|
||||
static constexpr std::array wallet_features{FEATURE_LATEST, FEATURE_PRE_SPLIT_KEYPOOL, FEATURE_NO_DEFAULT_KEY, FEATURE_HD_SPLIT, FEATURE_HD, FEATURE_COMPRPUBKEY, FEATURE_WALLETCRYPT, FEATURE_BASE};
|
||||
for (const WalletFeature& wf : wallet_features) {
|
||||
if (version >= wf) return wf;
|
||||
}
|
||||
return static_cast<WalletFeature>(0);
|
||||
}
|
||||
|
||||
WalletDescriptor GenerateWalletDescriptor(const CExtPubKey& master_key, const OutputType& addr_type, bool internal)
|
||||
{
|
||||
int64_t creation_time = GetTime();
|
||||
|
||||
@@ -11,27 +11,6 @@
|
||||
#include <vector>
|
||||
|
||||
namespace wallet {
|
||||
/** (client) version numbers for particular wallet features */
|
||||
enum WalletFeature
|
||||
{
|
||||
FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getwalletinfo's clientversion output)
|
||||
|
||||
FEATURE_WALLETCRYPT = 40000, // wallet encryption
|
||||
FEATURE_COMPRPUBKEY = 60000, // compressed public keys
|
||||
|
||||
FEATURE_HD = 130000, // Hierarchical key derivation after BIP32 (HD Wallet)
|
||||
|
||||
FEATURE_HD_SPLIT = 139900, // Wallet with HD chain split (change outputs will use m/0'/1'/k)
|
||||
|
||||
FEATURE_NO_DEFAULT_KEY = 159900, // Wallet without a default key written
|
||||
|
||||
FEATURE_PRE_SPLIT_KEYPOOL = 169900, // Upgraded to HD SPLIT and can have a pre-split keypool
|
||||
|
||||
FEATURE_LATEST = FEATURE_PRE_SPLIT_KEYPOOL
|
||||
};
|
||||
|
||||
bool IsFeatureSupported(int wallet_version, int feature_version);
|
||||
WalletFeature GetClosestWalletFeature(int version);
|
||||
|
||||
enum WalletFlags : uint64_t {
|
||||
// wallet flags in the upper section (> 1 << 31) will lead to not opening the wallet if flag is unknown
|
||||
|
||||
@@ -167,15 +167,13 @@ class CreateWalletTest(BitcoinTestFramework):
|
||||
assert_raises_rpc_error(-4, 'descriptors argument must be set to "true"; it is no longer possible to create a legacy wallet.', self.nodes[0].createwallet, wallet_name="legacy", descriptors=False)
|
||||
|
||||
self.log.info("Check that the version number is being logged correctly")
|
||||
with node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Last client version = ", "Wallet file version = "]):
|
||||
with node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Last client version = "]):
|
||||
node.createwallet("version_check")
|
||||
wallet = node.get_wallet_rpc("version_check")
|
||||
wallet_version = wallet.getwalletinfo()["walletversion"]
|
||||
client_version = node.getnetworkinfo()["version"]
|
||||
wallet.unloadwallet()
|
||||
with node.assert_debug_log(
|
||||
expected_msgs=[f"Last client version = {client_version}", f"Wallet file version = {wallet_version}"],
|
||||
unexpected_msgs=["Wallet file version = 10500"]
|
||||
expected_msgs=[f"Last client version = {client_version}"]
|
||||
):
|
||||
node.loadwallet("version_check")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user