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
Closes #2186. RPC getblock now accepts height or hash. #2187
Conversation
27ea5f0
to
83f2540
Compare
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.
Spacing nit, and a suggested extension (could go either in this or another PR).
src/rpcblockchain.cpp
Outdated
} | ||
catch (const std::exception &e) { | ||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter"); | ||
} |
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.
Inconsistent indentation.
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.
Indentation fixed via force push
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.
I still see an indentation problem - lines 416-419 start with a tab instead of eight spaces.
"\nArguments:\n" | ||
"1. \"hash\" (string, required) The block hash\n" | ||
"1. \"hash|height\" (string, required) The block hash or height\n" |
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.
It might be useful to also allow a height relative to the chain tip. Maybe tip-<num>
, if there isn't already a syntax for this in another RPC call.
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.
Filed #2197
Note that this is a specific deviation from Bitcoin Core's RPC policy, which is to have each RPC call perform some unique atomic process (hence I'm not suggesting this PR is a bad idea; I'm just pointing out that we should be aware of the direction we are taking the RPC by doing so. Multiplexing in this way also means that the height must be represented as a JSON string rather than a JSON integer, which may affect some use cases (see e.g. #2052 where the boolean field is now a string, and in Python must be handled as such). |
Well, the RPC is still atomic i.e. retrieving a block from storage. The only thing that has changed here is the key format being used to find a block. Btw, I'm not sure sure if upstream has a strict policy about this, otherwise I agree that having to convert from string to int requires a bit of extra legwork. The benefits though are improved usability for end users and reduction of network traffic and load on the server - one rpc call instead of two. |
83f2540
to
a88bcc6
Compare
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.
utACK pending resolution of comments.
src/rpcblockchain.cpp
Outdated
} | ||
catch (const std::exception &e) { | ||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter"); | ||
} |
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.
I still see an indentation problem - lines 416-419 start with a tab instead of eight spaces.
src/rpcblockchain.cpp
Outdated
} | ||
|
||
if (nHeight < 0 || nHeight > chainActive.Height()) { | ||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); |
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.
Tab instead of spaces.
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.
Fixed vim gremlins.
src/rpcblockchain.cpp
Outdated
); | ||
|
||
LOCK(cs_main); | ||
|
||
std::string strHash = params[0].get_str(); | ||
|
||
// If height is supplied, find the hash | ||
if (strHash.size() < 64) { |
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.
Non-blocking: is there a constant somewhere we can reference here instead of a hard-coded length? Or is there a precedent in the codebase for assuming txid hashes are 64 chars long? It looks like uint256S()
reads up to 64 characters from the end of the given string, so I guess it's fair enough to specify 64 here given we directly reference uint256
shortly after.
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.
Done, now references uint256.
a88bcc6
to
7d3b152
Compare
@str4d Comments addressed. Please update to green tick. |
@zkbot r+ |
📌 Commit 7d3b152 has been approved by |
Closes #2186. RPC getblock now accepts height or hash.
☀️ Test successful - zcash |
No description provided.