Skip to content
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: Assert that RPCArg names are equal to CRPCCommand ones (mining,zmq,rpcdump) #19717

Merged
merged 4 commits into from
Aug 31, 2020

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Aug 14, 2020

This is split out from #18531 to just touch the RPC methods in misc. Description from the main pr:

Motivation

RPCArg names in the rpc help are currently only used for documentation. However, in the future they could be used to teach the server the named arguments. Named arguments are currently registered by the CRPCCommands and duplicate the RPCArg names from the documentation. This redundancy is fragile, and has lead to errors in the past (despite having linters to catch those kind of errors). See section "bugs found" for a list of bugs that have been found as a result of the changes here.

Changes

The changes here add an assert in the CRPCCommand constructor that the RPCArg names are identical to the ones in the CRPCCommand.

Future work

Here or follow up, makes sense to also assert type of returned UniValue?

Sure, but let's not get ahead of ourselves. I am going to submit any further works as follow-ups, including:

  • Removing the CRPCCommand arguments, now that they are asserted to be equal and thus redundant
  • Removing all python regex linters on the args, now that RPCMan can be used to generate any output, including the cli.cpp table
  • Auto-formatting and sanity checking the RPCExamples with RPCMan
  • Checking passed-in json in self-check. Removing redundant checks
  • Checking returned json against documentation to avoid regressions or false documentation
  • Compile the RPC documentation at compile-time to ensure it doesn't change at runtime and is completely static

Bugs found

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

src/rpc/server.cpp Outdated Show resolved Hide resolved
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 14, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, 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.

@practicalswift
Copy link
Contributor

Concept ACK

Copy link
Member

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK fa3d9ce.

@fjahr
Copy link
Contributor

fjahr commented Aug 31, 2020

tested ACK fa3d9ce

Reviewed code, used help on a few RPCs, changed an RPC arg to see the failure.

@maflcko maflcko merged commit 89a8299 into bitcoin:master Aug 31, 2020
@maflcko maflcko deleted the 2008-rpcMisc branch August 31, 2020 15:49
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 31, 2020
…ommand ones (mining,zmq,rpcdump)

fa3d9ce rpc: Assert that RPCArg names are equal to CRPCCommand ones (rpcdump) (MarcoFalke)
fa32c1d rpc: Assert that RPCArg names are equal to CRPCCommand ones (zmq) (MarcoFalke)
faaa46d rpc: Assert that RPCArg names are equal to CRPCCommand ones (mining) (MarcoFalke)
fa93bc1 rpc: Remove unused return type from appendCommand (MarcoFalke)

Pull request description:

  This is split out from bitcoin#18531 to just touch the RPC methods in misc. Description from the main pr:

  ### Motivation

  RPCArg names in the rpc help are currently only used for documentation. However, in the future they could be used to teach the server the named arguments. Named arguments are currently registered by the `CRPCCommand`s and duplicate the RPCArg names from the documentation. This redundancy is fragile, and has lead to errors in the past (despite having linters to catch those kind of errors). See section "bugs found" for a list of bugs that have been found as a result of the changes here.

  ### Changes

  The changes here add an assert in the `CRPCCommand` constructor that the RPCArg names are identical to the ones in the `CRPCCommand`.

  ### Future work

  > Here or follow up, makes sense to also assert type of returned UniValue?

  Sure, but let's not get ahead of ourselves. I am going to submit any further works as follow-ups, including:

  * Removing the CRPCCommand arguments, now that they are asserted to be equal and thus redundant
  * Removing all python regex linters on the args, now that RPCMan can be used to generate any output, including the cli.cpp table
  * Auto-formatting and sanity checking the RPCExamples with RPCMan
  * Checking passed-in json in self-check. Removing redundant checks
  * Checking returned json against documentation to avoid regressions or false documentation
  * Compile the RPC documentation at compile-time to ensure it doesn't change at runtime and is completely static

  ### Bugs found

  * The assert identified issue bitcoin#18607
  * The changes itself fixed bug bitcoin#19250

ACKs for top commit:
  fjahr:
    tested ACK fa3d9ce
  promag:
    Code review ACK fa3d9ce.

Tree-SHA512: 068ade4b55cc195868d53b7f9a27151d45b440857bb069e261a49d102a49a38fdba5d68868516a1d66a54a73ba34681362f934ded7349e894042bde873b75719
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 20, 2021
Summary:
This is a backport of [[bitcoin/bitcoin#19717 | core#19717]] [1/4]
bitcoin/bitcoin@fa93bc1

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10145
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 20, 2021
Summary:
This is a backport of [[bitcoin/bitcoin#19717 | core#19717]] [2/4]
bitcoin/bitcoin@faaa46d

Note: the double `\n` in `rpc_generate.py` is required because of D7184

Depends on D10145 and D10149

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10146
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 20, 2021
Summary:
This is a backport of [[bitcoin/bitcoin#19717 | core#19717]] [3/4]
bitcoin/bitcoin@fa32c1d

Depends on D10146 and D10149

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10147
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 20, 2021
Summary:
This concludes backport of [[bitcoin/bitcoin#19717 | core#19717]] [4/4]
bitcoin/bitcoin@fa3d9ce

Depends on D10147, D10149 and D10159

Note: the forward declaration of RPC functions in rpcwallet.cpp don't seem to exist in Bitcoin ABC, and the ones in wallet_tests.cpp were in rpcdump.h (see D45)

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10148
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants