mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
WIP: rpc: Stamp getblock OpenRPC result discriminator #36175
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36175
Loading…
Reference in a new issue
No description provided.
Delete branch "openrpc-discriminated-result"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
OpenRPC documents
getblockas a four-wayoneOfonverbosity, but the dump does not say which integer selects which arm. Therefore, clients that expose a type or method per verbosity (e.g. corepc, btcd) have to hardcode that map.This patch adds optional
RPCResultDiscriminatormetadata, emits it asx-bitcoin-discriminated-result, and stampsgetblock.getblockrequest handling and returned block data are unchanged. Now,help getblocknotes that verbosity 2 and 3 cannot be told apart by validating a response alone.Also updates
getopenrpcinfoschema text to documentx-bitcoin-discriminated-resultandx-bitcoin-default-hint.The change to the schema's format is:
x-bitcoin-discriminated-resultongetblockgetblockdescription notes verbosity 2 and 3 overlapschema text for
x-bitcoin-default-hintandx-bitcoin-discriminated-resultOther results can also use the same discriminator pattern.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Concept ACK
One thing I could not settle by reading. The test asserts the discriminator's literals rather than the two relations behind them. Inserting an argument before
verbosityingetblockleavesparameterIndex1 addressing the new argument, and swapping the verbosity 2 and 3 arms points value 2 at the arm withprevout. rpc_openrpc.py passes on both builds, and none of the three newCHECK_NONFATALs looks at either relation. Worth pinning them? Comparinggetblock["params"][discriminator["parameterIndex"]]["name"]todiscriminator["parameter"], and asserting the two object arms differ inprevoutin the ordervaluesclaims, fails on both and passes on this head.Worth putting in the description? Validating cannot pick the arm either, because a block with no spends comes back byte identical at verbosity 2 and 3, since a coinbase input has no
prevoutto add, and arm 3 listsprevoutwithout requiring it, so both arms accept both responses and theoneOfdoes not resolve. That answers the reviewer who asks why a consumer cannot just validate, which the current wording leaves open. Already true on the base.The
schemafield inOpenRPCDocResultalready explainsx-bitcoin-unitto whoever reads the help. Worth a line forx-bitcoin-discriminatedResulttoo? The parameter-sideschemafield next to it has the same gap forx-bitcoin-default-hint, if you would rather cover both at once.nit: the other
x-bitcoin-keys in the document are all lowercase and hyphenated, sox-bitcoin-discriminated-resultwould match.The only constructor takes
std::vector<int>, thoughvaluesis already astd::vector<UniValue>. Of the fifteen methods with aoneOfresult today, onlygetrawtransactionis another integer case and six more turn on a boolean or a string, soUniValuewould cover eight instead of two. The other seven need a different shape rather than a wider type, so eight is the ceiling for this shape. Is the integer form deliberate for a first pass? I tried it, and astd::vector<UniValue>overload sits beside theintone, withgetblockheaderemitting"values": [true, false]andgetblockunchanged.nit:
param_name,param_indexandvaluescould carry them_prefix and the const thatRPCResultsandRPCResultnext door use.Done.
Done.
Yes, the integer form was done deliberately on this first pass. Would prefer to add overloads in specific commits that use them.
Nits done.
Good catch, thanks! I've updated the tests according to your suggestion
Rebased off master
What is this cast for?
I've removed the cast. I had initially used it to get around an error that I can no longer reproduce
Updates:
ACK
85f2993079RPCResultDiscriminatorseems like a fair concept to use here.I tried to think of other ways to implement, such as attaching each verbosity value directly to its
RPCResultarm, which would remove the parallel ordering betweenvaluesandoneOf, but it would be overkill for the one current use IMO.Base:
a773e1e33b349dc819b5a0edc1c7a4839dc73b48Head:
85f29930790aee2bd4477df730b74fe11e91ebe9Findings
Suggestions
Describe the discriminator as selecting on one parameter (src/rpc/server.cpp:564, head)
The description says the extension can name a request parameter “or parameters,” but
RPCResultDiscriminatorstores one parameter name and index, and the emitter writes scalarparameterandparameterIndexfields. Consumers therefore have no defined encoding for a multi-parameter selector. Narrow the description to one parameter or define and emit a multi-parameter form before advertising it.Full review report
Same, I find it a bit ugly that we can't discriminate all results. The reason is due to legacy code such as:
Which leads to issues such as https://github.com/bitcoin/bitcoin/issues/18476.
I don't think this will be fixed any time soon, or ever, so maybe a dedicated
RPCResult{Undiscriminated{"text"}, ...could be introduced. This way, the docs and the schema could be derived from the same ground truth.I am asking because clients would either care to have all of them discriminated, or none? What is so special about
getblock?Also, while reviewing I found a likely unrelated bug:
"mempool chunks" is not a discriminator, but should be the description of the array?
This sounds reasonable. I can work on this once I get some more time, or happy to review a PR by someone else.
I had planned to go one by one for the RPCs that are selected by a request parameter.
getblockseems to be a more commonly used and complex RPC, so I figured it was the best one to start with.Good catch. I will open a PR for a fix, unless someone else does before me.
@nervana21 do you still plan on opening this?
Yes, PR opened. Thanks for the reminder
Maybe turn into draft for now?
Done!