Check if the wallet already contains the descriptor GetDescriptorScriptPubKeyMan #32013

removed duplicate calling of GetDescriptorScriptPubKeyMan after this its significantly improved performance of importdescriptor part.
This commit is contained in:
Saikiran 2025-03-10 15:20:55 +05:30
parent 45719390a1
commit d53f4d8b43
2 changed files with 7 additions and 8 deletions

View file

@ -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); 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 // Add descriptor to the wallet
auto spk_manager = wallet.AddWalletDescriptor(w_desc, keys, label, desc_internal); auto spk_manager = wallet.AddWalletDescriptor(w_desc, keys, label, desc_internal);
if (spk_manager == nullptr) { if (spk_manager == nullptr) {

View file

@ -69,6 +69,8 @@
#include <wallet/types.h> #include <wallet/types.h>
#include <wallet/walletdb.h> #include <wallet/walletdb.h>
#include <wallet/walletutil.h> #include <wallet/walletutil.h>
#include <rpc/request.h>
#include <rpc/protocol.h>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
@ -3950,8 +3952,13 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
return nullptr; return nullptr;
} }
std::string error;
auto spk_man = GetDescriptorScriptPubKeyMan(desc); auto spk_man = GetDescriptorScriptPubKeyMan(desc);
if (spk_man) { 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()); WalletLogPrintf("Update existing descriptor: %s\n", desc.descriptor->ToString());
spk_man->UpdateWalletDescriptor(desc); spk_man->UpdateWalletDescriptor(desc);
} else { } else {