From 66de58208a713e16f0d48bceed4d7496eae4b05b Mon Sep 17 00:00:00 2001 From: woltx <94266259+w0xlt@users.noreply.github.com> Date: Tue, 15 Jul 2025 01:07:01 -0700 Subject: [PATCH] wallet: Remove `CWallet::nWalletVersion` and related functions --- src/wallet/scriptpubkeyman.h | 1 - src/wallet/test/wallet_tests.cpp | 1 - src/wallet/wallet.cpp | 23 ----------------------- src/wallet/wallet.h | 8 -------- src/wallet/walletdb.cpp | 20 -------------------- src/wallet/walletdb.h | 2 -- src/wallet/wallettool.cpp | 1 - test/functional/wallet_createwallet.py | 6 ++---- 8 files changed, 2 insertions(+), 60 deletions(-) diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index f8086fdbff7..905c5c003ba 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -47,7 +47,6 @@ public: virtual WalletDatabase& GetDatabase() const = 0; virtual bool IsWalletFlagSet(uint64_t) const = 0; virtual void UnsetBlankWalletFlag(WalletBatch&) = 0; - virtual void SetMinVersion(enum WalletFeature, WalletBatch* = nullptr) = 0; //! Pass the encryption key to cb(). virtual bool WithEncryptionKey(std::function cb) const = 0; virtual bool HasEncryptionKeys() const = 0; diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 19feaca2060..b23b6e94603 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -492,7 +492,6 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) const std::shared_ptr wallet = std::make_shared(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, "")); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c7df818745f..9e3b9f678aa 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -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 CWallet::GetConflicts(const Txid& txid) const { std::set 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::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); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index c7c6c3c1070..b9ca377538b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -321,9 +321,6 @@ private: std::atomic 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 @@ -585,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. @@ -822,9 +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 wallet transactions that conflict with given transaction (spend same outputs) std::set GetConflicts(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 2c0073f3568..79c2af24b29 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -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; diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index 5327a2cf691..7a1dac3bce4 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -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& secret); bool WriteDescriptor(const uint256& desc_id, const WalletDescriptor& descriptor); diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp index 228f3efbfb7..af32986ce65 100644 --- a/src/wallet/wallettool.cpp +++ b/src/wallet/wallettool.cpp @@ -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)); diff --git a/test/functional/wallet_createwallet.py b/test/functional/wallet_createwallet.py index a2e7aae33ea..cf0d8b4e0b8 100755 --- a/test/functional/wallet_createwallet.py +++ b/test/functional/wallet_createwallet.py @@ -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")