Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Aug 31, 2020

This is split out from #18531 to just touch some RPC methods. 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

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 31, 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.

@fjahr
Copy link
Contributor

fjahr commented Aug 31, 2020

utACK fa6bb0c

@tryphe
Copy link
Contributor

tryphe commented Sep 16, 2020

utACK fa6bb0c. Reducing data duplication is nice. Code changes are minimal and concise.

@tryphe
Copy link
Contributor

tryphe commented Sep 16, 2020

Other thoughts: perhaps leave a commented example of how to add the old style RPC, if someone wants to add their own RPC without documentation.

@maflcko maflcko merged commit d692d19 into bitcoin:master Sep 22, 2020
@maflcko maflcko deleted the 2008-rpcAssertNames branch September 22, 2020 15:58
@maflcko
Copy link
Member Author

maflcko commented Sep 22, 2020

Other thoughts: perhaps leave a commented example of how to add the old style RPC, if someone wants to add their own RPC without documentation.

You can skip adding documentation by passing empty strings, though the argument names need to be specified (both with the legacy constructor and the new one). Only difference is that the types will have to be specified as well. If it is worth it to allow arbitrary types for a quick hack, it might be useful to overwrite the Check method (e.g. with a noop), but I'll leave that for a follow-up.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 23, 2020
…d ones (blockchain,rawtransaction)

fa6bb0c Assert that RPCArg names are equal to CRPCCommand ones (rawtransaction) (MarcoFalke)
fa80c81 Assert that RPCArg names are equal to CRPCCommand ones (blockchain) (MarcoFalke)

Pull request description:

  This is split out from bitcoin#18531 to just touch some RPC methods. 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:
    utACK fa6bb0c
  tryphe:
    utACK fa6bb0c. Reducing data duplication is nice. Code changes are minimal and concise.

Tree-SHA512: deb0edc3f999baf055526eaa199b98c500635e12502dece7aa3cad5319db330eb5ee7459a5c8f040a83671a7f20c560c19a2026fb76c8416f138aa332727cbce
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 12, 2021
Summary:
> This is split out from #18531 to just touch some RPC methods. 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.

This is a backport of [[bitcoin/bitcoin#19849 | core#19849]] [1/2]
bitcoin/bitcoin@fa80c81

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10298
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 12, 2021
Summary:
This is a backport of [[bitcoin/bitcoin#19849 | core#19849]] [2/2]
bitcoin/bitcoin@fa6bb0c

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10299
@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.

4 participants