-
Notifications
You must be signed in to change notification settings - Fork 38.6k
RPC: access RPC arguments by name #29277
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
RPC: access RPC arguments by name #29277
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. 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. |
|
Concept ACK |
|
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
2c222ea to
d2369cb
Compare
|
Force pushed to make CI happy:
|
fjahr
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.
Concept ACK, certainly makes the RPC code more readable.
@stickies-v have you considered preparing a map once when an RPC is called rather than doing the search for the index every time an arg is accessed?
I doubt this will have any impact. It could even perform worse, and require more code? Also, maps aren't constexpr, so if this is moved toward constexpr/consteval, it will have to be re-written again. |
d2369cb to
3918736
Compare
|
Force pushed to address indentation issue (and removed the unintuitive "developer mistake" comment in docstring)
I agree with @maflcko's reasoning, so going to leave this as is. |
maflcko
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 3918736 🍔
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 391873694137f241dfe1f57ed9058a438e147218 🍔
0mHHsiB/JX9sv6SH8E4hfbfpMPUipMUdvJ7diZjq+LEVBYg0u48Usa9OFR7sl0OdlDEJ3c64WImMfBoc80W4Bg==
Same amount of code and I don't see how this would perform worse: fjahr@cbda2cf I also find this easier to reason about.
I guess I don't have enough insight into future development plans of the RPC to judge that if is. But either way it seems weird to me that the best solution should be a |
You removed the
The In any case, it shouldn't matter much, since apparently it can easily be reverted if the switch to constexpr is done. |
tdb3
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.
Nice addition. Increases readability.
Concept ACK.
Inline comment provided.
Built and exercised unit tests and rpc* functional tests. All passed.
Compare the results of self.Arg with the request.params accessors to ensure they behave the same way.
Overload the Arg and MaybeArg helpers to allow accessing arguments by name as well. Also update the docs to document Arg and MaybeArg separately
Use the new key-based Arg helper in a few locations to show how it is used.
3918736 to
30a6c99
Compare
stickies-v
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.
Force-pushed to:
- rebase to latest master to address CI failure (?)
- fix some documentation inaccuracies (1, 2)
- address some test nits (1, 2)
- consistently use
actionvariable inscantxoutsetas per this comment
Thank you all for the review, apologies for the slow follow-up while I was on holidays.
Same amount of code and I don't see how this would perform worse: fjahr@cbda2cf I also find this easier to reason about.
Thank for writing out the code, I had assumed it'd be a bit more overhead (even after adding the CHECK_NONFATAL which can be done in just one line). I would still prefer to stick with the current approach. As maflcko suggests, the number of parameters is always going to be very small, so given that we don't have to allocate a map I'm unsure how this would perform differently but I don't think it's worth investigating given that both will be very fast. I do prefer this approach being more self-contained inside GetParamIndex, as opposed to adding another member variable and adding to the already verbose RPCHelpMan constructor, so will keep as is.
|
Does it work with |
Nope. I think we should just address the general use case of getting |
| ChainstateManager& chainman = EnsureAnyChainman(request.context); | ||
| LOCK(cs_main); | ||
| return GetNetworkHashPS(self.Arg<int>(0), self.Arg<int>(1), chainman.ActiveChain()); | ||
| return GetNetworkHashPS(self.Arg<int>("nblocks"), self.Arg<int>("height"), chainman.ActiveChain()); |
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.
It could make sense to remove the index-based access and require the name-based access?
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.
Done in #29997
|
Code review ACK 30a6c99 I still prefer my suggested approach but it's still an improvement and I don't want to block this. |
|
ACK 30a6c99 🥑 Show signatureSignature: |
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 review ACK 30a6c99. Nice change! Implementation is surprisingly simple and additional unit test coverage is welcome, too.
Does it work with
OBJ_NAMED_PARAMS?Nope. I think we should just address the general use case of getting
OBJ/ARRargs with theArghelpers, and then that should help withOBJ_NAMED_PARAMStoo?
It would be nice to support this for consistency, but benefit is probably more minor since these arguments are already accessed by name, and omitting this keeps the code very simple.
Summary: Add arg helper unit test. Compare the results of self.Arg with the request.params accessors to ensure they behave the same way. Overload the Arg and MaybeArg helpers to allow accessing arguments by name as well. Also update the docs to document Arg and MaybeArg separately Use the new key-based Arg helper in a few locations to show how it is used. This is a backport of [[bitcoin/bitcoin#29277 | core#29277]] Depends on D17946 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D17947
Adds string overloads for the
RPCHelpMan::ArgandRPCHelpMan::MaybeArghelpers to be able to access RPC arguments by name instead of index number. Especially in RPCs with a large number of parameters, this can be quite helpful.Example usage:
Most of the LoC is adding test coverage and documentation updates. No behaviour change.
An alternative approach to #27788 with significantly less overhaul.