From 91310753da412e043daa6da355660ae8c038d504 Mon Sep 17 00:00:00 2001 From: scgbckbone Date: Tue, 17 Dec 2024 11:21:56 +0100 Subject: [PATCH] bugfix: disallow label for ranged descriptors & allow external descriptors to have label * do not only check user provided range data to decide whether descriptor is ranged * properly handle std::optional when checking if descriptor is internal --- src/wallet/rpc/backup.cpp | 8 +++++--- test/functional/wallet_rescan_unconfirmed.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index bfd7249c046..4544162d847 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -1482,6 +1482,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c } // Range check + std::optional is_ranged; int64_t range_start = 0, range_end = 1, next_index = 0; if (!parsed_descs.at(0)->IsRange() && data.exists("range")) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Range should not be specified for an un-ranged descriptor"); @@ -1496,6 +1497,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c range_end = wallet.m_keypool_size; } next_index = range_start; + is_ranged = true; if (data.exists("next_index")) { next_index = data["next_index"].getInt(); @@ -1517,12 +1519,13 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c } // Ranged descriptors should not have a label - if (data.exists("range") && data.exists("label")) { + if (is_ranged.has_value() && is_ranged.value() && data.exists("label")) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Ranged descriptors should not have a label"); } + bool desc_internal = internal.has_value() && internal.value(); // Internal addresses should not have a label either - if (internal && data.exists("label")) { + if (desc_internal && data.exists("label")) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label"); } @@ -1538,7 +1541,6 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c for (size_t j = 0; j < parsed_descs.size(); ++j) { auto parsed_desc = std::move(parsed_descs[j]); - bool desc_internal = internal.has_value() && internal.value(); if (parsed_descs.size() == 2) { desc_internal = j == 1; } else if (parsed_descs.size() > 2) { diff --git a/test/functional/wallet_rescan_unconfirmed.py b/test/functional/wallet_rescan_unconfirmed.py index 69ad522b5d3..9bdc932aa3a 100755 --- a/test/functional/wallet_rescan_unconfirmed.py +++ b/test/functional/wallet_rescan_unconfirmed.py @@ -66,7 +66,8 @@ class WalletRescanUnconfirmed(BitcoinTestFramework): assert tx_parent_to_reorg["txid"] in node.getrawmempool() self.log.info("Import descriptor wallet on another node") - descriptors_to_import = [{"desc": w0.getaddressinfo(parent_address)['parent_desc'], "timestamp": 0, "label": "w0 import"}] + # descriptor is ranged - label not allowed + descriptors_to_import = [{"desc": w0.getaddressinfo(parent_address)['parent_desc'], "timestamp": 0}] node.createwallet(wallet_name="w1", disable_private_keys=True) w1 = node.get_wallet_rpc("w1")