cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
657 stars 343 forks source link

Implement Height Parameter for Queries #1063

Open msteiner96 opened 2 years ago

msteiner96 commented 2 years ago

I suggest that we add another parameter to ALL querys, using which you can execute queries not automatically to the current blockheight but to a lower blockheight.

This needs an archive node, since most nodes only have 100 heights saved. Anyways, we can catch that error and it might be helpful.

Flags:
      --height int      Use a specific height to query state at (this can error if the node is pruning state)
webmaster128 commented 2 years ago

First step is here: https://github.com/cosmos/cosmjs/issues/1250

lovrobiljeskovic commented 1 year ago

@webmaster128 Hey, I am looking for this same functionality as well. I'm not sure that I follow how #1250 allows for querying with a block height? Or is there still some implementation needed for us to be able to do any query with a block height?

Appreciate any help that you can provide!

webmaster128 commented 1 year ago

Turns out the gRPC interface does not support height parameters directly. However, they can be passed as metadata. See https://docs.cosmos.network/v0.47/run-node/interact-node#query-for-historical-state-using-grpcurl and https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md.

In https://github.com/cosmos/cosmjs/pull/1378 you see a proof of concept how this can be added to our client to preserve and send it as part of the tendermint RPC request.

I dod not test that in a live system yet. If someone wants to explore this forther, have a look at #1378.