Skip to content

Commit 06ea278

Browse files
committed
Merge bitcoin/bitcoin#25220: rpc: fix incorrect warning for address type p2sh-segwit in createmultisig
3a9b9bb test: ensure createmultisig and addmultisigaddress are not returning any warning for expected cases (brunoerg) eaf6f63 rpc: fix inappropriate warning for address type p2sh-segwit in createmultisig and addmultisigaddress (brunoerg) Pull request description: Fixes #25127 If there are any uncompressed keys when calling `AddAndGetMultisigDestination`, it will just default to a legacy address regardless of the chosen `address_type`. So, #23113 added a warnings field which will warn the user why their address format is different. However, when creating a multisig (p2sh-segwit), it is returning an inappropriate warning, because when getting the output type from destination (`OutputTypeFromDestination`), it returns `ScriptHash` for both legacy and `P2SH_SEGWIT`. So, since `P2SH_SEGWIT` is different from `ScriptHash`, it returns the warning: https://github.com/bitcoin/bitcoin/blob/192d639a6b1bd0feaa52e6ea4e63e33982704c32/src/rpc/output_script.cpp#L166-L169 So, to avoid this mistake I changed `OutputTypeFromDestination` to `descriptor->GetOutputType()` to get the appropriate output type. ACKs for top commit: jonatack: ACK 3a9b9bb laanwj: Code review ACK 3a9b9bb Tree-SHA512: 49f717479c2b8906277e7591ddd4747f7961c2d5c77494b5124045de9036a4277d46b9ad99279d51f0c4484284c445f1e1d3c55c49bbf0716741bad426a89369
2 parents e82d806 + 3a9b9bb commit 06ea278

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/rpc/output_script.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ static RPCHelpMan createmultisig()
163163
result.pushKV("descriptor", descriptor->ToString());
164164

165165
UniValue warnings(UniValue::VARR);
166-
if (!request.params[2].isNull() && OutputTypeFromDestination(dest) != output_type) {
166+
if (descriptor->GetOutputType() != output_type) {
167167
// Only warns if the user has explicitly chosen an address type we cannot generate
168168
warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present.");
169169
}
170-
if (warnings.size()) result.pushKV("warnings", warnings);
170+
if (!warnings.empty()) result.pushKV("warnings", warnings);
171171

172172
return result;
173173
},

src/wallet/rpc/addresses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ RPCHelpMan addmultisigaddress()
302302
result.pushKV("descriptor", descriptor->ToString());
303303

304304
UniValue warnings(UniValue::VARR);
305-
if (!request.params[3].isNull() && OutputTypeFromDestination(dest) != output_type) {
305+
if (descriptor->GetOutputType() != output_type) {
306306
// Only warns if the user has explicitly chosen an address type we cannot generate
307307
warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present.");
308308
}
309-
if (warnings.size()) result.pushKV("warnings", warnings);
309+
if (!warnings.empty()) result.pushKV("warnings", warnings);
310310

311311
return result;
312312
},

test/functional/rpc_createmultisig.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,17 @@ def run_test(self):
9191
assert 'warnings' not in result
9292

9393
# Generate addresses with the segwit types. These should all make legacy addresses
94+
err_msg = ["Unable to make chosen address type, please ensure no uncompressed public keys are present."]
95+
9496
for addr_type in ['bech32', 'p2sh-segwit']:
95-
result = self.nodes[0].createmultisig(2, keys, addr_type)
97+
result = self.nodes[0].createmultisig(nrequired=2, keys=keys, address_type=addr_type)
9698
assert_equal(legacy_addr, result['address'])
97-
assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."])
99+
assert_equal(result['warnings'], err_msg)
98100

99101
if self.is_bdb_compiled():
100-
result = wmulti0.addmultisigaddress(2, keys, '', addr_type)
102+
result = wmulti0.addmultisigaddress(nrequired=2, keys=keys, address_type=addr_type)
101103
assert_equal(legacy_addr, result['address'])
102-
assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."])
104+
assert_equal(result['warnings'], err_msg)
103105

104106
self.log.info('Testing sortedmulti descriptors with BIP 67 test vectors')
105107
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json'), encoding='utf-8') as f:
@@ -173,6 +175,7 @@ def do_multisig(self):
173175
desc = descsum_create(desc)
174176

175177
msig = node2.createmultisig(self.nsigs, self.pub, self.output_type)
178+
assert 'warnings' not in msig
176179
madd = msig["address"]
177180
mredeem = msig["redeemScript"]
178181
assert_equal(desc, msig['descriptor'])

0 commit comments

Comments
 (0)