Skip to content

Commit 57e8f34

Browse files
committed
Merge bitcoin/bitcoin#32977: wallet: Remove wallet version and several legacy related functions
60d1042 wallet: Remove unused `WalletFeature` enums (woltx) 66de582 wallet: Remove `CWallet::nWalletVersion` and related functions (woltx) 7cda3d0 wallet: Remove `IsFeatureSupported()` and `CanSupportFeature()` (woltx) ba01585 wallet: `MigrateToDescriptor` no longer calls `CanSupportFeature` (woltx) 63acee2 wallet: Remove `GetClosestWalletFeature()` (woltx) e27da31 wallet: Remove `GetVersion()` (woltx) Pull request description: This PR incorporates the suggestion provided by PRabahy and pablomartin4btc in bitcoin/bitcoin#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 bitcoin/bitcoin#32944 ACKs for top commit: maflcko: review ACK 60d1042 🐾 achow101: ACK 60d1042 pablomartin4btc: ACK 60d1042 Tree-SHA512: 1a7ad8e15d57df8f66545776e7d178a2cd5312c87769a29770588375e3de5f24247aab9919acf004ed3eca16d08ba595b5f1c7b2b3eef7752e89d9c295624583
2 parents 97593c1 + 60d1042 commit 57e8f34

File tree

12 files changed

+11
-108
lines changed

12 files changed

+11
-108
lines changed

src/wallet/rpc/wallet.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static RPCHelpMan getwalletinfo()
4040
{
4141
{
4242
{RPCResult::Type::STR, "walletname", "the wallet name"},
43-
{RPCResult::Type::NUM, "walletversion", "the wallet version"},
43+
{RPCResult::Type::NUM, "walletversion", "(DEPRECATED) only related to unsupported legacy wallet, returns the latest version 169900 for backwards compatibility"},
4444
{RPCResult::Type::STR, "format", "the database format (only sqlite)"},
4545
{RPCResult::Type::NUM, "txcount", "the total number of transactions in the wallet"},
4646
{RPCResult::Type::NUM, "keypoolsize", "how many new keys are pre-generated (only counts external keys)"},
@@ -82,16 +82,16 @@ static RPCHelpMan getwalletinfo()
8282

8383
UniValue obj(UniValue::VOBJ);
8484

85+
const int latest_legacy_wallet_minversion{169900};
86+
8587
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
8688
obj.pushKV("walletname", pwallet->GetName());
87-
obj.pushKV("walletversion", pwallet->GetVersion());
89+
obj.pushKV("walletversion", latest_legacy_wallet_minversion);
8890
obj.pushKV("format", pwallet->GetDatabase().Format());
8991
obj.pushKV("txcount", (int)pwallet->mapWallet.size());
9092
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
93+
obj.pushKV("keypoolsize_hd_internal", pwallet->GetKeyPoolSize() - kpExternalSize);
9194

92-
if (pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) {
93-
obj.pushKV("keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize));
94-
}
9595
if (pwallet->IsCrypted()) {
9696
obj.pushKV("unlocked_until", pwallet->nRelockTime);
9797
}

src/wallet/scriptpubkeyman.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,13 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
624624
for (const auto& chain_pair : m_inactive_hd_chains) {
625625
chains.push_back(chain_pair.second);
626626
}
627+
628+
bool can_support_hd_split_feature = m_hd_chain.nVersion >= CHDChain::VERSION_HD_CHAIN_SPLIT;
629+
627630
for (const CHDChain& chain : chains) {
628631
for (int i = 0; i < 2; ++i) {
629632
// Skip if doing internal chain and split chain is not supported
630-
if (chain.seed_id.IsNull() || (i == 1 && !m_storage.CanSupportFeature(FEATURE_HD_SPLIT))) {
633+
if (chain.seed_id.IsNull() || (i == 1 && !can_support_hd_split_feature)) {
631634
continue;
632635
}
633636
// Get the master xprv

src/wallet/scriptpubkeyman.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class WalletStorage
4747
virtual WalletDatabase& GetDatabase() const = 0;
4848
virtual bool IsWalletFlagSet(uint64_t) const = 0;
4949
virtual void UnsetBlankWalletFlag(WalletBatch&) = 0;
50-
virtual bool CanSupportFeature(enum WalletFeature) const = 0;
51-
virtual void SetMinVersion(enum WalletFeature, WalletBatch* = nullptr) = 0;
5250
//! Pass the encryption key to cb().
5351
virtual bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const = 0;
5452
virtual bool HasEncryptionKeys() const = 0;

src/wallet/test/wallet_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
492492
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateMockableWalletDatabase());
493493
LOCK(wallet->cs_wallet);
494494
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
495-
wallet->SetMinVersion(FEATURE_LATEST);
496495
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
497496
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, ""));
498497
}

src/wallet/wallet.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -639,23 +639,6 @@ void CWallet::SetLastBlockProcessed(int block_height, uint256 block_hash)
639639
WriteBestBlock();
640640
}
641641

642-
void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in)
643-
{
644-
LOCK(cs_wallet);
645-
if (nWalletVersion >= nVersion)
646-
return;
647-
WalletLogPrintf("Setting minversion to %d\n", nVersion);
648-
nWalletVersion = nVersion;
649-
650-
{
651-
WalletBatch* batch = batch_in ? batch_in : new WalletBatch(GetDatabase());
652-
if (nWalletVersion > 40000)
653-
batch->WriteMinVersion(nWalletVersion);
654-
if (!batch_in)
655-
delete batch;
656-
}
657-
}
658-
659642
std::set<Txid> CWallet::GetConflicts(const Txid& txid) const
660643
{
661644
std::set<Txid> result;
@@ -821,9 +804,6 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
821804
}
822805
}
823806

