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

fixed recursive queries losing context #213

Merged
merged 1 commit into from
Jul 22, 2020
Merged

Conversation

reuvenpo
Copy link
Contributor

@reuvenpo reuvenpo commented Jul 22, 2020

This PR fixes an issue where performing recursive Smart Queries would fail on the second recursion, because keeper.queryPlugins would be uninitialized. The problem was that DefaultQueryPlugins and WasmQuerier were getting partially initialized copies of the keeper object, and would try to use the partly initialized copy instead of the concrete object.
In our testing in SecretNetwork, this fix allowed us to recurse queries multiple times (x >= 5) :)

CC: @assafmo

@reuvenpo reuvenpo requested a review from ethanfrey as a code owner July 22, 2020 13:18
@codecov
Copy link

codecov bot commented Jul 22, 2020

Codecov Report

Merging #213 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #213   +/-   ##
=======================================
  Coverage   72.02%   72.02%           
=======================================
  Files          27       27           
  Lines        2624     2624           
=======================================
  Hits         1890     1890           
  Misses        621      621           
  Partials      113      113           
Impacted Files Coverage Δ
x/wasm/internal/keeper/keeper.go 91.00% <100.00%> (ø)
x/wasm/internal/keeper/query_plugins.go 57.71% <100.00%> (ø)

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 6e021d9...a7f801d. Read the comment docs.

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Great fix. Thank you

@@ -82,7 +82,7 @@ func NewKeeper(cdc *codec.Codec, storeKey sdk.StoreKey, paramSpace params.Subspa
authZPolicy: DefaultAuthorizationPolicy{},
paramSpace: paramSpace,
}
keeper.queryPlugins = DefaultQueryPlugins(bankKeeper, stakingKeeper, keeper).Merge(customPlugins)
keeper.queryPlugins = DefaultQueryPlugins(bankKeeper, stakingKeeper, &keeper).Merge(customPlugins)
Copy link
Member

Choose a reason for hiding this comment

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

Nice to use a pointer/reference here. I support it.

Ah... now I get it. We copy the keeper into the query plugins before we set keeper.queryPlugins 🤯 🤦

Now I understand how this ends up as nil and all the issues.

Thanks for hunting it down, I was super busy today with other org stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something that may or may not be a bug, similarly to this, is that all the methods on the keeper take it by value. I think you should review the codebase for this sort of thing, because there may be many more places where we copy things that should be passed by reference.

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 all over the cosmos sdk. I remember a large debate with the core devs when someone wanted to make the keepers pointers. There was big backlash on the grounds of immuntabilitt or such. Anyway, I agree with you, I prefer pointer methods

@ethanfrey ethanfrey merged commit 04cfcdc into master Jul 22, 2020
@ethanfrey ethanfrey deleted the fix-recursive-queries branch July 22, 2020 15:22
@ethanfrey ethanfrey mentioned this pull request Jul 27, 2020
9 tasks
zemyblue pushed a commit to Finschia/wasmd that referenced this pull request Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants