#36175 rpc: Stamp `getblock` OpenRPC result discriminator

full analysis

https://github.com/bitcoin/bitcoin/pull/36175 · nervana21 · +54/-5 in 4 files, 3 commits · labels: RPC/REST/ZMQ

Goal

  • Let RPC client generators automatically map getblock verbosity levels to their result schemas
  • Stops downstream client libraries from having to hardcode which parameter value selects which schema

This pull request introduces an `RPCResultDiscriminator` struct to annotate RPC methods with `oneOf` result schemas in OpenRPC. It applies this annotation to `getblock` under the custom `x-bitcoin-discriminated-result` property, mapping verbosity levels 0 through 3 to their respective result arms. It also documents schema extensions in `getopenrpcinfo` and explains in `getblock` help why verbosity 2 and 3 responses cannot be distinguished by JSON schema validation alone.

Problem: OpenRPC documents `getblock` as a four-way `oneOf` based on the `verbosity` parameter, but does not specify which parameter value selects which schema branch, forcing client libraries to hardcode the mapping.

Category: RPC / REST / ZMQ (#34 of 52)

P3 · new feature

  • P3 because it adds structured metadata to OpenRPC output for downstream client generators
  • Tools like corepc and btcd will no longer need to hardcode the getblock schema mapping
  • It provides tooling leverage without altering runtime RPC behavior or node stability

P3 because it adds structured metadata to OpenRPC output for downstream client generators. As the author notes, clients like corepc and btcd previously had to hardcode the verbosity-to-schema mapping for getblock. The change does not alter runtime RPC handling or consensus/node behavior, but provides clean tooling value.

Membership: Touches src/rpc/blockchain.cpp, src/rpc/server.cpp, src/rpc/util.h, and OpenRPC functional tests.

Factors: security/stability 0, bug 0, performance 0, user value 1, leverage 1

Reviewability: Ready

  • Ready to review now; diff is small, CI passes, and only a minor inline question is open

The patch is small, cleanly rebased, and CI passes. Only one minor inline question is outstanding.

Author status: Active; addressed initial feedback and force-pushed updates

Open concerns:

  • maflcko asked about the necessity of a static_cast<int> on parameter index in server.cpp

Resolved concerns:

  • jeanpablojp suggested pinning parameter-name and schema-content invariants in rpc_openrpc.py instead of just literal values, which the author implemented
  • Documented x-bitcoin-discriminated-result and x-bitcoin-default-hint in OpenRPCDocResult schema documentation

Agreement: Positive

  • Generally positive reception on clarifying schema branches for downstream tools
  • Concept ACK with test and documentation improvements that the author incorporated (jeanpablojp)
  • Minor inline question regarding a static_cast on parameter index (maflcko)

Concept ACK from jeanpablojp with resolved suggestions; minor comment from maflcko

Reviewer jeanpablojp Concept ACKed the PR and suggested test and documentation improvements that were incorporated. Reviewer maflcko left a minor inline question.

  • jeanpablojp gave a Concept ACK and suggested strengthening test assertions and schema documentation
  • nervana21 implemented jeanpablojp's suggestions and updated tests
  • maflcko asked about a static_cast in server.cpp

Review verdicts (DrahtBot): 0

Files

11 lines under test/bench/ci.

  • src/rpc/util.h +23/-0
  • src/rpc/server.cpp +15/-2
  • test/functional/rpc_openrpc.py +11/-0
  • src/rpc/blockchain.cpp +5/-3

Card

This PR adds `RPCResultDiscriminator` metadata to the OpenRPC schema generator and stamps `getblock` with `x-bitcoin-discriminated-result` to explicitly map verbosity parameters 0-3 to their respective result schemas. This allows RPC code generators and typed client libraries to automatically map return types to `getblock` calls without hardcoding. It has a Concept ACK from jeanpablojp, who reviewed and suggested test improvements that were addressed, with an open minor inquiry from maflcko. Review is ready and the patch is small and self-contained.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T15:58, confidence high, input hash e1e5c0500cb812d1