Skip to content

parsing bug with abci_query data #1505

Closed as not planned
Closed as not planned

Description

@xloem

Bug Report

abci_query on gaiad is raising a marshaling error for me, and requiring the serialized request object to be passed raw rather than hex or base64 encoded.

11:51AM DBG HTTP HANDLER module=rpc-server req="marshaling error: json: unsupported type: func() (io.ReadCloser, error)"                                                                           
11:51AM DBG HTTPRestRPC args=[{},{},{},{},{}] method=/abci_query module=rpc-server returns=[{},{}]                                                                                                 
11:51AM DBG served RPC HTTP response duration=0 method=GET module=rpc-server remoteAddr=127.0.0.1:51840 status=200 url={"ForceQuery":false,"Fragment":"","Host":"","OmitHost":false,"Opaque":"","Path":"/abci_query","RawFragment":"","RawPath":"","RawQuery":"path=%22%2Fcosmos.auth.v1beta1.Query%2FModuleAccountByName%22\u0026data=%22%5Cn%5Crfee_collector%22\u0026height=null","Scheme":"","User":null}                                                                                                                                                                                            

Setup

CometBFT version (use cometbft version or git rev-parse --verify HEAD if installed from source):
v0.34.29
Have you tried the latest version: yes/no
i don't think so (although I might have); i tried a few versions and repositories, but have been focusing on gaiad which i am trying to troubleshoot interactions with. i haven't found any mention of this issue online, and it extends back to before gaia 4 (now at 13).
ABCI app (name for built-in, URL for self-written if it's publicly available):
This is the abci_query path to rpc server handling raw grpc request objects. The above test uses cosmos.auth.v1beta1.Query/ModuleAccountByName .

Environment:

  • OS (e.g. from /etc/os-release): Red Hat Linux 7
  • Install tools: Built gaia v13 and other versions from git.
  • Others:

node command runtime flags: nothing special, gaiad start --log_level trace --home ~/src/gaia/mytestnet/node0/gaiad

Config

What happened?

When I pass nonempty request objects to /abci_query , I get an error in the log, and I only get success if I encode their bytes to a raw json string in the data field. This makes it difficult to pass the binary request objects, as it relies on string encoding in the client.

What did you expect to happen?

There shouldn't be an error in the log. Ideally the endpoint would accept hex-encoded or base64-encoded data.

How to reproduce it

 gaiad testnet --keyring-backend test --v 1 --starting-ip-address 127.0.0.1
 gaiad start --log_level trace --home mytestnet/node0/gaiad
curl -v 'http://127.0.0.1:26657/abci_query?path=%22%2Fcosmos.auth.v1beta1.Query%2FModuleAccountByName%22&data=%22%5Cn%5Crfee_collector%22'

Logs

11:51AM DBG HTTP HANDLER module=rpc-server req="marshaling error: json: unsupported type: func() (io.ReadCloser, error)"                                                                           
11:51AM DBG HTTPRestRPC args=[{},{},{},{},{}] method=/abci_query module=rpc-server returns=[{},{}]                                                                                                 
11:51AM DBG served RPC HTTP response duration=0 method=GET module=rpc-server remoteAddr=127.0.0.1:51840 status=200 url={"ForceQuery":false,"Fragment":"","Host":"","OmitHost":false,"Opaque":"","Path":"/abci_query","RawFragment":"","RawPath":"","RawQuery":"path=%22%2Fcosmos.auth.v1beta1.Query%2FModuleAccountByName%22\u0026data=%22%5Cn%5Crfee_collector%22\u0026height=null","Scheme":"","User":null}                                                                                                                                                                                            

dump_consensus_state output

This happens on a virgin testnet.

Anything else we need to know

It seems there are possibly a handful of bugs here that I haven't fully explained:

  • there is an error in the debug log (topic of this issue)
  • the data parameter is not accepted when hex encoded / the error message expresses hex encoding when the wrong type is passed
  • request objects are rejected as malformed when the binary can't be encoded as UTF-8 (this can often be avoided but quickly happens with pagination keys)

I imagining correctly supporting hex or base64 encoding rather than requiring a raw encoding would resolve this. Falling back to a raw encoding if the data is not encoded correctly might provide for backward compatibility.

As a user resolving the question of how to pass pagination keys to gaia rpc is unanswered.

Activity

  1. added
    bug
    needs-triage
    on Oct 16, 2023
  2. andynog commented on Oct 17, 2023

    @andynog
    Contributor

    Hi @xloem, could it be related to this ? Based on the version you're using
    #443

  3. removed
    needs-triage
    on Oct 17, 2023
  4. self-assigned this
    on Oct 17, 2023
  5. moved this from Todo to In Progress in CometBFT 2023on Oct 17, 2023
  6. moved this from In Progress to Todo in CometBFT 2023on Oct 17, 2023
  7. xloem commented on Oct 25, 2023

    @xloem
    Author

    This isn't quite the same thing as the linked issue, as the endpoint differs and it works for me only if data can be passed unencoded rather than hex or base64, but it does involve the same material of normalizing the binary encodings across endpoints.
    [EDIT: I did look at this a little, but I am new to go and haven't yet found where in the source the abci_query parameters are decoded from json.]

  8. added
    abci
    on Oct 31, 2023
  9. moved this from Todo to In Progress in CometBFT 2023on Oct 31, 2023
  10. xloem commented on Nov 12, 2023

    @xloem
    Author

    It seems one can mostly work around this by ensuring all int field values of request objects are either below 0x80 or above 0x4041 . It seems varint values in the range 0x80-0x4041 do not survive UTF-8 coding. This mostly works but it does become hard to request pages for anything beyond the first 127 items. Additionally strings are limited to 127 bytes length. I've also run into issues specifying blockheights that I haven't looked into, but these can be specified on the RPC side.

  11. mmsqe commented on May 10, 2024

    @mmsqe
    Contributor

    @xloem have you try hex encode the marshalled request? or you can try base64 encoded fee_collector from cronos.

    curl -s -X GET 'https://rpc.cronos.org/abci_query?path=%22%2Fcosmos.auth.v1beta1.Query%2FModuleAccountByName%22&data=0x0A0D6665655F636F6C6C6563746F72' | jq -r '.result.response.value'
    CmUKIi9jb3Ntb3MuYXV0aC52MWJldGExLk1vZHVsZUFjY291bnQSPwouCipjcmMxN3hwZnZha20yYW1nOTYyeWxzNmY4NHoza2VsbDhjNWw4OGVrZXIYCBINZmVlX2NvbGxlY3Rvcg==
    
  12. melekes commented on Sep 5, 2024

    @melekes
    Collaborator

    @xloem are you still experiencing this issue? Since you didn't respond to @mmsqe ^ above, I assume it's no longer true. Please reopen if I'm wrong.

  13. xloem commented on Sep 12, 2024

    @xloem
    Author

    Hex encoding was not working for me with my local node, as made clear in the report repeatedly. It is unclear to me whether that has been fixed, but I hope it has.

    I am no longer using cosmos blockchains, but I might come back in future years.

    Thanks for all your time and effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

abcibug

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions