-
Notifications
You must be signed in to change notification settings - Fork 36.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli/gui: support "@height" in place of blockhash for getblock on client side #16439
Conversation
This is an alternate approach to #16345 . It may solve #15412 and remove the desire to drop client-side arg validation per #15448 . Previous discussion (as pointed out in 16345) is in #16317, #14858 and #8457. There's a bunch of other ways of doing this:
This way isn't much code, particularly for supporting more generally, and while having to turn the number into a string is a bit annoying in code, it's not that bad, and very easy from the command line or the GUI. So up for consideration (edited to add json pipelining suggestion) |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
I still don't like overloading the meaning of the parameter, but I'll stop repeating myself … (also theoretically this could mess with software that assumes that only valid block hashes would be accepted by the RPC, though passing unchecked user input directly to RPC is arguably a bad idea…) |
So leave things as-is including the exception for |
@ajtowns do you see advantages of these approaches beside being faster to write or slightly fast execution (compared to also calling If this goes forward, wouldn't it be better to prefix with |
It's a fair bit less complexity for the person asking for something -- you don't have to cut and paste a blockhash, or have a
Did think about that, but
Using a non-hex prefix makes it pretty unambiguous you don't mean a block hash. At least in theory you could have a block with hash |
Weak concept ACK. I understand @laanwj's point of view: ideally, the RPC server code implements simple unambiguous primitive operations, and complexity of how to make them interact is offloaded to the client. In places where user friendliness for CLI users conflicts with that, it can be implemented as extra functionality in On the other hand, this approach seems actually simpler in total code complexity than having various hooks in Perhaps an analogy is |
Concept ACK. I didn't follow previous discussions, but I like the @ syntax, think it is simpler and more convenient than the other duplicating / aliasing / pipelining suggestions, and don't see a real potential for misuse. (Apologies if I missed any other practical objections in previous discussion, they mostly seemed like aesthetic complaints.) |
src/rpc/blockchain.cpp
Outdated
@@ -820,7 +843,7 @@ static UniValue getblock(const JSONRPCRequest& request) | |||
RPCHelpMan{"getblock", | |||
"\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n" | |||
"If verbosity is 1, returns an Object with information about block <hash>.\n" | |||
"If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n", | |||
"If verbosity is 2, returns an Object with information about block <hash> and information about each transaction.\n", | |||
{ | |||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STR_HEX
no longer applies and this should be a new type, similar to AMOUNT
Weak concept ACK, for exactly the same reasons that sipa gives here: #16439 (comment) |
I could live with that concept,... though I still think it's client functionality. What if the client (bitcoin-cli) does an extra call for For a I think it's worth to extent |
Thanks… you're formulating it better than me To be clear: it's not that I dislike the syntax. I'm not NACKing this. I think this would be useful from the command line. But I think doing this on the server side is the wrong way to go. I think this is the wrong direction. Please also look at it from the perspective of someone writing a RPC wrapper in a static language, say, rust. After this change, the parameter needs to be an |
One problem with this is that the height can refer to a different block in a sequence of calls: foo @height
# a wild reorg
bar @height
# bar operates on a different block than foo |
Isn't that to be expected and not particularly surprising? You get the same behaviour now if you call
I think you'd have to define a new table "convert height to blockhash params" in rpc/client.cpp as otherwise you'd do weird things like convert a wallet label from "@123" into a block 123's hash. That in turn means you have to keep your client in sync with the server, more than you would if it was just parsed on the server. I've added in a quick hack to bitcoin-cli to support
Note this is already the case for Are there any other shortcuts like this that seem useful? git comparisons like "foo^" for a parent or ancestor don't seem like they'd be that useful for blocks if you're already able to query by height easily, and short-references (ie, just specifying 8 digits if that's enough to reference a unique id) don't seem better than the height, and aren't convenient when the first digits are all zero... |
It doesn't have to be an enum, it can also be a plain blockhash (hex string) and not support the user-facing |
No, you would call |
re: #16439 (comment)
Could someone expand on this more? I don't understand this comment, and don't understand in general why people seem to like the idea of moving logic from the server to the client. Can someone be specific about an actual advantage that would come from moving logic from server to client, or be clear about what types of logic should be moved? Should every type of logic that it's possible to move be moved, or is there a different criteria for deciding what belongs in If I'm writing a rust client or any other type of client, it would seem like the more logic there is in Putting more logic in Putting more logic in
re: #16439 (comment)
This seems like an argument not only for requiring hashes server side, but also for requiring hashes client side, and against both this PR and #16345. I don't have much opinion on it, but just wanted to be clear about the implications. Maybe it would be a big inconvenience, or maybe it would prevent mistakes by users who forget about the possibilities of reorgs. |
|
User should be assumed to know what a reorg is or be educated about them in the rpc help text, imo. |
The point is that use of the interface will usually be automatic/programmatic. Manual use (though a cli, in whatever programming language) is only a small subset of uses of the RPC interface. Features that are only useful for manual use (such as this one) should go into the client. Every programmatic use can just as easily call It seems it needs to be said often enough: the RPC interface does not exist for bitcoin-cli, or for end users. It's an API for applications to use bitcoin core. If you want to make things friendlier for end-users, the place to do so is not usually the server side. |
Concept NACK. The RPC interface is for software, not human interaction. The decision to not support heights in places of hashes was intentional. |
Concept ACK. This seems like a nice convenience that doesn't introduce any ambiguity or much complexity. |
Honestly I don't understand what is so inconvenient. Here's some more problems/inconsistencies:
Some (at least Also, consider this: bitcoin/test/functional/rpc_blockchain.py Lines 143 to 146 in 7821821
You would have to call getblockhash anyway otherwise you wouldn't be able to call reconsiderblock .
|
Would be nice if the gui supported this, even when it is not added to bitcoind |
@MarcoFalke GUI console supports |
Restating my Concept ACK here. I prefer the I've skimmed the code and it looks good. Will fully review once commits are cleaned up and this is no longer a draft. |
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK cc7078e per git range-diff 218fe60 674f961 cc7078e
, rebase only
See also #20273.
|
I think #20273 is better solution for a problem, server code should not be complicated if that can be avoided, so Concept NACK. |
@kristapsk This doesn't touch server code... |
cc7078e
to
4a8a294
Compare
Rebased on top of #20012 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested re-ACK 4a8a294
std::vector<std::string> args{stack.back().begin() + 1, stack.back().end()}; | ||
|
||
// Convert block heights "@123" or "@best" to block hash when appropriate | ||
for (size_t i = 0; i < args.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (size_t i = 0; i < args.size(); i++) { | |
for (size_t i = 0; i < args.size(); ++i) { |
Bumped to add new rpcs... |
ACK, modulo may as well squash the new commit into the first one. I reread the discussion at the top to reswap the context into memory and agree this is better on the client side for the reasons stated in #16439 (comment).
Since it needs to be documented somewhere, maybe add a reusable line to the RPC helps mentioning that it's a client-side shortcut. Human users consume these helps for CLI use in addition to for writing client-side software. |
This isn't seeing any progress so closing. |
Update bitcoin-cli and gui debug console so that RPC calls that accept a block hash to reference a block will also accept a block by height prefixed by
@
, or@best
to reference the tip. The clients will just make an RPC call togetblockhash
orgetbestblockhash
to replace the argument with the hash before making the requested RPC call.Affected RPCs:
The RPC calls waitforblock, and reconsiderblock are unaffected because specifying a blockhash already in the main chain for those calls is not useful, and getblockstats is unaffected because it already accepts a height.