RPC getblockstats first argument inconsistency #15412

issue jonasschnelli openend this issue on February 15, 2019
  1. jonasschnelli commented at 8:57 am on February 15, 2019: contributor

    Maybe I’m wrong, but it looks like that the handling of the height/hash union for getblockstats first argument seems inconsistent or wrong.

    bitcoin-cli getblockstats 10000 #c5f015 works bitcoin-cli getblockstats '"<hash>"' #c5f015 works bitcoin-cli getblockstats <hash> #f03c15 gives “Error parsing JSON”

    Ignoring that a '"<hash>"' (simple string) is probably not a valid json text, it seems to be inconsistent with other calls like getblock <hash>

  2. jonasschnelli added the label RPC/REST/ZMQ on Feb 15, 2019
  3. jonasschnelli added the label good first issue on Feb 15, 2019
  4. IlyasRidhuan commented at 9:14 am on February 16, 2019: none

    It looks like the error is because the first input param to getblockstats get passed to ParseNonRFCJSONValue regardless if its a string (which shouldn’t happen since that is valid in RFC4627 spec). This is also why the '"<hash>"' works, because it is considered invalid.

    The issue lies in the check in client.cpp always returning true when searching vRPCConvertParams. AFAIK this table is only used by bitcoin-cli and the GUI debug console

    I can think of solution whereby the call is changed from getblockstats <hash/height> to getblockstats <hash> <height> where height is the overriding input. However, that seems to be overkill since it’s specifically a problem when calling via bitcoin-cli and the GUI debug console but would break backward compatibility.

    Happy to get some help in thinking of a better answer , but perhaps better parsing of the args is a preferred solution?

  5. sipa commented at 9:41 am on February 16, 2019: member

    There is no solution to this. bitcoin-cli parses some arguments as JSON, and some as strings. As a numeric argument is permitted, it has to be JSON here. That also implies that if you want to pass a string, you need to write it as a JSON string. To make what you’re asking for work, bitcoin-cli would need to somehow recognize that specifically for getblockstats if the argument looks like a hash, it is in fact a string and not JSON.

    It’s probably better to have a separate getblockstatsbyhash RPC.

  6. fanquake renamed this:
    RPC getblockstats first argument inconstancy
    RPC getblockstats first argument inconsistency
    on Feb 16, 2019
  7. maflcko added the label Brainstorming on Feb 16, 2019
  8. ryanofsky commented at 2:58 pm on February 19, 2019: contributor
    @sipa do you think there would be a big downside if bitcoin-cli just stopped throwing “Error parsing JSON” errors and instead passed any argument that didn’t parse as JSON as a literal string?
  9. jonasschnelli commented at 6:00 am on February 20, 2019: contributor
    Can’t we just threat the argument as non-json string (no conversion) and parse the number/hash in the getblockstats call code?
  10. ryanofsky commented at 11:27 am on February 20, 2019: contributor

    Can’t we just threat the argument as non-json string (no conversion) and parse the number/hash in the getblockstats call code?

    Yes, but this seems like an inferior solution. My suggestion which would simplify bitcoin-cli logic (just eliminating the exception on UniValue::read failure), where this would complicate the server side logic. Also, my suggestion could be general and work for any argument, where this require new code to be written for individual arguments.

    Also, you didn’t say what heuristic you would use to distinguish hash strings from height strings like "10000". Maybe it is just checking string length. But any heuristic you wanted to use server side wouldn’t be as good as the one I was suggesting client-side, because the server doesn’t know the context of the call, so will make things jankier for clients other than bitcoin-cli. For example, if you’re using python client right now, numbers are always treated as heights, strings are always treated as hashes. But with a server side check, some python strings would have to start being treated as heights and result in weird errors or return values.

  11. maflcko commented at 2:17 pm on February 20, 2019: member
    Now that exactly one type has to be specified in the help via RPCArg, this is hopefully the only inconsistency we will ever see. @ryanofsky Mind to create a pull, so we can test this?
  12. ryanofsky commented at 3:19 pm on February 20, 2019: contributor

    @ryanofsky Mind to create a pull, so we can test this?

    Created #15448. This would also allow removing the ParseNonRFCJSONValue function.

  13. maflcko referenced this in commit 5e5dd9918e on Apr 20, 2020
  14. maflcko removed the label good first issue on May 22, 2020
  15. PastaPastaPasta referenced this in commit 7f631dbb14 on Dec 22, 2021
  16. PastaPastaPasta referenced this in commit ce24ca5794 on Dec 22, 2021
  17. PastaPastaPasta referenced this in commit c65f526ac1 on Dec 22, 2021
  18. PastaPastaPasta referenced this in commit affb7a472f on Dec 28, 2021
  19. pinheadmz commented at 2:28 pm on April 27, 2023: member
    This issue is unlikely to be fixed in Bitcoin Core. We’ll close for now, but feel free to open another issue or pull request with a fix.
  20. pinheadmz closed this on Apr 27, 2023

  21. gades referenced this in commit f3141b7980 on Dec 1, 2023
  22. gades referenced this in commit a5ef01c8ef on Dec 9, 2023
  23. bitcoin locked this on Apr 26, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-01 10:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me