-
Notifications
You must be signed in to change notification settings - Fork 596
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
Refactor 08-wasm with improvements after 02-client refactor #6088
Conversation
WalkthroughWalkthroughThe changes in the Changes
Assessment against linked issues
Possibly related issues
Recent Review DetailsConfiguration used: .coderabbit.yml Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
* Move functionality from client state methods to light client module methods. - Yank all statements and delete functions as needed. - Make any required functions from types/ public. - Add the vm in the 08-wasm keeper. - Update documentation to include documentation of deleted functions. * Remove global VM, introspection to retrieve client identifier. - Refactor signatures to explicitly pass vm, client identifier for time being. - Refactor tests to conform with new signatures. - Replace occurences of `ibcwasm.GetVM` in other keeper functions. * Move migrateContract from clientState to keeper method. - Matches moves for other functions. - Move is required to address future circular dependency for state management (keeper would import types and types would import keeper) - Rm migrate_contract(test).go files. * Move state management to keeper. - Remove globals for state (Checksums) - Move access functions from types to keeper, move tests. - Update calls using global to instead go through keeper. * Make InitializePinnedCodes a method on the keeper. * Remove pending todo in test for migrate contract. This previously was testing a function that didn't set the client state after calling the contract (invoking through the keeper always sets a client state after contract invocation). Hence, even if we don't set explicitly in the migrateFn callback, we _still_ get a client state in the end. * Move vm entrypoint functions in keeper/ package. * feat: move vm entry points to keeper. * chore: simplify signatures. * test: add amended tests for contact keeper. * refactor: move querier to keeper package. * lint: you'll never fix me. * refactor: remove queryRouter global variable - Move into the func for creating new plugins, pass it to acceptStargateQuery directly. This is probably what wasmd did (see they don't accept a query router now?). Since we don't use the get elsewhere, this was the smallest diff for a globa. - Preemptively ran make lint-fix, gotcha linting crybaby. * refactor: remove global for query plugins. * nit: rename to queryPlugins. * refactor: remove QueryPluginsI interface. * refactor: make queryHandler a private type. * Make migrateContractCode a private function, clean up uneeded export in export_test.go for types/. * refactor: Move vm entrypoints to keeper. - Remove generic types and do unmarshalling in light client methods. - Move all functions onto keeper and adjust call sites. * chore: address some testing todos. Move testing unmarshal failure case to light client tests. * chore: additional tiny nits. - Consistently use wasmClientKeeper as local var name. - Reorg keeper fields slightly. - Rm 'vm.go' which was already empty. * chore: restructure definitions to make diff more readable. * d'oh: rm vm arg from instantiate. * nit: Space out keeper fields. Remove TODO for method name.
fc05cb9
to
0b27b84
Compare
Will clean up some of the pending TODOs and then open for review. Diff is already large enough so don't want to add to it atm with additional diffs for the follow ups in #6103 |
return clientState.UpdateState(ctx, cdc, clientStore, clientMsg) | ||
clientMessage, ok := clientMsg.(*types.ClientMessage) | ||
if !ok { | ||
panic(fmt.Errorf("expected type %T, got %T", &types.ClientMessage{}, clientMsg)) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
|
||
res, err := l.keeper.WasmSudo(ctx, clientID, clientStore, clientState, payload) | ||
if err != nil { | ||
panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
|
||
var result types.UpdateStateResult | ||
if err := json.Unmarshal(res, &result); err != nil { | ||
panic(errorsmod.Wrap(types.ErrWasmInvalidResponseData, err.Error())) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods Warning
@@ -45,7 +45,6 @@ type queryHandler struct { | |||
} | |||
|
|||
// newQueryHandler returns a default querier that can be used in the contract. | |||
// TODO(jim): Make private and use export_test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stale
@@ -328,13 +328,14 @@ func (suite *KeeperTestSuite) TestStargateQuery() { | |||
// NOTE: we register query callbacks against: types.TimestampAtHeightMsg{} | |||
// in practise, this can against any client state msg, however registering against types.StatusMsg{} introduces recursive loops | |||
// due to test case: "success: verify membership query" | |||
// TODO(Jim): Sanity check that it unmarshals correctly? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checked the typical res is nil/not nil.
if !found { | ||
return errorsmod.Wrap(clienttypes.ErrClientNotFound, substituteClientID) | ||
} | ||
|
||
substituteClientState := substituteClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dunno why tf I had done this 😅
@@ -854,7 +854,9 @@ func (suite *WasmTestSuite) TestVerifyUpgradeAndUpdateState() { | |||
}, | |||
clienttypes.ErrClientNotFound, | |||
}, | |||
/* TODO(jim): Get back to these. | |||
/* NOTE(jim): This can't fail on unmarshalling, it appears. Any consensus type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make sense to keep this in to note for covering this edge case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there something we should do about this commented out code for a follow up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsure tbh. On the one hand I think we should be aware of this quirk, on the other hand, can't seem to best find a place to add it.
@@ -1462,24 +1463,20 @@ func (suite *WasmTestSuite) TestRecoverClient() { | |||
}, | |||
clienttypes.ErrClientNotFound, | |||
}, | |||
/* TODO(jim): We don't pass a client state directly now so we need to modify how this is tested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first test was removed, was already checked. Second test was amended to cover the case where the substitute has a diff checksum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Amazing work, really clean for the scope of this refactor 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I think I've reviewed all necessary files. Happy to merge this and create follow ups for anything outstanding.
Just left some nits on tests and such. Awesome work on refactoring this! Looks much better imo! 🚀
storeService: storeService, | ||
clientKeeper: clientKeeper, | ||
authority: authority, | ||
} | ||
|
||
_, err := sb.Build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we'd be better placed just keeping the schema around on the Keeper
?
Avoid having to add it sometime when/if it becomes necessary.
I don't feel too strongly about it tho, happy to defer to your judgement on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave it off the keeper for time being, have a slight pref for not adding it if it isn't doing something (and makes someone wonder why its there in the future)
testCases := []struct { | ||
name string | ||
malleate func() | ||
malleate func(k *keeper.Keeper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nice to change these tests to use GetSimApp(suite.chainA).WasmClientKeeper
directly inside malleate instead of passing the arg. If only for consistencies sake with the rest of the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, part of one of the follow ups to refactor this!
@@ -132,17 +148,17 @@ func (suite *TypesTestSuite) TestStargateQuery() { | |||
|
|||
testCases := []struct { | |||
name string | |||
malleate func() | |||
malleate func(k *keeper.Keeper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -854,7 +854,9 @@ func (suite *WasmTestSuite) TestVerifyUpgradeAndUpdateState() { | |||
}, | |||
clienttypes.ErrClientNotFound, | |||
}, | |||
/* TODO(jim): Get back to these. | |||
/* NOTE(jim): This can't fail on unmarshalling, it appears. Any consensus type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there something we should do about this commented out code for a follow up?
Co-authored-by: Damian Nolan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Actionable comments outside the diff hunks (1)
modules/light-clients/08-wasm/types/gas_register.go (1)
Line range hint
3-11
: Reorder imports according to the specified custom order to comply with the project's coding standards.import ( + wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types" + errorsmod "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types" - errorsmod "cosmossdk.io/errors" - sdkmath "cosmossdk.io/math" - storetypes "cosmossdk.io/store/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" )
Denominator: 100, | ||
} | ||
|
||
VMGasRegister = NewDefaultWasmGasRegister() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a blank line before the declaration of VMGasRegister
for better readability.
+
VMGasRegister = NewDefaultWasmGasRegister()
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
VMGasRegister = NewDefaultWasmGasRegister() | |
VMGasRegister = NewDefaultWasmGasRegister() |
Linter complaining about import ordering I think 👀 edit: maybe it was my code suggestion |
Quality Gate passed for 'ibc-go'Issues Measures |
Description
closes: #5833
closes: #5834
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.
docs/
).godoc
comments.Files changed
in the GitHub PR explorer.SonarCloud Report
in the comment section below once CI passes.Summary by CodeRabbit
Refactor
keeper.go
for improved performance and code organization.keeper_vm.go
for better reliability and maintainability.gas_register.go
to optimize gas-related functionalities.New Features
keeper.go
.keeper_vm.go
to enhance functionality.VMGasRegister
ingas_register.go
for improved gas handling.Bug Fixes
keeper.go
for better error handling and code consistency.keeper_vm.go
for enhanced stability.gas_register.go
for improved performance.Documentation
keeper.go
,keeper_vm.go
, andgas_register.go
for better clarity and understanding.