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(08-wasm): querier plugins implemented #5345

Merged
merged 31 commits into from
Dec 12, 2023

Conversation

srdtrk
Copy link
Member

@srdtrk srdtrk commented Dec 8, 2023

Description

closes: #5325

Commit Message / Changelog Entry

feat(08-wasm): querier plugins implemented

see the guidelines for commit messages. (view raw markdown for examples)


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@srdtrk srdtrk added the 08-wasm label Dec 8, 2023
Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Excellent work @srdtrk! This looks good to me, pending @DimitrisJim suggestions on error redactions. I left a couple of nits on godocs etc

LGTM!!

modules/light-clients/08-wasm/types/querier.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/keeper/options.go Outdated Show resolved Hide resolved
@@ -107,3 +113,88 @@ func (suite *TypesTestSuite) TestCustomQuery() {
})
}
}

func (suite *TypesTestSuite) TestStargateQuery() {
typeURL := "/ibc.lightclients.wasm.v1.Query/Checksums"
Copy link
Member

Choose a reason for hiding this comment

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

wonder if we should add any more test queries for something basic, query from x/bank or x/staking for example, this is probably fine tho!

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 will add more if others also want this

modules/light-clients/08-wasm/types/querier.go Outdated Show resolved Hide resolved
Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Amazing, @srdtrk! Thanks for raising the issue and then opening the PR so quickly. Left a bunch of comments for now, but it looks good in my opinion. I will take a second look later today/tomorrow.

modules/light-clients/08-wasm/types/querier.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/querier.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/querier.go Outdated Show resolved Hide resolved
Comment on lines 95 to 103
// SetQueryPlugins sets the current query plugins
func SetQueryPlugins(plugins *QueryPlugins) {
queryPlugins = plugins
}

// GetQueryPlugins returns the current query plugins
func GetQueryPlugins() *QueryPlugins {
return queryPlugins
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to make these package internal? Should users use only WithQueryPlugins or do we expect them also to be able to use these 2 functions?

Copy link
Member

Choose a reason for hiding this comment

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

If possible it would be nice. There's the option of moving queryPlugins to internal/ibcwasm that I think @DimitrisJim suggested but unsure if that comes with some import cycle shenanigans.

Copy link
Member Author

@srdtrk srdtrk Dec 11, 2023

Choose a reason for hiding this comment

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

But the keeper needs access to these functions and the user needs to be exposed to QueryPlugins

Copy link
Contributor

@DimitrisJim DimitrisJim Dec 11, 2023

Choose a reason for hiding this comment

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

my main Q was w.r.t DefaultQuerier. As far as I understood, people will never override it, it just wraps things they override (namely, the queryPlugins) hence it could ideally be private (though still in types).

Copy link
Contributor

Choose a reason for hiding this comment

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

But the keeper needs access to these functions

The keeper can access these functions when it is internal? The 08-wasm keeper right?

Copy link
Contributor

Choose a reason for hiding this comment

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

After reviewing some more, I'd have a preference to move GetQueryPlugins/SetQueryPlugins to the internal package so that WithQueryPlugins is the only option to override the query plugins (ensuring no accidental nil values)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough @colin-axner. Do you think it'd be ok to keep queryHandler in types (after it is made private)? So that I don't need to move gas_registry to internal too?

Copy link
Contributor

@colin-axner colin-axner Dec 11, 2023

Choose a reason for hiding this comment

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

yes, I am definitely in favour of keeping all implementation code in types. Make it private when possible. For Get/Set of QueryPlugins, I would add QueryPlugins as an expected interface, so you don't need to move over the implementation logic. Hopefully we remove all this global stuff before too long

If it is too much work, I'm fine as is. Mostly interested in limiting accidental misuse of query plugins by creating one api for setting/updating them

Copy link
Member

Choose a reason for hiding this comment

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

Hopefully we remove all this global stuff before too long

Agree! But from the looks of things we should be able to switch over quite nicely from the internal/ibcwasm stuff to the vm and such existing as fields on the Keeper. Looks like it will be clean enough to do it when the time comes :)

And fwiw I think working with the internal dir for the global types makes a big difference for the time being!

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 moved getters and setters to internal now. And made queryHandler private


isAccepted := slices.Contains(accepted, request.Path)
if !isAccepted {
return nil, wasmvmtypes.UnsupportedRequest{Kind: fmt.Sprintf("'%s' path is not allowed from the contract", request.Path)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use wasmvm errors or our own?

Copy link
Member Author

Choose a reason for hiding this comment

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

wasmvm in my opinion. Similar to what wasmd does. This also helps with the redactErr function that I just added.

modules/light-clients/08-wasm/types/querier.go Outdated Show resolved Hide resolved
clientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec())

// reset query plugins after each test
types.SetQueryPlugins(types.NewDefaultQueryPlugins())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not do this after the call to SetupWasmWithMockVM as you do in the TestCustomQuery?

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 think the end of test might be more reliable now. I should maybe change the other one too

modules/light-clients/08-wasm/keeper/options_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

LGTM, going to review the test files next

modules/light-clients/08-wasm/types/querier.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/querier.go Outdated Show resolved Hide resolved
Comment on lines 95 to 103
// SetQueryPlugins sets the current query plugins
func SetQueryPlugins(plugins *QueryPlugins) {
queryPlugins = plugins
}

// GetQueryPlugins returns the current query plugins
func GetQueryPlugins() *QueryPlugins {
return queryPlugins
}
Copy link
Contributor

Choose a reason for hiding this comment

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

But the keeper needs access to these functions

The keeper can access these functions when it is internal? The 08-wasm keeper right?

Comment on lines 95 to 103
// SetQueryPlugins sets the current query plugins
func SetQueryPlugins(plugins *QueryPlugins) {
queryPlugins = plugins
}

// GetQueryPlugins returns the current query plugins
func GetQueryPlugins() *QueryPlugins {
return queryPlugins
}
Copy link
Contributor

Choose a reason for hiding this comment

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

it just wraps things they override (namely, the queryPlugins) hence it could ideally be private (though still in types).

Yea, I think it could be nice to make queryHandler and newQueryHandler private as it should only be invoked by types/vm.go? But it is a nice to have

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Thanks for the quick implementation @srdtrk! The feature looks good to me 🙂

@crodriguezvega
Copy link
Contributor

@srdtrk Can you please, pretty please update the docs as well (in this PR or in a follow-up)? 🙏

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Great work! Left just one more nit. Let's update the docs in a separate PR, so that the backport of this PR is clean to the release branches.

@srdtrk
Copy link
Member Author

srdtrk commented Dec 12, 2023

@crodriguezvega, let's add the docs in another PR as this feature should not be blocked on documentation issues and nits

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

all aboard! ⛵ lgtm!

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

ACK

@srdtrk srdtrk merged commit e2bcb77 into main Dec 12, 2023
74 checks passed
@srdtrk srdtrk deleted the serdar/issue#5325-replace-querier branch December 12, 2023 12:04
mergify bot pushed a commit that referenced this pull request Dec 12, 2023
* imp: moved gas to internal

* fix: fixed compiler complaints

* feat: added 'QueryRouter' interface

* imp: passing the queryRouter to keeper

* Revert "fix: fixed compiler complaints"

This reverts commit 208e314.

* Revert "imp: moved gas to internal"

This reverts commit b45b605.

* fix(test): fixed keeper_test.go

* imp: initial querier template

* imp: moved querier to types

* fix: compiler complaints

* imp: removed querier from keeper

* feat: including default querier

* imp: added options

* feat: querier implemented fully

* docs: improved godocs

* imp: improved the querier

* style: improved styling of querier

* fix: fixed options

* fix: fixed options not being passed with config

* style: renamed variables

* imp: added review items

* imp: review items

* imp: set and get query plugins made private

* docs: added more godocs

* fix: default plugin not set

* imp: review items

* docs: added a godoc

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit e2bcb77)

# Conflicts:
#	modules/light-clients/08-wasm/internal/ibcwasm/wasm.go
#	modules/light-clients/08-wasm/keeper/keeper.go
#	modules/light-clients/08-wasm/keeper/keeper_test.go
#	modules/light-clients/08-wasm/keeper/migrations.go
#	modules/light-clients/08-wasm/testing/simapp/app.go
#	modules/light-clients/08-wasm/types/querier_test.go
mergify bot pushed a commit that referenced this pull request Dec 12, 2023
* imp: moved gas to internal

* fix: fixed compiler complaints

* feat: added 'QueryRouter' interface

* imp: passing the queryRouter to keeper

* Revert "fix: fixed compiler complaints"

This reverts commit 208e314.

* Revert "imp: moved gas to internal"

This reverts commit b45b605.

* fix(test): fixed keeper_test.go

* imp: initial querier template

* imp: moved querier to types

* fix: compiler complaints

* imp: removed querier from keeper

* feat: including default querier

* imp: added options

* feat: querier implemented fully

* docs: improved godocs

* imp: improved the querier

* style: improved styling of querier

* fix: fixed options

* fix: fixed options not being passed with config

* style: renamed variables

* imp: added review items

* imp: review items

* imp: set and get query plugins made private

* docs: added more godocs

* fix: default plugin not set

* imp: review items

* docs: added a godoc

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit e2bcb77)
srdtrk added a commit that referenced this pull request Dec 12, 2023
* imp: moved gas to internal

