Skip to content
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

[Bug]: ABCI Query to CometRPC with height: 0 does not query most recent height #23481

Closed
1 task done
sybilsingleton opened this issue Jan 22, 2025 · 0 comments · Fixed by #23483
Closed
1 task done
Labels

Comments

@sybilsingleton
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

When querying the CometRPC with a height of 0, I expected to get the latest height.
But it actually queried the first block.

I think this section of code is the culprit because moving the condition req.Height == 0 to the top of the function fixes the issue and requesting a 0 or empty height returns the latest data like it should.

func (c *consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (resp *abciproto.QueryResponse, err error) {
resp, isGRPC, err := c.maybeRunGRPCQuery(ctx, req)
if isGRPC {
return resp, err
}
// when a client did not provide a query height, manually inject the latest
// for modules queries, AppManager does it automatically
if req.Height == 0 {
latestVersion, err := c.store.GetLatestVersion()
if err != nil {
return nil, err
}
req.Height = int64(latestVersion)
}

Cosmos SDK Version

main

How to reproduce?

Query with "height": 0

You can see that it returns "0" too

~ curl 'http://localhost:26657/' -H 'Content-Type: application/json' --data-raw '{
  "jsonrpc": "2.0",
  "id": 256237421866,
  "method": "abci_query",
  "params": {
    "path": "/cosmos.auth.v1beta1.Query/Account",
    "data": "0a2d636f736d6f733166746e7665706c686b6d63327974673477726c7a72786e6667347677396366763265747a6571",
    "prove": false,
    "height": "0".  <-- 0 height  
  }
}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   668  100   381  100   287  54103  40755 --:--:-- --:--:-- --:--:-- 95428
{
  "jsonrpc": "2.0",
  "id": 256237421866,
  "result": {
    "response": {
      "code": 0,
      "log": "",
      "info": "",
      "index": "0",
      "key": null,
      "value": "Cp0BCiAvY29zbW9zLmF1dGgudjFiZXRhMS5CYXNlQWNjb3VudBJ5Ci1jb3Ntb3MxZnRudmVwbGhrbWMyeXRnNHdybHpyeG5mZzR2dzljZnYyZXR6ZXESRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECjQCIEx5eky3T7fyhwd4qXWpQJmqJHV2OencvTcV5dF0gAg==",
      "proofOps": null,
      "height": "0",  <-- Should be latest block
      "codespace": ""
    }
  }
}

Query with non-zero height

Here it respects the requested height and returns the data from it.

~  curl 'http://localhost:26657/' -H 'Content-Type: application/json' --data-raw '{
  "jsonrpc": "2.0",
  "id": 256237421866,
  "method": "abci_query",
  "params": {
    "path": "/cosmos.auth.v1beta1.Query/Account",
    "data": "0a2d636f736d6f733166746e7665706c686b6d63327974673477726c7a72786e6667347677396366763265747a6571",
    "prove": false,
    "height": "445". <--- Specify a recent height
  }
}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   672  100   383  100   289   483k   365k --:--:-- --:--:-- --:--:--  656k
{
  "jsonrpc": "2.0",
  "id": 256237421866,
  "result": {
    "response": {
      "code": 0,
      "log": "",
      "info": "",
      "index": "0",
      "key": null,
      "value": "Cp0BCiAvY29zbW9zLmF1dGgudjFiZXRhMS5CYXNlQWNjb3VudBJ5Ci1jb3Ntb3MxZnRudmVwbGhrbWMyeXRnNHdybHpyeG5mZzR2dzljZnYyZXR6ZXESRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECjQCIEx5eky3T7fyhwd4qXWpQJmqJHV2OencvTcV5dF0gAg==",
      "proofOps": null,
      "height": "445",  <--- same height is used
      "codespace": ""
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🥳 Done
Development

Successfully merging a pull request may close this issue.

1 participant