824-
// Encryption was introduced in version 0.4.0
825-
SetMinVersion(FEATURE_WALLETCRYPT, encrypted_batch);
826-
827807
if (!encrypted_batch->TxnCommit()) {
828808
delete encrypted_batch;
829809
encrypted_batch = nullptr;
@@ -2871,9 +2851,6 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
28712851
{
28722852
LOCK(walletInstance->cs_wallet);
28732853

2874-
// ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key
2875-
walletInstance->SetMinVersion(FEATURE_LATEST);
2876-
28772854
// Init with passed flags.
28782855
// Always set the cache upgrade flag as this feature is supported from the beginning.
28792856
walletInstance->InitWalletFlags(wallet_creation_flags | WALLET_FLAG_LAST_HARDENED_XPUB_CACHED);

src/wallet/wallet.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
321321
std::atomic<double> m_scanning_progress{0};
322322
friend class WalletRescanReserver;
323323

324-
//! the current wallet version: clients below this version are not able to load the wallet
325-
int nWalletVersion GUARDED_BY(cs_wallet){FEATURE_BASE};
326-
327324
/** The next scheduled rebroadcast of wallet transactions. */
328325
NodeClock::time_point m_next_resend{GetDefaultNextResend()};
329326
/** Whether this wallet will submit newly created transactions to the node's mempool and
@@ -556,9 +553,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
556553
int GetTxBlocksToMaturity(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
557554
bool IsTxImmatureCoinBase(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
558555

559-
//! check whether we support the named feature
560-
bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return IsFeatureSupported(nWalletVersion, wf); }
561-
562556
bool IsSpent(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
563557

564558
// Whether this or any known scriptPubKey with the same single key has been spent.
@@ -588,8 +582,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
588582
//! Upgrade DescriptorCaches
589583
void UpgradeDescriptorCache() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
590584

591-
bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; return true; }
592-
593585
//! Marks destination as previously spent.
594586
void LoadAddressPreviouslySpent(const CTxDestination& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
595587
//! Appends payment request to destination.
@@ -825,12 +817,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
825817

826818
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
827819

828-
//! signify that a particular wallet feature is now used.
829-
void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr) override;
830-
831-
//! get the current wallet format (the oldest client version guaranteed to understand this wallet)
832-
int GetVersion() const { LOCK(cs_wallet); return nWalletVersion; }
833-
834820
//! Get wallet transactions that conflict with given transaction (spend same outputs)
835821
std::set<Txid> GetConflicts(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
836822

src/wallet/walletdb.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ bool WalletBatch::WriteOrderPosNext(int64_t nOrderPosNext)
199199
return WriteIC(DBKeys::ORDERPOSNEXT, nOrderPosNext);
200200
}
201201

202-
bool WalletBatch::WriteMinVersion(int nVersion)
203-
{
204-
return WriteIC(DBKeys::MINVERSION, nVersion);
205-
}
206-
207202
bool WalletBatch::WriteActiveScriptPubKeyMan(uint8_t type, const uint256& id, bool internal)
208203
{
209204
std::string key = internal ? DBKeys::ACTIVEINTERNALSPK : DBKeys::ACTIVEEXTERNALSPK;
@@ -442,19 +437,6 @@ bool LoadHDChain(CWallet* pwallet, DataStream& ssValue, std::string& strErr)
442437
return true;
443438
}
444439

445-
static DBErrors LoadMinVersion(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
446-
{
447-
AssertLockHeld(pwallet->cs_wallet);
448-
int nMinVersion = 0;
449-
if (batch.Read(DBKeys::MINVERSION, nMinVersion)) {
450-
pwallet->WalletLogPrintf("Wallet file version = %d\n", nMinVersion);
451-
if (nMinVersion > FEATURE_LATEST)
452-
return DBErrors::TOO_NEW;
453-
pwallet->LoadMinVersion(nMinVersion);
454-
}
455-
return DBErrors::LOAD_OK;
456-
}
457-
458440
static DBErrors LoadWalletFlags(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
459441
{
460442
AssertLockHeld(pwallet->cs_wallet);
@@ -1137,8 +1119,6 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
11371119
if (has_last_client) pwallet->WalletLogPrintf("Last client version = %d\n", last_client);
11381120

11391121
try {
1140-
if ((result = LoadMinVersion(pwallet, *m_batch)) != DBErrors::LOAD_OK) return result;
1141-
11421122
// Load wallet flags, so they are known when processing other records.
11431123
// The FLAGS key is absent during wallet creation.
11441124
if ((result = LoadWalletFlags(pwallet, *m_batch)) != DBErrors::LOAD_OK) return result;

src/wallet/walletdb.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ class WalletBatch
241241

242242
bool WriteOrderPosNext(int64_t nOrderPosNext);
243243

244-
bool WriteMinVersion(int nVersion);
245-
246244
bool WriteDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const CPrivKey& privkey);
247245
bool WriteCryptedDescriptorKey(const uint256& desc_id, const CPubKey& pubkey, const std::vector<unsigned char>& secret);
248246
bool WriteDescriptor(const uint256& desc_id, const WalletDescriptor& descriptor);

src/wallet/wallettool.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag
3131
{
3232
LOCK(wallet_instance->cs_wallet);
3333

34-
wallet_instance->SetMinVersion(FEATURE_LATEST);
3534
wallet_instance->InitWalletFlags(wallet_creation_flags);
3635

3736
Assert(wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));

src/wallet/walletutil.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@ fs::path GetWalletDir()
3232
return path;
3333
}
3434

35-
bool IsFeatureSupported(int wallet_version, int feature_version)
36-
{
37-
return wallet_version >= feature_version;
38-
}
39-
40-
WalletFeature GetClosestWalletFeature(int version)
41-
{
42-
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};
43-
for (const WalletFeature& wf : wallet_features) {
44-
if (version >= wf) return wf;
45-
}
46-
return static_cast<WalletFeature>(0);
47-
}
48-
4935
WalletDescriptor GenerateWalletDescriptor(const CExtPubKey& master_key, const OutputType& addr_type, bool internal)
5036
{
5137
int64_t creation_time = GetTime();

0 commit comments

Comments
 (0)