Skip to content

abci_query path parameter interpretation does not match documentation #666

Closed

Description

@gibson042

(cloning tendermint/tendermint#10020)

Bug Report

Setup

CometBFT version (use cometbft version or git rev-parse --verify HEAD if installed from source): Tendermint 0.34.23

Have you tried the latest version: no

ABCI app (name for built-in, URL for self-written if it's publicly available): https://main.rpc.agoric.net/

What happened?

A GET /abci_query request with path query parameter as documented at https://docs.cometbft.com/v0.37/rpc/#/ABCI/abci_query (i.e., starting with "/") is rejected:

$ curl -sS 'https://main.rpc.agoric.net/abci_query?path=/custom/vstorage/data/activityhash'
{
  "jsonrpc": "2.0",
  "id": -1,
  "error": {
    "code": -32602,
    "message": "Invalid params",
    "data": "error converting http params to arguments: invalid character '/' looking for beginning of value"
  }
}

Wrapping that path in double quote characters (as at https://github.com/cometbft/cometbft/blob/main/spec/rpc/README.md#abciquery but without the unexpected =IHAVENOIDEA) works:

$ curl -sS 'https://main.rpc.agoric.net/abci_query?path="/custom/vstorage/data/activityhash"'
{
  "jsonrpc": "2.0",
  "id": -1,
  "result": {
    "response": {
      "code": 0,
      "log": "",
      "info": "",
      "index": "0",
      "key": null,
      "value": "ewogICJ2YWx1ZSI6ICIyYTk5YmU3NTIwNTk0MTg5MjlkODExYTA0ZGVlYTE4YjM3NGI3M2IxNTA3Y2ZkMjY2NTYwYzVlYWIwMWViOTk4Igp9",
      "proofOps": null,
      "height": "9225800",
      "codespace": ""
    }
  }
}

So does submitting the entire request as POSTed JSON-RPC:

$ curl -sS https://main.rpc.agoric.net --request POST --header 'Content-Type: application/json' --data \
  '{ "jsonrpc": "2.0", "id": -1, "method": "abci_query", "params": { "path": "/custom/vstorage/data/activityhash" } }'
{
  "jsonrpc": "2.0",
  "id": -1,
  "result": {
    "response": {
      "code": 0,
      "log": "",
      "info": "",
      "index": "0",
      "key": null,
      "value": "ewogICJ2YWx1ZSI6ICI2MDMzMDJmZmFlNTVjYmFmYjFiZWE2ZTZmM2E4Y2IxZWU0NGI3ZDBkZGFlYjUzZmE5OTkxMDFiMzcxMzJlOGY3Igp9",
      "proofOps": null,
      "height": "9225809",
      "codespace": ""
    }
  }
}

What did you expect to happen?

I expected the unquoted path URL query parameter value to be accepted as documented at https://docs.tendermint.com/v0.34/rpc/#/ABCI/abci_query , rather than rejected for not being JSON.

How to reproduce it

See above.

Logs

n/a

dump_consensus_state output

n/a

Anything else we need to know

The culprit is likely httpParamsToArgs, which has not changed since tendermint/tendermint#4968 was merged in 2020.

Activity

  1. added
    bug
    needs-triage
    on Apr 7, 2023
  2. adizere commented on Apr 27, 2023

    @adizere
    Contributor

    Thanks Richard @gibson042 for filing this, great catch! Seems also relatively easy to fix, though it needs a bit more investigation to find the root cause (likely in a method called from the one you mentioned httpParamsToArgs).

  3. added
    good first issue
    and removed
    needs-triage
    on Apr 27, 2023
  4. stevenferrer commented on May 21, 2023

    @stevenferrer
    Contributor

    Hi @adizere and @gibson042,

    As per my investigation, the handling of path argument is handled by this line where jsonStringToArg tries to parse the path value as a JSON.

    As I understand, the path should be handled by nonJSONStringToArg in this line since it's an unquoted string. I submitted a PR #864 to try and fix it, please lemme know your thoughts, thanks!

  5. stevenferrer commented on May 22, 2023

    @stevenferrer
    Contributor

    It seems one test failed because it expects that unquoted strings should error. Just wondering if this assumption still holds true? If not, then maybe we can safely update the test to not expect an error, thoughts?

  6. self-assigned this
    on Jun 16, 2023
  7. sergio-mena commented on Jun 16, 2023

    @sergio-mena
    Collaborator

    Taking a look at the backlog for this

  8. gibson042 commented on Jun 18, 2023

    @gibson042
    ContributorAuthor

    Looking at Using CometBFT: Formatting, this appears to be intentional (at least for transactions). If so, the issue could be resolved by updating documentation to clarify—the URLs would be unfortunately ugly, but at least the interface would be clear.

  9. sergio-mena commented on Jun 22, 2023

    @sergio-mena
    Collaborator

    Analysis

    I took a look at the way different types are handled or over our RPC. This is what I found out:

    • In v0.34.x, string-like parameters can be (internally) defined as two types: string and []byte
    • These are the types taken by (exhaustive list of our RPC endpoints taking string-like params)
      • abci_query: path is string, data is []byte
      • broadcast_tx_*: tx is []byte
      • block_by_hash: hash is []byte
      • check_tx: tx is []byte
      • tx: hash is []byte
      • tx_search: query is string, order_by is string
      • block_search: query is string, order_by is string

    So, as you can see, parameters query and order_by in endpoints tx_search and block_search are the only endpoints comparable to parameter path in abci_query (in that they are internally typed string).

    Testing

    This is how these three commands behave when double quotes are not used (they all fail). The behavior is consistent.

    localhost % curl -s 'http://localhost:5701/abci_query?path=/a/path' | jq
    
    {
      "jsonrpc": "2.0",
      "id": -1,
      "error": {
        "code": -32602,
        "message": "Invalid params",
        "data": "error converting http params to arguments: invalid character '/' looking for beginning of value"
      }
    }
    localhost % curl -s 'http://localhost:5701/block_search?query=block.height>10000' | jq
    {
      "jsonrpc": "2.0",
      "id": -1,
      "error": {
        "code": -32602,
        "message": "Invalid params",
        "data": "error converting http params to arguments: invalid character 'b' looking for beginning of value"
      }
    }
    localhost % curl -s 'http://localhost:5701/tx_search?query=tx.height>10000' | jq
    {
      "jsonrpc": "2.0",
      "id": -1,
      "error": {
        "code": -32602,
        "message": "Invalid params",
        "data": "error converting http params to arguments: invalid character 'x' in literal true (expecting 'r')"
      }
    }
    

    And this is how the commands behave when double quotes are used. The behavior is also consistent.

    localhost % curl -s 'http://localhost:5701/abci_query?path="/a/path"' | jq
    {
      "jsonrpc": "2.0",
      "id": -1,
      "result": {
        "response": {
          "code": 0,
          "log": "",
          "info": "",
          "index": "0",
          "key": null,
          "value": "",
          "proofOps": null,
          "height": "636",
          "codespace": ""
        }
      }
    }
    localhost % curl -s 'http://localhost:5701/block_search?query="block.height>10000"' | jq
    {
      "jsonrpc": "2.0",
      "id": -1,
      "result": {
        "blocks": [],
        "total_count": "0"
      }
    }
    localhost % curl -s 'http://localhost:5701/tx_search?query="tx.height>10000"' | jq
    {
      "jsonrpc": "2.0",
      "id": -1,
      "result": {
        "txs": [],
        "total_count": "0"
      }
    }
    localhost %
    

    Conclusion

    The behavior reported in this issue is the expected one. We can therefore confirm this is a documentation issue.

  10. added
    documentation
    on Jun 22, 2023
  11. removed
    bug
    on Jun 22, 2023
  12. stevenferrer commented on Jun 22, 2023

    @stevenferrer
    Contributor

    Hi @sergio-mena, thanks for the detailed analysis. I submitted PR #1015 to update the rpc/openapi spec to add double quotes to path param. Please let me know if there are other places that needs to be updated, thanks!

  13. sergio-mena commented on Jun 22, 2023

    @sergio-mena
    Collaborator

    Thanks a lot @stevenferrer, for filing #1015. We will take it from there. We will check all over ours docs, to make sure any example for one of those endpoints contains the double quotes

  14. alijnmerchant21 commented on Jun 23, 2023

    @alijnmerchant21
    Contributor

    Thanks - @stevenferrer for filing PR #1015. I have made some changes, reflected in the commit.
    Also made a PR #1020 to reflect changes on 0.34

  15. added 4 commits that reference this issue on Jun 28, 2023
    f6f13b1
    f96fa11
    9446f36
    a0c0c2e
  16. added 3 commits that reference this issue on Jun 28, 2023
    b60b805
    b9914a7
    dde9946
  17. added a commit that references this issue on Sep 18, 2023
    481c4c6
  18. added a commit that references this issue on Jan 16, 2024
    9cd2fac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

documentationgood first issuerpc

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions