-
Notifications
You must be signed in to change notification settings - Fork 38.7k
RPC/Wallet: Convert walletprocesspsbt to use options parameter #24963
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
vincenzopalazzo
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.
ACK 31ffd77
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/24963. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
pk-b2
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.
ACK 31ffd7782bf241ca09c7e192769ae9506bd2352f
- Built branch locally and exercised various manual test using both versions of the RPC
- Verified that passed in arguments get accepted
- Throws error when passing in options argument + additional invalid arguments
|
tbh I prefer #19762 instead of having options objects, but I don't feel strongly either way about this PR. |
|
There's a silent merge conflict with master. |
|
Drafted for now. Needs a PR description and rebasing to fix the merge conflict: wallet/rpc/spend.cpp:1541:75: error: no member named 'OMITTED_NAMED_ARG' in 'RPCArg::Optional'
{"options|sign", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "",
~~~~~~~~~~~~~~~~~~^
wallet/rpc/spend.cpp:1600:9: error: use of undeclared identifier 'RPCTypeCheckArgument'
RPCTypeCheckArgument(options, UniValue::VOBJ);
^
2 errors generated. |
81704c2 to
baf99a9
Compare
|
Rebased |
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.
Light code review ACK baf99a9c789779e89e7684a550e16cf1fb7ce862
src/rpc/util.h
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 "RPC: Support specifying different types for param aliases" (8a11b1525f2fa9f73715db46d228bda1eacdd2b2)
I think just calling this new struct member m_types would be more consistent with the m_names member. Also I think a followup commit should remove the m_type member which is now confusing and redundant.
src/rpc/util.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 "RPC: Support specifying different types for param aliases" (8a11b1525f2fa9f73715db46d228bda1eacdd2b2)
It would be good to have unit test coverage for this new code. Should be easy to add a test creating an RPCArg and calling this method in rpc_tests.cpp.
|
Converted to draft due to failing CI and inactivity |
|
CI failure appears to be a CI bug unrelated to this PR. |
0d09c94 to
645d041
Compare
|
Rebased to workaround CI bugs for now (is someone going to fix them?) |
Considering that CI is failing immediately after a |
Yes, there was a new issue introduced by the added commits too. But there was also a CI issue: it failed to merge into master before building. |
Not sure what failure you are referring to, but looking at https://github.com/bitcoin/bitcoin/actions/runs/11875971339/job/33093790745, it looks like the problem was that the CI did merge the config into master. The check-each-commit task is specifically written to compile the exact commits that are provided in the pull request, so that git bisect issues are detected early on. GHA is certainly buggy and I am not sure if there is a way to ask for some tasks to merge config and code and for others to not merge config nor code. Doing a rebase seems a simple enough workaround for now. If someone disagrees, pull requests with improvements are always welcome. |
ebbde4f to
40143ba
Compare
|
Assuming the remaining CI failure is #31307 |
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 review ACK 40143ba.
This is a pretty simple change to the RPC framework that should make it easy to add new options to RPCs like createwallet that currently accept too many positional parameters, without having to increase the number of positional parameters they already accept.
Without this PR, the only ways to add a new options to an RPC like createwallet without breaking backward compatibility are to add the option as a top-level parameter, where it can be specified as:
bitcoin-cli -named createwallet wallet_name option_name=option_value
bitcoin-cli createwallet wallet_name null null null null null null null option_valueor to add a new OBJ_NAMED_PARAMS parameter where it can be specified as:
bitcoin-cli -named createwallet wallet_name option_name=option_value
bitcoin-cli createwallet wallet_name null null null null null null null '{"option_name": "option_value"}'The first approach is unsafe because it allows option_value to be specified by position instead of name in an error prone way when there are too many positions. The second approach is safe, but not very appealing because it still increases the number of positional arguments, and doesn't display the old and new arguments in the same way in the documentation, or allow them to be accessed in the same way in the RPC implementation.
By contrast, this PR allows completely modernizing RPCs that accept a lot of positional parameters while retaining backwards compatibility. E.g. it would allow a new createwallet option to be passed as:
bitcoin-cli -named createwallet wallet_name option_name=option_value
bitcoin-cli createwallet wallet_name '{"option_name": "option_value"}'And it would show all options consistently in the documentation, and give callers ability to pass every option as a named parameter or as a field in an options object.
Notes on how this PR works:
- The first commit "RPC: Support specifying different types for param aliases" (04d7864) allows multiple types to be specified for parameters if the parameters have aliases, like:
"options|sign", {RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Type::BOOL}. It enforces that the number of types is the same as the number of aliases. Previously it was only possible to specify a single type for a parameter, even if it had multiple aliases. Additionally:- It updates the
RPCArg::MatchesType()function used to validate incoming RPC requests to accept any of the types specified in the list, instead of just the first type. If named parameters were passed, this commit does not enforce that the specific type corresponding to the named alias was used, but the third commit fixes this. - It fixes
RPCHelpMan::GetArgMap(), which is used to generatebitcoin-cli -regtest help dump_all_command_conversionsoutput, to output the correct type for each alias, instead just outputting the first type.
- It updates the
- The second commit updates
walletprocesspsbtto take advantage of the support for alias types added in the first commit. Specifically:- It changes the second parameter from
"sign"accepting a bool to"options|sign"accepting an options object or a bool. - It copies former definitions of the parameters 2-5 ("sign", "sighashtype", "bip32derivs", "finalize") into the options definition so they can be passed as options or named parameters by RPC clients.
- It keeps parameters 3-5 intact but marks them as hidden. Keeping these parameters allows clients to continue to pass them as positional parameters instead of as named parameters or options fields.
- It marks all the options
{.also_positional = true}to avoid errors from the RPC framework about options and parameters having duplicate names. - It updates the implementation of
walletprocesspsbtto read options and named arguments out of theoptionsobject, but keeps code for reading positional arguments out of theparamsobject if nooptionsobject is present.
- It changes the second parameter from
- The third commit adds stricter type checking to ensure that if a parameter has multiple aliases and each alias has an assigned type, and the parameter is passed by name instead of position, the parameter must have the expected type for that name. This prevents a bug described #24963 (comment), and the fourth commit just adds a test for this bug.
| } else { | ||
| // New style options are in an object | ||
| UniValue options = request.params[1]; | ||
| RPCTypeCheckObj(options, |
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 "RPC/Wallet: Convert walletprocesspsbt to use options parameter" (28023ff)
I think it would be good to move this code higher in the function, before the BlockUntilSyncedToCurrentChain and DecodeBase64PSBT calls to give caller more immediate feedback if they are calling this function with invalid parameters or the wrong types.
|
|
||
| # After update with wallet, only needs signing | ||
| updated = self.nodes[1].walletprocesspsbt(psbt, False, 'ALL', True)['psbt'] | ||
| assert_equal(updated, self.nodes[1].walletprocesspsbt(psbt, {"sign": False, "sighashtype": 'ALL', "bip32derivs": True})["psbt"]) |
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 "RPC/Wallet: Convert walletprocesspsbt to use options parameter" (28023ff)
Might be good to test a combination of named / positional arguments like
assert_equal(updated, self.nodes[1].walletprocesspsbt(psbt, sign=False, sighashtype='ALL', bip32derivs=True)["psbt"])|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
|
Closing this as it has not had any activity in a while. If you are interested in continuing work on this, please leave a comment so that it can be reopened. Marking as up for grabs. |
walletprocesspsbthas a single logical positional argument and a bunch that only make sense as named options. Convert them to an actual options Object for a better positional API.Retains backward compatibility for now.