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

Adding upcoming gauges query #1195

Merged
merged 24 commits into from
Apr 15, 2022
Merged

Adding upcoming gauges query #1195

merged 24 commits into from
Apr 15, 2022

Conversation

xBalbinus
Copy link
Contributor

Closes: #1158

Description

Added new request definitions in the proto. UpcomingGaugesPerDenom, UpcomingGaugesPerDenomRequest, UpcomingGaugesPerDenomResponse

Made proto-all

Added a keeper method in x/incentives/keeper/grpc_query.go .

Ditto for adding a test for this in grpc_query_test.go: note: I implemented tests as well for querying active upcoming gauges per denom. At the moment, they're not table driven but still diving deeper in and will implement soon.


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@ValarDragon
Copy link
Member

Nice work! I think the mytestnet folder got accidentally committed

@xBalbinus xBalbinus changed the title Xiangan/gaugequeries Adding upcoming gauges query Apr 5, 2022
xBalbinus and others added 3 commits April 5, 2022 12:52
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Comment on lines 140 to 153
pageRes, err := query.FilteredPaginate(valStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) {
upcomingGauges := k.GetUpcomingGauges(ctx)
for _, gauge := range upcomingGauges {
if gauge.DistributeTo.Denom == req.Denom {
gauges = append(gauges, gauge)
}
}
return true, nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.UpcomingGaugesPerDenomResponse{Data: gauges, Pagination: pageRes}, nil
Copy link
Member

Choose a reason for hiding this comment

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

On reviewing this PR, I'm realizing that every filtered paginate usage in this package is wrong. I think its fine to merge this as is though, since its not a real performance overhead / can be fixed later. (We should make an issue to track it)

Filtered paginate's method of working is actually pretty awkward / maybe we need to change it at the SDK level. It gives you the value in []bytes, that this code should then de-marshal, and check if it meets the required constraints. If accumulate is true, only then add it to the gauges result. But this is a high amount of overhead tbh. I think its probably worth getting this refactored in the SDK to be simple, with go 1.18 Generics.

I'll add more detail on this / convert it to an issue, doesn't block this PR!

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

Nice job on your first code change PR!!

LGTM! (It has the same behavior as ActiveGaugesPerDenom)

We should make two follow on issues:

  • One brainstorming ways for fixing the erroneous pagination behavior (either we change things directly here, or add better pagination code scaffolding)
  • Steps for getting a better table driven test framework here. (We need to make it easy to make upcoming, present, and completed gauges in the test suite)

suite.SetupTest()

// initial check
res, err := suite.app.IncentivesKeeper.ActiveGaugesPerDenom(sdk.WrapSDKContext(suite.ctx), &types.ActiveGaugesPerDenomRequest{})
Copy link
Member

Choose a reason for hiding this comment

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

oh you have to make a querier struct now for this to work now. (An update happened on main.

Change to suite.querier,ActiveGaugesPerDenom and I think that should work in all places where this is erroring.

@ValarDragon
Copy link
Member

Can you run make format to fix the lint errors

@xBalbinus
Copy link
Contributor Author

xBalbinus commented Apr 6, 2022 via email

@ValarDragon
Copy link
Member

PR LGTM, its having the liveness test timeout, but this confuses me, since this doesn't even touch the state machine? Any ideas @alexanderbez ?

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Looks great @xBalbinus!

I left some minor feedback. I'm also taking a look at the liveness test.

proto/osmosis/incentives/query.proto Show resolved Hide resolved
cmd := &cobra.Command{
Use: "upcoming-gauges-per-denom [denom]",
Short: "Query scheduled gauges per denom",
Long: strings.TrimSpace(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: for concise/straight forward CLI handlers like this, I'd argue Long is not necessary as it does not offer any additional help or insight.

Copy link
Contributor

Choose a reason for hiding this comment

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

bump @xBalbinus

x/incentives/keeper/grpc_query.go Outdated Show resolved Hide resolved
x/incentives/keeper/grpc_query.go Show resolved Hide resolved
x/incentives/keeper/grpc_query.go Show resolved Hide resolved
@alexanderbez alexanderbez added C:gRPC Issues and PRs related to the gRPC service and HTTP gateway. C:x/incentives labels Apr 7, 2022
@alexanderbez
Copy link
Contributor

alexanderbez commented Apr 7, 2022

Re liveness failures:

➜ starport chain serve --reset-once -v -c ./starport.ci.yml
[STARPORT] Cosmos SDK's version is: stargate - v0.45.1
[STARPORT] 
[STARPORT] 🛠️  Building proto...
[STARPORT] cannot build app:
[STARPORT] 
[STARPORT]      cannot build app:
[STARPORT] 
[STARPORT]      error while running command /var/folders/jl/532qskgn2y32m_qg3p4l8q440000gn/T/protoc832737936: osmosis/incentives/query.proto:136:54: Field number 1 has already been used in "osmosis.incentives.UpcomingGaugesPerDenomRequest" by field "denom".
[STARPORT] : exit status 1

Just an FYI, if liveness fails or timesout, you can always run it locally to find out why:

$ starport chain serve --reset-once -v -c ./starport.ci.yml

Comment on lines 135 to 136
string denom = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

We gotta be more careful with reviewing proto structs. I missed this too.

Suggested change
string denom = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 1;
string denom = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oop! Updated.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah your totally right. Is there a way we can lint for this more easily? I don't get why make proto-all even compiled with this as an issue.

xBalbinus and others added 5 commits April 7, 2022 17:09
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
@xBalbinus
Copy link
Contributor Author

make proto-format done; changes committed! Thanks @alexanderbez and @ValarDragon for your input & help.

@ValarDragon ValarDragon added the A:backport/v7.x Do not use. backport patches to v7.x branch label Apr 7, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 12, 2022

Codecov Report

Merging #1195 (3190691) into main (b6d342a) will decrease coverage by 0.82%.
The diff coverage is 3.71%.

@@            Coverage Diff             @@
##             main    #1195      +/-   ##
==========================================
- Coverage   20.90%   20.08%   -0.83%     
==========================================
  Files         196      203       +7     
  Lines       25425    26786    +1361     
==========================================
+ Hits         5316     5379      +63     
- Misses      19118    20409    +1291     
- Partials      991      998       +7     
Impacted Files Coverage Δ
x/claim/abci.go 0.00% <ø> (ø)
x/claim/client/cli/query.go 34.45% <ø> (ø)
x/claim/client/cli/tx.go 0.00% <ø> (ø)
x/claim/handler.go 0.00% <ø> (ø)
x/claim/keeper/claim.go 64.33% <ø> (ø)
x/claim/keeper/grpc_query.go 2.50% <ø> (ø)
x/claim/keeper/hooks.go 28.00% <ø> (ø)
x/claim/keeper/keeper.go 87.50% <ø> (ø)
x/claim/keeper/params.go 81.81% <ø> (ø)
x/claim/module.go 58.06% <ø> (ø)
... and 102 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 40d7094...3190691. Read the comment docs.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

🚀🚀🚀🚀🚀🚀🚀🚀🚀

@alexanderbez
Copy link
Contributor

I'm confused as to how CI is passing. Starport liveness test reports:

[STARPORT] # github.com/osmosis-labs/osmosis/v7/x/incentives/keeper
[STARPORT] ../../x/incentives/keeper/grpc_query.go:173:47: unknown field 'Data' in struct literal of type "github.com/osmosis-labs/osmosis/v7/x/incentives/types".UpcomingGaugesPerDenomResponse
[STARPORT] : exit status 2

@xBalbinus
Copy link
Contributor Author

Should we fix the liveliness tests first before committing? What might be causing this?

@alexanderbez
Copy link
Contributor

alexanderbez commented Apr 13, 2022

Should we fix the liveliness tests first before committing? What might be causing this?

@xBalbinus Yes, we need to fix it. The liveness test does two things primarily -- test the chain builds and runs. The error above tells you:

[STARPORT] ../../x/incentives/keeper/grpc_query.go:173:47: unknown field 'Data' in struct literal of type "github.com/osmosis-labs/osmosis/v7/x/incentives/types".UpcomingGaugesPerDenomResponse

@github-actions github-actions bot added the C:CLI label Apr 13, 2022
@xBalbinus
Copy link
Contributor Author

I just pushed out some fixes / changes & make all has been doing well for me (all tests passed). Let me know if the liveliness is still an issue.

@ValarDragon
Copy link
Member

So to fix that liveness error, can you do make proto-all, and then replace the usage of Data on line 173, with UpcomingGauges which is what should get written after make proto-all is ran? That should hopefully fix the liveness test

@github-actions github-actions bot added the C:x/gamm Changes, features and bugs related to the gamm module. label Apr 15, 2022
@ValarDragon ValarDragon merged commit eb39af7 into main Apr 15, 2022
@ValarDragon ValarDragon deleted the xiangan/gaugequeries branch April 15, 2022 02:33
mergify bot pushed a commit that referenced this pull request Apr 15, 2022
* Add queries for getting Upcoming gauges by denom

* rudimentary tests for denomquery

* Update proto/osmosis/incentives/query.proto

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>

* removed mytestnet

* fixed query tests

* fixed query tests

* Update proto/osmosis/incentives/query.proto pagination number

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Update x/incentives/keeper/grpc_query.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* implemented feedback

* amended minor bug with prefixStore

* investigating BeginDistribution issues

* investigating grpc_query_test.go

* Fix grpc query test

* fixed grpc tests, added nil checks for grpc query, removed long for query.go

* additional grpcquery fixes (double if removed)

* liveliness error fix

* gofmt grpc_query_test.go

* liveliness test fixes

* liveliness test fixes

Co-authored-by: Xiangan He <xiangan@polychain.capital>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
(cherry picked from commit eb39af7)

# Conflicts:
#	docs/core/proto-docs.md
#	go.mod
#	go.sum
#	proto/osmosis/gamm/v1beta1/query.proto
#	x/gamm/types/query.pb.go
#	x/incentives/client/cli/query.go
#	x/incentives/keeper/grpc_query.go
ValarDragon added a commit that referenced this pull request Apr 18, 2022
* Adding upcoming gauges query (#1195)

* Add queries for getting Upcoming gauges by denom

* rudimentary tests for denomquery

* Update proto/osmosis/incentives/query.proto

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>

* removed mytestnet

* fixed query tests

* fixed query tests

* Update proto/osmosis/incentives/query.proto pagination number

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Update x/incentives/keeper/grpc_query.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* implemented feedback

* amended minor bug with prefixStore

* investigating BeginDistribution issues

* investigating grpc_query_test.go

* Fix grpc query test

* fixed grpc tests, added nil checks for grpc query, removed long for query.go

* additional grpcquery fixes (double if removed)

* liveliness error fix

* gofmt grpc_query_test.go

* liveliness test fixes

* liveliness test fixes

Co-authored-by: Xiangan He <xiangan@polychain.capital>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
(cherry picked from commit eb39af7)

# Conflicts:
#	docs/core/proto-docs.md
#	go.mod
#	go.sum
#	proto/osmosis/gamm/v1beta1/query.proto
#	x/gamm/types/query.pb.go
#	x/incentives/client/cli/query.go
#	x/incentives/keeper/grpc_query.go

* fixing conflicts

* Revert "fixing conflicts"

This reverts commit 28022f1.

* Fix merge conflicts

* changed queriers to app.IncentiveKeepers

Co-authored-by: Xiangan He <76530366+xBalbinus@users.noreply.github.com>
Co-authored-by: Xiangan He <xiangan@polychain.capital>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v7.x Do not use. backport patches to v7.x branch C:CLI C:gRPC Issues and PRs related to the gRPC service and HTTP gateway. C:x/gamm Changes, features and bugs related to the gamm module. C:x/incentives
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add queries for getting Upcoming gauges by denom
4 participants