-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Add P2SH-P2WSH support to listunspent RPC #14481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/wallet/rpcwallet.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not a separate witnessScript field like in #14454?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sjors because this has to be compatible with how signrawtransaction works, so it can be passed directly in. signrawtransaction only accepts the witness script as "redeemScript" and automatically wraps it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be super involved to add support for witnessScript to signrawtransactionwithkey and signrawtransactionwithwallet? The terminology is already quite confusing, so consistency can really help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with @Sjors I'd much rather we fix terminology instead of compounding confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #14481 (comment)
Being consistent with terminology from https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wsh-address and importmulti seems good. Making it possible to call signrawtransaction directly also seems good. Can't we do both by updating signrawtransaction to accept a witnessScript field?
If we did this, I guess there would still be question of whether signrawtransaction should remain backwards compatible and continue accepting overloaded redeemScript's introduced in #12427, or if that feature should be deprecated. I'd probably opt not to deprecate. Nicolas made decent usability arguments in #11708 (comment), #11708 (comment) that overloading redeemScript can make calling signraw less painful, and that it doesn't introduce ambiguities that would let callers shoot themselves in the foot (which I guess would not be the case with importmulti).
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code utACK c789fef8ca4739e2fb3c930bacad77543650b781, but I agree with others about not wanting to overload redeemScript in listunspent #14481 (comment). It seems like it should be possible to be compatible with signraw without overloading.
src/wallet/rpcwallet.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #14481 (comment)
Being consistent with terminology from https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wsh-address and importmulti seems good. Making it possible to call signrawtransaction directly also seems good. Can't we do both by updating signrawtransaction to accept a witnessScript field?
If we did this, I guess there would still be question of whether signrawtransaction should remain backwards compatible and continue accepting overloaded redeemScript's introduced in #12427, or if that feature should be deprecated. I'd probably opt not to deprecate. Nicolas made decent usability arguments in #11708 (comment), #11708 (comment) that overloading redeemScript can make calling signraw less painful, and that it doesn't introduce ambiguities that would let callers shoot themselves in the foot (which I guess would not be the case with importmulti).
src/wallet/rpcwallet.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsPayToWitnessScriptHash succeeding and ExtractDestination failing should never happen, right? I think it would be better to trigger an actual error in this case than to silently fall back to the non-witness case.
|
I wonder if it isn't just easier to support passing in a descriptor in |
|
@meshcollider is there an update on the status of this PR? c789fef8ca4739e2fb3c930bacad77543650b781 seems like an improvement to me, and has my ACK. But I do think it would be an easy win to replace "redeemScript" with "witnessScript" there, and tweak Or if we want to abandon this approach and jump to descriptors instead as suggested in #14481 (comment), this seems like another good option. Do you have thoughts on it? Does it require more work? Is it blocked on anything now that #14477 is merged? |
|
@ryanofsky I plan on modifying this for terminology as above for now, and then I think we should look at RPC descriptor support as a whole after that. But I will come back to this PR in the next few days |
|
I've rebased this and addressed the terminology comments above, moving to a new witnessScript field with backwards compatibility |
Sjors
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bd2b1f65e949a1768c6f989677ea24b746384ca6 looks OK, but...
I have my doubt if backwards compatibility with something that was already buggy is worth the confusion of overloading redeemScript for listunspent. I'd rather have it null if signrawtransaction can infer it anyway, or even just the P2SH wrapper redeem script.
It might be better to squash the first and last commit.
I think addmultisigaddress should also return both redeemScript and witnessScript in the correct manner, so you you can just test:
assert_equal(unspent_output["witnessScript"], p2sh_p2wsh_address["witnessScript"])
assert_equal(unspent_output["redeemScript"], p2sh_p2wsh_address["redeemScript"])
assert_equal(unspent_output["redeemScript"], CScript([OP_0, sha256(hex_str_to_bytes(unspent_output["witnessScript"])))|
Forgot to update the release notes, listunspent doesn't overload redeemScript anymore Agree about addmultisigaddress, and about squashing 👍 |
|
I've squashed and updated the release notes, but modifying |
doc/release-notes-14481.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe optionally instead of also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please pass fractional amounts as a Decimal
Sjors
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to return a witnessScript as well as redeemScript would be a breaking change, because currently the witnessScript is returned as "redeemScript"
I could be wrong, but I suspect very few people use addmultisigaddress with SegWit in an automated setup (maybe @alecalve has stats on how much SegWit multisig is used in general). So it might still be early enough for a breaking change to use redeemScript and witnessScript accurately and consistently throughout the RPC.
(I can live with not doing it though)
src/rpc/rawtransaction.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also referring to this overloading.
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 77c0c8e246e1a7f8c403c19d13c8bb699dba8cf4. Left some comments but I think this is good to merge as-is. Only changes since last review are rebase and following up on previous suggestions (main one being to switch from redeemScript to witnessScript). Thanks for adopting these!
change to use
redeemScriptandwitnessScriptaccurately and consistently throughout the RPC
Would agree with Sjors in preferring to use these terms consistently, and breaking backwards compatibility in what seems to be a minor edge case. This could be done in a followup PR, and would be easy thing to explain in release notes.
src/rpc/rawtransaction.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Make listunspent return witness script for P2WSH or P2SH-P2WSH" (0b665ab577ab41e3b7b12d9b7d83c151cf90fdaf)
Could update commit message to mention change to signrawtransactionwithkey
src/wallet/rpcwallet.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Make listunspent return witness script for P2WSH or P2SH-P2WSH" (0b665ab577ab41e3b7b12d9b7d83c151cf90fdaf)
This would be broken if compiled with NDEBUG, which even though we don't support it, isn't really great for readability because you don't expect to see code with side effects inside an assert. Would be a little better to write something like:
bool extracted = ExtractDestitionation...;
assert(extracted);|
Needs rebase (blame me) |
|
Rebased and addressed comments above. @MarcoFalke I expect a review from you then ;)
|
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
utACK 6ca836a |
6ca836a Add release note for listunspent P2WSH change (MeshCollider) 928beae Add test for P2SH-P2WSH in signrawtransactionwithkey and listunspent (MeshCollider) 314784a Make listunspent and signrawtransaction RPCs support witnessScript (MeshCollider) Pull request description: This is a reworked version of #11708 after #12427 and the `signrawtransaction` split. For a P2WSH address, listunspent should return the witness script, and for a P2SH-P2WSH address, it should also return the inner witness script (because SignTransaction will automatically wrap it in P2SH if required). Includes a test which also tests the behaviour of #12427, and release note. Tree-SHA512: a8e72cf16930312bf48ec47e44a68f8d7e26664043c1b4cc0983eb25aec4087e511188ff9a0f181cd7b8a0c068c60d7f1e7e3f226b79e8c48890039dcf57f7b7
This is a reworked version of #11708 after #12427 and the
signrawtransactionsplit.For a P2WSH address, listunspent should return the witness script, and for a P2SH-P2WSH address, it should also return the inner witness script (because SignTransaction will automatically wrap it in P2SH if required).
Includes a test which also tests the behaviour of #12427, and release note.