diff --git a/Makefile b/Makefile index 75db4c1bae2..9498ddaa2b4 100644 --- a/Makefile +++ b/Makefile @@ -331,7 +331,7 @@ lint-fix: @echo "--> Running linter" @./scripts/go-lint-all.sh --fix -#? format: Run gofumpt and mispell +#? format: Run gofumpt and misspell format: find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs gofumpt -w find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs misspell -w diff --git a/modules/light-clients/08-wasm/keeper/keeper.go b/modules/light-clients/08-wasm/keeper/keeper.go index 586a678fe33..0556189bbc7 100644 --- a/modules/light-clients/08-wasm/keeper/keeper.go +++ b/modules/light-clients/08-wasm/keeper/keeper.go @@ -82,6 +82,11 @@ func (k Keeper) newQueryHandler(ctx sdk.Context, callerID string) *queryHandler return newQueryHandler(ctx, k.GetQueryPlugins(), callerID) } +// storeWasmCode stores the contract to the VM, pins the checksum in the VM's in memory cache and stores the checksum +// in the 08-wasm store. The checksum identifying it is returned if successful. The following checks are made to the +// contract code before storing: +// - Size bounds are checked. Contract length must not be 0 or exceed a specific size (maxWasmSize). +// - The contract must not have already been stored in store. func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wasmvm.WasmCode, gasLimit uint64) (wasmvm.Checksum, uint64, error)) ([]byte, error) { var err error if types.IsGzip(code) { @@ -134,6 +139,8 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wa return checksum, nil } +// migrateContractCode migrates the contract for a given light client to one denoted by the given new checksum. The checksum we +// are migrating to must first be stored using storeWasmCode and must not match the checksum currently stored for this light client. func (k Keeper) migrateContractCode(ctx sdk.Context, clientID string, newChecksum, migrateMsg []byte) error { wasmClientState, err := k.GetWasmClientState(ctx, clientID) if err != nil { diff --git a/modules/light-clients/08-wasm/keeper/querier_test.go b/modules/light-clients/08-wasm/keeper/querier_test.go index f41ee194d0e..b27c5adcc55 100644 --- a/modules/light-clients/08-wasm/keeper/querier_test.go +++ b/modules/light-clients/08-wasm/keeper/querier_test.go @@ -47,17 +47,17 @@ func mockCustomQuerier() func(sdk.Context, json.RawMessage) ([]byte, error) { func (suite *KeeperTestSuite) TestCustomQuery() { testCases := []struct { name string - malleate func(k *keeper.Keeper) + malleate func() expError error }{ { "success: custom query", - func(k *keeper.Keeper) { + func() { querierPlugin := keeper.QueryPlugins{ Custom: mockCustomQuerier(), } - k.SetQueryPlugins(querierPlugin) + GetSimApp(suite.chainA).WasmClientKeeper.SetQueryPlugins(querierPlugin) suite.mockVM.RegisterQueryCallback(types.StatusMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, querier wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) { echo := CustomQuery{ Echo: &QueryEcho{ @@ -87,7 +87,7 @@ func (suite *KeeperTestSuite) TestCustomQuery() { }, { "failure: default query", - func(k *keeper.Keeper) { + func() { suite.mockVM.RegisterQueryCallback(types.StatusMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, _ wasmvm.KVStore, _ wasmvm.GoAPI, querier wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) { resp, err := querier.Query(wasmvmtypes.QueryRequest{Custom: json.RawMessage("{}")}, math.MaxUint64) suite.Require().ErrorIs(err, wasmvmtypes.UnsupportedRequest{Kind: "Custom queries are not allowed"}) @@ -109,9 +109,9 @@ func (suite *KeeperTestSuite) TestCustomQuery() { err := endpoint.CreateClient() suite.Require().NoError(err) - wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper + tc.malleate() - tc.malleate(&wasmClientKeeper) + wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), endpoint.ClientID) clientState, ok := endpoint.GetClientState().(*types.ClientState) @@ -148,17 +148,17 @@ func (suite *KeeperTestSuite) TestStargateQuery() { testCases := []struct { name string - malleate func(k *keeper.Keeper) + malleate func() expError error }{ { "success: custom query", - func(k *keeper.Keeper) { + func() { querierPlugin := keeper.QueryPlugins{ Stargate: keeper.AcceptListStargateQuerier([]string{typeURL}, GetSimApp(suite.chainA).GRPCQueryRouter()), } - k.SetQueryPlugins(querierPlugin) + GetSimApp(suite.chainA).WasmClientKeeper.SetQueryPlugins(querierPlugin) suite.mockVM.RegisterQueryCallback(types.TimestampAtHeightMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, store wasmvm.KVStore, _ wasmvm.GoAPI, querier wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) { queryRequest := types.QueryChecksumsRequest{} @@ -200,12 +200,12 @@ func (suite *KeeperTestSuite) TestStargateQuery() { // This exercises the full flow through the grpc handler and into the light client for verification, handling encoding and routing. // Furthermore we write a test key and assert that the state changes made by this handler were discarded by the cachedCtx at the grpc handler. "success: verify membership query", - func(k *keeper.Keeper) { + func() { querierPlugin := keeper.QueryPlugins{ Stargate: keeper.AcceptListStargateQuerier([]string{""}, GetSimApp(suite.chainA).GRPCQueryRouter()), } - k.SetQueryPlugins(querierPlugin) + GetSimApp(suite.chainA).WasmClientKeeper.SetQueryPlugins(querierPlugin) store := suite.chainA.GetContext().KVStore(GetSimApp(suite.chainA).GetKey(exported.StoreKey)) store.Set(proofKey, value) @@ -277,7 +277,7 @@ func (suite *KeeperTestSuite) TestStargateQuery() { }, { "failure: default querier", - func(k *keeper.Keeper) { + func() { suite.mockVM.RegisterQueryCallback(types.TimestampAtHeightMsg{}, func(_ wasmvm.Checksum, _ wasmvmtypes.Env, _ []byte, store wasmvm.KVStore, _ wasmvm.GoAPI, querier wasmvm.Querier, _ wasmvm.GasMeter, _ uint64, _ wasmvmtypes.UFraction) (*wasmvmtypes.QueryResult, uint64, error) { queryRequest := types.QueryChecksumsRequest{} bz, err := queryRequest.Marshal() @@ -311,9 +311,9 @@ func (suite *KeeperTestSuite) TestStargateQuery() { err := endpoint.CreateClient() suite.Require().NoError(err) - wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper + tc.malleate() - tc.malleate(&wasmClientKeeper) + wasmClientKeeper := GetSimApp(suite.chainA).WasmClientKeeper payload := types.QueryMsg{ TimestampAtHeight: &types.TimestampAtHeightMsg{