-
Notifications
You must be signed in to change notification settings - Fork 38.7k
rpc: Disallow gettxoutsetinfo queries for a specific block with use_index=false
#25471
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
Conversation
|
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. |
shaavan
left a comment
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.
Concept ACK
- I agree with allowing displaying an RPC error instead of an Internal bug error because:
- AFAIK. This will enable the incorrect command to fail faster
- This will allow users to understand better the problem's cause and how to solve it.
Now, as for the alternative that you suggested:
An alternative way would be to allow the interaction if the specified hash_or_height happens to correspond to the tip...
I want to explain why I think it is better not to switch to the alternative.
- This will potentially increase the code complexity.
- Running the command
bitcoin-cli -namedgettxoutsetinfohash_type='muhash' use_index='false'prints the info for the current best block. So technically, the alternative is not needed. - Since it is explicitly mentioned in the
gettxoutsetinfohelp message, thehash_or_heightoption is available only with the coinstatsindex. So ideally, it shouldn't be allowed to provide hash_or_height value withuse_index=0.
Arguments:
1. hash_type (string, optional, default="hash_serialized_2") Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'muhash', 'none'.
2. hash_or_height (string or numeric, optional) The block hash or height of the target height (only available with coinstatsindex).
3. use_index (boolean, optional, default=true) Use coinstatsindex, if available.
However, not using the alternative makes the gettxoutsetinfo command quite verbose, as there is no way to make use_index = false without using the --named option.
Screenshot:
So I would suggest reordering the arguments of this RPC to
1. `hash_type`
2. `use_index`
3. `hash_or_height`
Because, first, it would eliminate the need to use --named for specific cases, and second, this makes the ordering of argument logically sounder.
And I would also suggest mentioning in the description of hash_or_height, that not using this command would print info for the best block.
|
Thanks for the review!
That would be nice, but it would break compatibility with older versions, which I think should really be avoided unless absolutely necessary. For other RPCs, we sometimes even keep dysfunctional dummy-arguments around to avoid this. (
I'll do this with my next push! |
|
I tried to produce the same error and have difficulty with it. |
You need to start bitcoind with the coinstatsindex to reproduce this, e.g. Doing the same locally with -regtest instead of -signet works too, but then you need to mine a couple of blocks yourself ( |
…ndex=false by returning an RPC error where previously a NonFatalError would be thrown.
2e9c043 to
27c8056
Compare
shaavan
left a comment
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.
ACK 27c8056
Changes since my last review:
- The help message for the default behavior of the
hash_or_heightargument has been added.
I was able to successfully run the ./bitcoin-cli -signet help gettxoutsetinfo command, and verify the help message has been displayed correctly.
|
utACK 27c8056 |
|
Concept ACK for fixing the internal error that's exposed to RPC In the longer term, I'd like to see |
…ific block with `use_index=false` 27c8056 rpc: Disallow gettxoutsetinfo queries for a specific block with use_index=false (Martin Zumsande) Pull request description: In the `gettxoutsetinfo` RPC, if we set `use_index` to false but specify `hash_or_height`, we currently hit a nonfatal error, e.g. `gettxoutsetinfo "muhash" "1" "false"` results in: ``` Internal bug detected: "!pindex || pindex->GetBlockHash() == view->GetBestBlock()" rpc/blockchain.cpp:836 (GetUTXOStats) ``` The failing check was added in [bitcoin#24410](bitcoin@664a14b), but the previous behavior, returning the specified height together with data corresponding to the tip's height, was very confusing too in my opinion. Fix this by disallowing the interaction of `use_index=false` and `hash_or_height` and add a RPC help example with `-named` because users might ask themselves how to use the `use_index` flag witout hitting an error. An alternative way would be to allow the interaction if the specified `hash_or_height` happens to correspond to the tip (which should then also be applied to the `HASH_SERIALIZED` check before). If reviewers would prefer that, please say so. ACKs for top commit: fjahr: utACK 27c8056 shaavan: ACK 27c8056 Tree-SHA512: 1d81c34eaa48c86134a2cf7193246d5de6bfd819d413c3b3fae9cb9290e0297a336111eeaecede2f0f020b0f9a181d240de0da4493e1b387fe63b8189154442b


In the
gettxoutsetinfoRPC, if we setuse_indexto false but specifyhash_or_height, we currently hit a nonfatal error, e.g.gettxoutsetinfo "muhash" "1" "false"results in:The failing check was added in #24410, but the previous behavior, returning the specified height together with data corresponding to the tip's height, was very confusing too in my opinion.
Fix this by disallowing the interaction of
use_index=falseandhash_or_heightand add a RPC help example with-namedbecause users might ask themselves how to use theuse_indexflag witout hitting an error.An alternative way would be to allow the interaction if the specified
hash_or_heighthappens to correspond to the tip (which should then also be applied to theHASH_SERIALIZEDcheck before). If reviewers would prefer that, please say so.