From d53f4d8b43c5d15b1ff2fcafeebc2124142009c8 Mon Sep 17 00:00:00 2001 From: Saikiran Date: Mon, 10 Mar 2025 15:20:55 +0530 Subject: [PATCH] Check if the wallet already contains the descriptor GetDescriptorScriptPubKeyMan #32013 removed duplicate calling of GetDescriptorScriptPubKeyMan after this its significantly improved performance of importdescriptor part. --- src/wallet/rpc/backup.cpp | 8 -------- src/wallet/wallet.cpp | 7 +++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index ac23b092d40..3a00dca8d96 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -1575,14 +1575,6 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c WalletDescriptor w_desc(std::move(parsed_desc), timestamp, range_start, range_end, next_index); - // Check if the wallet already contains the descriptor - auto existing_spk_manager = wallet.GetDescriptorScriptPubKeyMan(w_desc); - if (existing_spk_manager) { - if (!existing_spk_manager->CanUpdateToWalletDescriptor(w_desc, error)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, error); - } - } - // Add descriptor to the wallet auto spk_manager = wallet.AddWalletDescriptor(w_desc, keys, label, desc_internal); if (spk_manager == nullptr) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7abd17d31e9..29c332797f7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -69,6 +69,8 @@ #include #include #include +#include +#include #include #include @@ -3950,8 +3952,13 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat return nullptr; } + std::string error; auto spk_man = GetDescriptorScriptPubKeyMan(desc); if (spk_man) { + if (!spk_man->CanUpdateToWalletDescriptor(desc, error)) { + WalletLogPrintf("Invalid param: %s\n", error); + throw JSONRPCError(RPC_INVALID_PARAMETER, error); + } WalletLogPrintf("Update existing descriptor: %s\n", desc.descriptor->ToString()); spk_man->UpdateWalletDescriptor(desc); } else {