rpc: Assert that RPCArg names are equal to CRPCCommand ones (misc) #19528

pull MarcoFalke wants to merge 4 commits into bitcoin:master from MarcoFalke:2007-rpcMiscAssert changing 8 files +110 −76
  1. MarcoFalke commented at 7:37 pm on July 15, 2020: member

    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

    • The assert identified issue #18607
    • The changes itself fixed bug #19250
  2. MarcoFalke added the label Refactoring on Jul 15, 2020
  3. MarcoFalke added the label RPC/REST/ZMQ on Jul 15, 2020
  4. MarcoFalke force-pushed on Jul 15, 2020
  5. MarcoFalke force-pushed on Jul 15, 2020
  6. DrahtBot commented at 4:40 am on July 16, 2020: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #19550 (rpc: Add getindexinfo RPC by fjahr)
    • #18448 (rpc: fix/add missing RPCExamples for “Util” RPCs by theStack)
    • #16365 (Log RPC parameters (arguments) if -debug=rpcparams by LarryRuane)

    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.

  7. in src/rpc/server.cpp:260 in fa266ae6a2 outdated
    262-        const CRPCCommand *pcmd;
    263-
    264-        pcmd = &vRPCCommands[vcidx];
    265-        mapCommands[pcmd->name].push_back(pcmd);
    266+    for (const auto& c : vRPCCommands) {
    267+        std::cout << appendCommand(c.name, &c) << std::endl;
    


    theStack commented at 2:09 pm on August 2, 2020:
    Looks like some debug output is left here? Note that unlike the original code, appendCommand() is more strict as it doesn’t append the command If RPC is running (I guess that’s the reason for the cout, you wanted to test If appendCommand returns false in practice).
  8. theStack commented at 2:12 pm on August 2, 2020: member
    Concept ACK. As far as I see, this mainly uses the new CRPCCommand constructor that was introduced in an earlier PR. Will review the main commit more in detail.
  9. MarcoFalke force-pushed on Aug 2, 2020
  10. MarcoFalke commented at 7:13 pm on August 2, 2020: member
    Thanks, fixed leftover
  11. MarcoFalke force-pushed on Aug 2, 2020
  12. rpc: Treat all args after a hidden arg as hidden as well
    This commit has no effect right now, but hardens the code for the future
    fa459bdc87
  13. refactor: Use C++11 range based for loops to simplify rpc code fa89ca9b5b
  14. rpc: Limit echo to 10 args fa50bdc755
  15. rpc: Assert that RPCArg names are equal to CRPCCommand ones (misc) fa77de2baa
  16. MarcoFalke force-pushed on Aug 2, 2020
  17. theStack approved
  18. theStack commented at 10:13 am on August 7, 2020: member

    ACK https://github.com/bitcoin/bitcoin/pull/19528/commits/fa77de2baa40ee828c850ef4068c76cc3619e87b For a small code readability nit, I think it makes sense to re-indent after all RPC modules have been updated to use the new RPCHelpMan. The first few ctor arguments to RPCHelpMan seem to be over-indented, while the function body seems under-indented, which looks quite odd. Would personally prefer it like this:

     0static RPCHelpMan somecoolrpcmethod()
     1{
     2    return RPCHelpMan{"name",
     3        "\ndescription\n",
     4        {
     5            ...
     6        },
     7        RPCResult{
     8            ...
     9        },
    10        RPCExamples{
    11            ...
    12        },
    13        [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
    14        {
    15            ...
    16        },
    17    };
    18}
    
  19. in src/rpc/misc.cpp:627 in fa77de2baa
    631+        [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
    632+{
    633+    if (request.fHelp) throw std::runtime_error(self.ToString());
    634 
    635-    CHECK_NONFATAL(request.params.size() != 100);
    636+    if (request.params[9].isStr()) {
    


    laanwj commented at 3:14 pm on August 7, 2020:
    I don’t think multiplexing an argument on string/number type is generally a good idea. Because it’s harder to use from some (statically typed) languages, and even from bitcoin-cli I think.. But for a test call ti’s fine so no problem here specifically, but it’s not something to encourage.
  20. laanwj commented at 3:16 pm on August 7, 2020: member
    Code review ACK fa77de2baa40ee828c850ef4068c76cc3619e87b
  21. ryanofsky approved
  22. ryanofsky commented at 1:39 pm on August 12, 2020: member
    Code review ACK fa77de2baa40ee828c850ef4068c76cc3619e87b. Pretty straightfoward changes
  23. fjahr commented at 3:21 pm on August 13, 2020: member

    tested ACK fa77de2baa40ee828c850ef4068c76cc3619e87b

    Reviewed code, used the new style from fa77de2baa40ee828c850ef4068c76cc3619e87b in #19550 and tested the change in echo.

  24. MarcoFalke merged this on Aug 14, 2020
  25. MarcoFalke closed this on Aug 14, 2020

  26. MarcoFalke deleted the branch on Aug 14, 2020
  27. sidhujag referenced this in commit b761dae549 on Aug 16, 2020
  28. deadalnix referenced this in commit b46e1c9d15 on Sep 10, 2021
  29. deadalnix referenced this in commit 16268cd747 on Sep 10, 2021
  30. Fabcien referenced this in commit 378a70f4ea on Sep 10, 2021
  31. Fabcien referenced this in commit 09c0f3c592 on Sep 10, 2021
  32. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 00:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me