rpc: Check named args names and result field names at compile time #36478

pull maflcko wants to merge 2 commits into bitcoin:master from maflcko:2610-rpc-compile-time-names-and-fiel-names changing 9 files +92 −43
  1. maflcko commented at 4:00 PM on October 8, 2026: member

    This is a small linter to reject confusingly named RPC arg names or RPC result fields. Generally, such names should be snake_case. Otherwise, there are bugs and confusion.

    For now, write a C++20 consteval linter that still accepts MiXed_cAse. In the future, it can be made stricter.

  2. DrahtBot renamed this:
    rpc: Check named args names and result field names at compile time
    rpc: Check named args names and result field names at compile time
    on Oct 8, 2026
  3. DrahtBot added the label RPC/REST/ZMQ on Oct 8, 2026
  4. DrahtBot commented at 4:01 PM on October 8, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK fametrano

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35713 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35713.svg"></sub> (Remove boost as a unit test runner by rustaceanrob)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. maflcko commented at 4:01 PM on October 8, 2026: member

    This is a refactor, only the RPC docs change minimally:

    diff --git a/generateblock b/generateblock
    index c552f4a..e1d1cbd 100644
    --- a/generateblock
    +++ b/generateblock
    @@ -1,2 +1,2 @@
    -generateblock "output" ["rawtx/txid",...] ( submit )
    +generateblock "output" ["rawtx_or_txid",...] ( submit )
     
    @@ -11,3 +11,3 @@ Arguments:
          [
    -       "rawtx/txid",    (string)
    +       "rawtx_or_txid",    (string)
            ...
    diff --git a/getnetworkinfo b/getnetworkinfo
    index 33b9c69..7d075f9 100644
    --- a/getnetworkinfo
    +++ b/getnetworkinfo
    @@ -18,3 +18,3 @@ Result:
       "inv_buckets" : {                                  (json object)
    -    "inbound/outbound" : {                           (json object) connection direction
    +    "direction" : {                                  (json object) connection direction (inbound or outbound)
           "backlog" : n,                                 (numeric) number of queued txs to announce
    diff --git a/getprioritisedtransactions b/getprioritisedtransactions
    index a87170f..d3dc64c 100644
    --- a/getprioritisedtransactions
    +++ b/getprioritisedtransactions
    @@ -6,3 +6,3 @@ Result:
     {                                 (json object) prioritisation keyed by txid
    -  "<transactionid>" : {           (json object)
    +  "transactionid" : {             (json object)
         "fee_delta" : n,              (numeric) transaction fee delta in satoshis
    diff --git a/getrawaddrman b/getrawaddrman
    index 43e3219..d44bd58 100644
    --- a/getrawaddrman
    +++ b/getrawaddrman
    @@ -9,3 +9,3 @@ Result:
       "table" : {                      (json object) buckets with addresses in the address manager table ( new, tried )
    -    "bucket/position" : {          (json object) the location in the address manager table (<bucket>/<position>)
    +    "bucket_and_position" : {      (json object) address manager table location, formatted as <bucket>/<position>
           "address" : "str",           (string) The address of the node
    
  6. maflcko force-pushed on Oct 8, 2026
  7. DrahtBot added the label CI failed on Oct 8, 2026
  8. DrahtBot commented at 5:18 PM on October 8, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task previous releases: https://github.com/bitcoin/bitcoin/actions/runs/37805451315/job/113408400251</sub> <sub>LLM reason (✨ experimental): The build failed compiling rpc_tests.cpp: GCC 12 rejected constant evaluation of ConstevalRpcArgName construction in std::tuple.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  9. rpc: Check named args names at compile time fa0794bb62
  10. rpc: Check result field names at compile time
    This also requires disabling modernize-use-emplace for now, because
    clang-tidy will incorrectly suggest to use emplace, which will not work
    with the consteval name.
    
    Disabling should be fine, because moves are typically cheap and in-place
    construction is not really needed.
    fabdf113d3
  11. maflcko force-pushed on Oct 8, 2026
  12. DrahtBot removed the label CI failed on Oct 8, 2026
  13. fametrano commented at 6:52 AM on October 25, 2026: none

    tACK fabdf113d377d507658557cfb5933dcd13324f10

    I built the base and the head (macOS, Apple clang 21) and compared them on regtest with a script that dumps and diffs both builds. help for all 174 commands, hidden ones included, differs only in the four renames you listed, plus the column realignment in generateblock that the longer name causes. getopenrpcinfo is byte-identical, with and without show_hidden. Calls to the touched RPCs gave the same result structure under -rpcdoccheck=1. rpc_tests and ten related functional tests pass. Compile time of rpc/blockchain.cpp, rpc/rawtransaction.cpp and wallet/rpc/spend.cpp did not grow.

    I also compiled a file of deliberately bad names, one case at a time. The check rejected all of them: a space or - in argument names, a space, /, <> or non-ASCII in result keys, and such names nested inside OBJ arguments and OBJ_DYN results. A name built at runtime is rejected too. The errors point at the offending literal.

    Alias lists with empty parts still compile, such as "a||b", "|" and "a|". At runtime the empty part becomes a named argument called "". Rejecting it may be worth it while you are here. I can share the script and the file as a gist.

  14. maflcko commented at 8:54 AM on October 26, 2026: member

    Alias lists with empty parts still compile

    I'd say that is fine, because there is no risk. The goal here is to just lint the name and slowly converge toward snake_case. Results with an empty string are valid (e.g. in arrays). And Args with an empty string shouldn't pass normal review or tests anyway. No need to lint those.


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: 2026-10-30 09:40 UTC