* fix: fixed compiler complaints

* feat: added 'QueryRouter' interface

* imp: passing the queryRouter to keeper

* Revert "fix: fixed compiler complaints"

This reverts commit 208e314.

* Revert "imp: moved gas to internal"

This reverts commit b45b605.

* fix(test): fixed keeper_test.go

* imp: initial querier template

* imp: moved querier to types

* fix: compiler complaints

* imp: removed querier from keeper

* feat: including default querier

* imp: added options

* feat: querier implemented fully

* docs: improved godocs

* imp: improved the querier

* style: improved styling of querier

* fix: fixed options

* fix: fixed options not being passed with config

* style: renamed variables

* imp: added review items

* imp: review items

* imp: set and get query plugins made private

* docs: added more godocs

* fix: default plugin not set

* imp: review items

* docs: added a godoc

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit e2bcb77)

Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com>
colin-axner pushed a commit that referenced this pull request Dec 12, 2023
* feat(08-wasm): querier plugins implemented (#5345)

* imp: moved gas to internal

* fix: fixed compiler complaints

* feat: added 'QueryRouter' interface

* imp: passing the queryRouter to keeper

* Revert "fix: fixed compiler complaints"

This reverts commit 208e314.

* Revert "imp: moved gas to internal"

This reverts commit b45b605.

* fix(test): fixed keeper_test.go

* imp: initial querier template

* imp: moved querier to types

* fix: compiler complaints

* imp: removed querier from keeper

* feat: including default querier

* imp: added options

* feat: querier implemented fully

* docs: improved godocs

* imp: improved the querier

* style: improved styling of querier

* fix: fixed options

* fix: fixed options not being passed with config

* style: renamed variables

* imp: added review items

* imp: review items

* imp: set and get query plugins made private

* docs: added more godocs

* fix: default plugin not set

* imp: review items

* docs: added a godoc

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit e2bcb77)

# Conflicts:
#	modules/light-clients/08-wasm/internal/ibcwasm/wasm.go
#	modules/light-clients/08-wasm/keeper/keeper.go
#	modules/light-clients/08-wasm/keeper/keeper_test.go
#	modules/light-clients/08-wasm/keeper/migrations.go
#	modules/light-clients/08-wasm/testing/simapp/app.go
#	modules/light-clients/08-wasm/types/querier_test.go

* fix conflicts.

* lint issues

---------

Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com>
Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
08-wasm priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace the pass-through querier with an extension API
5 participants