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

feat(tm2): Add Specific Block Height query Feature to ABCI Queries #2722

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Aug 22, 2024

Description

Added a new function that performs ABCI queries at a specific block height.

  • Modified ABCIQueryWithOptions in the RPC client to support querying at specific block heights.
  • Updated QueryHandler and QueryCfg to include height and prove options.
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Aug 22, 2024
Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 65.78947% with 13 lines in your changes missing coverage. Please review.

Project coverage is 60.77%. Comparing base (04d5239) to head (9afbe23).
Report is 39 commits behind head on master.

Files with missing lines Patch % Lines
tm2/pkg/sdk/baseapp.go 0.00% 7 Missing ⚠️
tm2/pkg/crypto/keys/client/query.go 66.66% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2722      +/-   ##
==========================================
+ Coverage   60.23%   60.77%   +0.53%     
==========================================
  Files         562      563       +1     
  Lines       75091    76127    +1036     
==========================================
+ Hits        45230    46264    +1034     
+ Misses      26481    26461      -20     
- Partials     3380     3402      +22     
Flag Coverage Δ
contribs/gnodev 61.46% <ø> (+0.06%) ⬆️
contribs/gnofaucet 15.31% <ø> (ø)
gno.land 67.17% <ø> (+2.41%) ⬆️
gnovm 65.63% <ø> (+1.30%) ⬆️
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (ø)
tm2 62.07% <65.78%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@notJoon notJoon marked this pull request as draft August 22, 2024 03:31
@notJoon notJoon marked this pull request as ready for review August 23, 2024 02:43
@notJoon notJoon requested a review from a team as a code owner August 23, 2024 02:43
@dongwon8247 dongwon8247 requested a review from r3v4s August 26, 2024 01:59
@r3v4s
Copy link
Contributor

r3v4s commented Aug 26, 2024

Latest approach seems better than old one. However to fully support this functionality, I think we need pruning strategy. @zivkovicmilos Do we have any?

@notJoon
Copy link
Member Author

notJoon commented Aug 26, 2024

we need pruning strategy.

I think this is probably related 🤔

https://github.com/gnolang/gno/blob/master/tm2/pkg/store/types/options.go#L10-L23

Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tackling this 🙏

I can't seem to make the querying work for custom heights. This simple post request:

{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "abci_query",
    "params": [
        "bank/balances/g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
        "",
        "10", // HEIGHT
        false
    ]
}

Will return:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "response": {
            "ResponseBase": {
                "Error": {
                    "@type": "/std.InternalError"
                },
                "Data": null,
                "Events": null,
                "Log": "",
                "Info": ""
            },
            "Key": null,
            "Value": null,
            "Proof": null,
            "Height": "0"
        }
    }
}

The logs on the node would just have this:

ABCIQuery	{"module": "rpc", "path": "bank/balances/g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5", "data": "", "result": {"Error":{},"Data":null,"Events":null,"Log":"","Info":"","Key":null,"Value":null,"Proof":null,"Height":0}}

"data": data,
"prove": opts.Prove,
}
if opts.Height != 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: isn't this misleading? Specifying 0 will cause an error down the line if I'm not mistaken, but in this case it will just continue on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. yes it would be clearer to only add the key if opts.Height is greater than 0

@@ -56,6 +60,15 @@ import (
// | height | int64 | 0 | false | Height (0 means latest) |
// | prove | bool | false | false | Includes proof if true |
func ABCIQuery(ctx *rpctypes.Context, path string, data []byte, height int64, prove bool) (*ctypes.ResultABCIQuery, error) {
if height < 0 {
return nil, errors.New("height cannot be negative")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a standard error

@@ -56,6 +60,15 @@ import (
// | height | int64 | 0 | false | Height (0 means latest) |
// | prove | bool | false | false | Includes proof if true |
func ABCIQuery(ctx *rpctypes.Context, path string, data []byte, height int64, prove bool) (*ctypes.ResultABCIQuery, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a small unit test that verifies the errors?

I know our RPC testing suite is super janky, but it shouldn't be too much of a hassle to write a few cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I promise refactoring this testing suite is on my bucket list

@@ -389,10 +392,6 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
default:
return handleQueryCustom(app, path, req)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this error wrap?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because it was unreacahble. I'll add the error message back in proper position

@@ -49,6 +49,7 @@ type BaseApp struct {
// See methods setCheckState and setDeliverState.
checkState *state // for CheckTx
deliverState *state // for DeliverTx
currentState *state // current state, set after Commit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always nil, I think you can drop it

@@ -487,7 +488,11 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res

// cache wrap the commit-multistore for safety
// XXX RunTxModeQuery?
ctx := NewContext(RunTxModeCheck, cacheMS, app.checkState.ctx.BlockHeader(), app.logger).WithMinGasPrices(app.minGasPrices)
// ctx := NewContext(RunTxModeCheck, cacheMS, app.checkState.ctx.BlockHeader(), app.logger).WithMinGasPrices(app.minGasPrices)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove the comment?

@notJoon notJoon marked this pull request as draft September 12, 2024 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related
Projects
Status: In Progress
Status: In Review
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants