diff --git a/modules/light-clients/08-wasm/test_data/ics07_tendermint_cw.wasm.gz b/modules/light-clients/08-wasm/test_data/ics07_tendermint_cw.wasm.gz old mode 100644 new mode 100755 index bef8395ffd3..9f842a016d2 Binary files a/modules/light-clients/08-wasm/test_data/ics07_tendermint_cw.wasm.gz and b/modules/light-clients/08-wasm/test_data/ics07_tendermint_cw.wasm.gz differ diff --git a/modules/light-clients/08-wasm/test_data/ics10_grandpa_cw.wasm.gz b/modules/light-clients/08-wasm/test_data/ics10_grandpa_cw.wasm.gz old mode 100644 new mode 100755 index 952179e25df..a5890accf4d Binary files a/modules/light-clients/08-wasm/test_data/ics10_grandpa_cw.wasm.gz and b/modules/light-clients/08-wasm/test_data/ics10_grandpa_cw.wasm.gz differ diff --git a/modules/light-clients/08-wasm/types/client_state.go b/modules/light-clients/08-wasm/types/client_state.go index d11e73d5c1d..164e974c64c 100644 --- a/modules/light-clients/08-wasm/types/client_state.go +++ b/modules/light-clients/08-wasm/types/client_state.go @@ -110,22 +110,35 @@ func (cs ClientState) GetTimestampAtHeight( return consState.GetTimestamp(), nil } +type instantiateMessage struct { + ClientState *ClientState `json:"client_state"` + ConsensusState *ConsensusState `json:"consensus_state"` +} + // Initialize checks that the initial consensus state is an 08-wasm consensus state and // sets the client state, consensus state in the provided client store. // It also initializes the wasm contract for the client. -func (cs ClientState) Initialize(ctx sdk.Context, marshaler codec.BinaryCodec, clientStore sdk.KVStore, state exported.ConsensusState) error { +func (cs ClientState) Initialize(ctx sdk.Context, _ codec.BinaryCodec, clientStore sdk.KVStore, state exported.ConsensusState) error { consensusState, ok := state.(*ConsensusState) if !ok { return errorsmod.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T", &ConsensusState{}, state) } - setClientState(clientStore, marshaler, &cs) - setConsensusState(clientStore, marshaler, consensusState, cs.GetLatestHeight()) + + payload := instantiateMessage{ + ClientState: &cs, + ConsensusState: consensusState, + } + + encodedData, err := json.Marshal(payload) + if err != nil { + return errorsmod.Wrapf(err, "failed to marshal payload for wasm contract instantiation") + } // The global store key can be used here to implement #4085 // wasmStore := ctx.KVStore(WasmStoreKey) - _, err := initContract(ctx, clientStore, cs.CodeHash) + _, err := initContract(ctx, clientStore, cs.CodeHash, encodedData) if err != nil { return errorsmod.Wrapf(err, "failed to initialize contract") } diff --git a/modules/light-clients/08-wasm/types/store.go b/modules/light-clients/08-wasm/types/store.go index 7ebbf3fc320..f7ec241a9c6 100644 --- a/modules/light-clients/08-wasm/types/store.go +++ b/modules/light-clients/08-wasm/types/store.go @@ -96,20 +96,6 @@ func (ws updateProposalWrappedStore) getStore(key []byte) sdk.KVStore { return ws.substituteStore } -// setClientState stores the client state. -func setClientState(clientStore sdk.KVStore, cdc codec.BinaryCodec, clientState *ClientState) { - key := host.ClientStateKey() - val := clienttypes.MustMarshalClientState(cdc, clientState) - clientStore.Set(key, val) -} - -// setConsensusState stores the consensus state at the given height. -func setConsensusState(clientStore sdk.KVStore, cdc codec.BinaryCodec, consensusState *ConsensusState, height exported.Height) { - key := host.ConsensusStateKey(height) - val := clienttypes.MustMarshalConsensusState(cdc, consensusState) - clientStore.Set(key, val) -} - // getConsensusState retrieves the consensus state from the client prefixed // store. An error is returned if the consensus state does not exist or it cannot be unmarshalled. func GetConsensusState(clientStore sdk.KVStore, cdc codec.BinaryCodec, height exported.Height) (*ConsensusState, error) { diff --git a/modules/light-clients/08-wasm/types/vm.go b/modules/light-clients/08-wasm/types/vm.go index 1486e5acc67..15ca15aa041 100644 --- a/modules/light-clients/08-wasm/types/vm.go +++ b/modules/light-clients/08-wasm/types/vm.go @@ -47,7 +47,7 @@ func (r contractResult) Error() string { } // initContract calls vm.Init with appropriate arguments. -func initContract(ctx sdk.Context, clientStore sdk.KVStore, codeHash []byte) (*wasmvmtypes.Response, error) { +func initContract(ctx sdk.Context, clientStore sdk.KVStore, codeHash []byte, msg []byte) (*wasmvmtypes.Response, error) { sdkGasMeter := ctx.GasMeter() multipliedGasMeter := NewMultipliedGasMeter(sdkGasMeter, VMGasRegister) gasLimit := VMGasRegister.runtimeGasForContract(ctx) @@ -59,9 +59,8 @@ func initContract(ctx sdk.Context, clientStore sdk.KVStore, codeHash []byte) (*w Funds: nil, } - initMsg := []byte("{}") - ctx.GasMeter().ConsumeGas(VMGasRegister.NewContractInstanceCosts(len(initMsg)), "Loading CosmWasm module: instantiate") - response, gasUsed, err := WasmVM.Instantiate(codeHash, env, msgInfo, initMsg, newStoreAdapter(clientStore), cosmwasm.GoAPI{}, nil, multipliedGasMeter, gasLimit, costJSONDeserialization) + ctx.GasMeter().ConsumeGas(VMGasRegister.NewContractInstanceCosts(len(msg)), "Loading CosmWasm module: instantiate") + response, gasUsed, err := WasmVM.Instantiate(codeHash, env, msgInfo, msg, newStoreAdapter(clientStore), cosmwasm.GoAPI{}, nil, multipliedGasMeter, gasLimit, costJSONDeserialization) VMGasRegister.consumeRuntimeGas(ctx, gasUsed) return response, err }