From 5431f2dc2159f55e0fbe89d07deb97fe2a73fb43 Mon Sep 17 00:00:00 2001 From: pablomartin4btc Date: Tue, 13 May 2025 11:35:02 -0300 Subject: [PATCH 1/3] wallet, refactor: Remove Legacy warnings and errors Remove dead code due to legacy wallet removal. --- src/wallet/wallet.cpp | 59 ++++++++----------------------------------- 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6542abc23df..af1a20dacb5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -288,11 +288,6 @@ std::shared_ptr LoadWalletInternal(WalletContext& context, const std::s return nullptr; } - // Legacy wallets are being deprecated, warn if the loaded wallet is legacy - if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { - warnings.emplace_back(_("Wallet loaded successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future. Legacy wallets can be migrated to a descriptor wallet with migratewallet.")); - } - NotifyWalletLoaded(context, wallet); AddWallet(context, wallet); wallet->postInitProcess(); @@ -382,12 +377,9 @@ std::shared_ptr CreateWallet(WalletContext& context, const std::string& uint64_t wallet_creation_flags = options.create_flags; const SecureString& passphrase = options.create_passphrase; - if (wallet_creation_flags & WALLET_FLAG_DESCRIPTORS) options.require_format = DatabaseFormat::SQLITE; - else { - error = Untranslated("Legacy wallets can no longer be created"); - status = DatabaseStatus::FAILED_CREATE; - return nullptr; - } + // Only descriptor wallets can be created + Assert(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS); + options.require_format = DatabaseFormat::SQLITE; // Indicate that the wallet is actually supposed to be blank and not just blank to make it encrypted bool create_blank = (wallet_creation_flags & WALLET_FLAG_BLANK_WALLET); @@ -404,13 +396,6 @@ std::shared_ptr CreateWallet(WalletContext& context, const std::string& return nullptr; } - // Descriptor support must be enabled for an external signer wallet - if ((wallet_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) && !(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS)) { - error = Untranslated("Descriptor support must be enabled when using an external signer"); - status = DatabaseStatus::FAILED_CREATE; - return nullptr; - } - // Do not allow a passphrase when private keys are disabled if (!passphrase.empty() && (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { error = Untranslated("Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled."); @@ -453,17 +438,7 @@ std::shared_ptr CreateWallet(WalletContext& context, const std::string& // Set a seed for the wallet { LOCK(wallet->cs_wallet); - if (wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { - wallet->SetupDescriptorScriptPubKeyMans(); - } else { - for (auto spk_man : wallet->GetActiveScriptPubKeyMans()) { - if (!spk_man->SetupGeneration()) { - error = Untranslated("Unable to generate initial keys"); - status = DatabaseStatus::FAILED_CREATE; - return nullptr; - } - } - } + wallet->SetupDescriptorScriptPubKeyMans(); } // Relock the wallet @@ -478,11 +453,6 @@ std::shared_ptr CreateWallet(WalletContext& context, const std::string& // Write the wallet settings UpdateWalletSetting(*context.chain, name, load_on_start, warnings); - // Legacy wallets are being deprecated, warn if a newly created wallet is legacy - if (!(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS)) { - warnings.emplace_back(_("Wallet created successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future.")); - } - status = DatabaseStatus::SUCCESS; return wallet; } @@ -813,6 +783,9 @@ void CWallet::AddToSpends(const CWalletTx& wtx, WalletBatch* batch) bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) { + // Only descriptor wallets can be encrypted + Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)); + if (IsCrypted()) return false; @@ -871,8 +844,8 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) Lock(); Unlock(strWalletPassphrase); - // If we are using descriptors, make new descriptors with a new seed - if (IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS) && !IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET)) { + // Make new descriptors with a new seed + if (!IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET)) { SetupDescriptorScriptPubKeyMans(); } Lock(); @@ -2896,18 +2869,8 @@ std::shared_ptr CWallet::Create(WalletContext& context, const std::stri assert(walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)); if ((wallet_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) || !(wallet_creation_flags & (WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET))) { - if (walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { - walletInstance->SetupDescriptorScriptPubKeyMans(); - // SetupDescriptorScriptPubKeyMans already calls SetupGeneration for us so we don't need to call SetupGeneration separately - } else { - // Legacy wallets need SetupGeneration here. - for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) { - if (!spk_man->SetupGeneration()) { - error = _("Unable to generate initial keys"); - return nullptr; - } - } - } + walletInstance->SetupDescriptorScriptPubKeyMans(); + // SetupDescriptorScriptPubKeyMans already calls SetupGeneration for us so we don't need to call SetupGeneration separately } if (chain) { From 573bcd75d7b65ff02aaeea40d6f870a9c0bc7490 Mon Sep 17 00:00:00 2001 From: pablomartin4btc Date: Tue, 13 May 2025 12:37:53 -0300 Subject: [PATCH 2/3] wallet, refactor: Remove unused SetupGeneration SetupGeneration was supposed to be the function that all SPKMs used to setup automatic generation, but it didn't work out that way and ended up being legacy only. It should be deleted at this point. --- src/wallet/scriptpubkeyman.h | 6 ------ src/wallet/wallet.cpp | 1 - 2 files changed, 7 deletions(-) diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index e41ab6d669d..9ecc6084596 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -112,12 +112,6 @@ public: */ virtual std::vector MarkUnusedAddresses(const CScript& script) { return {}; } - /** Sets up the key generation stuff, i.e. generates new HD seeds and sets them as active. - * Returns false if already setup or setup fails, true if setup is successful - * Set force=true to make it re-setup if already setup, used for upgrades - */ - virtual bool SetupGeneration(bool force = false) { return false; } - /* Returns true if HD is enabled */ virtual bool IsHDEnabled() const { return false; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index af1a20dacb5..bdfe8d66592 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2870,7 +2870,6 @@ std::shared_ptr CWallet::Create(WalletContext& context, const std::stri if ((wallet_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) || !(wallet_creation_flags & (WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET))) { walletInstance->SetupDescriptorScriptPubKeyMans(); - // SetupDescriptorScriptPubKeyMans already calls SetupGeneration for us so we don't need to call SetupGeneration separately } if (chain) { From ce90f0c99fded22dd24f08757d6f48b5c6b52990 Mon Sep 17 00:00:00 2001 From: pablomartin4btc Date: Mon, 9 Jun 2025 20:19:31 -0300 Subject: [PATCH 3/3] rpc, wallet, refactor: Remove non-descriptor errors It is not possible to load a legacy/ non-descriptor wallet anymore so no need to check for WALLET_FLAG_DESCRIPTORS in RPC calls, even when passing -rpcwallet/ JSON `/wallet//` endpoint, that searches for the wallets loaded already in the context. --- src/wallet/rpc/backup.cpp | 9 --------- src/wallet/rpc/wallet.cpp | 9 --------- 2 files changed, 18 deletions(-) diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index c2a11e66c7c..f7d37239c6c 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -356,11 +356,6 @@ RPCHelpMan importdescriptors() // the user could have gotten from another RPC command prior to now wallet.BlockUntilSyncedToCurrentChain(); - // Make sure wallet is a descriptor wallet - if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { - throw JSONRPCError(RPC_WALLET_ERROR, "importdescriptors is not available for non-descriptor wallets"); - } - WalletRescanReserver reserver(*pwallet); if (!reserver.reserve(/*with_passphrase=*/true)) { throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait."); @@ -493,10 +488,6 @@ RPCHelpMan listdescriptors() const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return UniValue::VNULL; - if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { - throw JSONRPCError(RPC_WALLET_ERROR, "listdescriptors is not available for non-descriptor wallets"); - } - const bool priv = !request.params[0].isNull() && request.params[0].get_bool(); if (priv) { EnsureWalletIsUnlocked(*wallet); diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index 4bd4851609d..d1bf4105aa6 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -763,10 +763,6 @@ RPCHelpMan gethdkeys() const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return UniValue::VNULL; - if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { - throw JSONRPCError(RPC_WALLET_ERROR, "gethdkeys is not available for non-descriptor wallets"); - } - LOCK(wallet->cs_wallet); UniValue options{request.params[0].isNull() ? UniValue::VOBJ : request.params[0]}; @@ -865,11 +861,6 @@ static RPCHelpMan createwalletdescriptor() std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); if (!pwallet) return UniValue::VNULL; - // Make sure wallet is a descriptor wallet - if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { - throw JSONRPCError(RPC_WALLET_ERROR, "createwalletdescriptor is not available for non-descriptor wallets"); - } - std::optional output_type = ParseOutputType(request.params[0].get_str()); if (!output_type) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str()));