Skip to content

Commit

Permalink
fixing the new store changes by using the adapter in the wasmer engine
Browse files Browse the repository at this point in the history
  • Loading branch information
spoo-bar committed May 16, 2023
1 parent 3324492 commit 7b8038e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
6 changes: 2 additions & 4 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,13 @@ func (k Keeper) instantiate(
// 0x03 | BuildContractAddressClassic (sdk.AccAddress)
prefixStoreKey := types.GetContractStorePrefix(contractAddress)
prefixStore := types.PrefixStoreInfo{PrefixKey: prefixStoreKey, Store: ctx.MultiStore().GetKVStore(k.storeKey)}
vmStore := types.NewStoreAdapter(prefixStore)

// prepare querier
querier := k.newQueryHandler(ctx, contractAddress)

// instantiate wasm contract
gas := k.runtimeGasForContract(ctx)
res, gasUsed, err := k.wasmVM.Instantiate(ctx, codeInfo.CodeHash, env, info, initMsg, vmStore, cosmwasmAPI, &querier, k.gasMeter(ctx), gas, costJSONDeserialization)
res, gasUsed, err := k.wasmVM.Instantiate(ctx, codeInfo.CodeHash, env, info, initMsg, prefixStore, cosmwasmAPI, &querier, k.gasMeter(ctx), gas, costJSONDeserialization)
k.consumeRuntimeGas(ctx, gasUsed)
if err != nil {
return nil, nil, sdkerrors.Wrap(types.ErrInstantiateFailed, err.Error())
Expand Down Expand Up @@ -430,9 +429,8 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller

prefixStoreKey := types.GetContractStorePrefix(contractAddress)
prefixStore := types.PrefixStoreInfo{PrefixKey: prefixStoreKey, Store: ctx.MultiStore().GetKVStore(k.storeKey)}
vmStore := types.NewStoreAdapter(prefixStore)
gas := k.runtimeGasForContract(ctx)
res, gasUsed, err := k.wasmVM.Migrate(ctx, newCodeInfo.CodeHash, env, msg, vmStore, cosmwasmAPI, &querier, k.gasMeter(ctx), gas, costJSONDeserialization)
res, gasUsed, err := k.wasmVM.Migrate(ctx, newCodeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, &querier, k.gasMeter(ctx), gas, costJSONDeserialization)
k.consumeRuntimeGas(ctx, gasUsed)
if err != nil {
return nil, sdkerrors.Wrap(types.ErrMigrationFailed, err.Error())
Expand Down
24 changes: 12 additions & 12 deletions x/wasm/types/tracking_wasmer_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (t *TrackingWasmerEngine) Query(ctx sdk.Context, code wasmvm.Checksum, env

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.Query(code, env, queryMsg, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.Query(code, env, queryMsg, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -389,7 +389,7 @@ func (t *TrackingWasmerEngine) Instantiate(ctx sdk.Context, checksum wasmvm.Chec

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.Instantiate(checksum, env, info, initMsg, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.Instantiate(checksum, env, info, initMsg, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -445,7 +445,7 @@ func (t *TrackingWasmerEngine) Execute(ctx sdk.Context, code wasmvm.Checksum, en

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.Execute(code, env, info, executeMsg, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.Execute(code, env, info, executeMsg, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -501,7 +501,7 @@ func (t *TrackingWasmerEngine) Migrate(ctx sdk.Context, checksum wasmvm.Checksum

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.Migrate(checksum, env, migrateMsg, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.Migrate(checksum, env, migrateMsg, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -557,7 +557,7 @@ func (t *TrackingWasmerEngine) Sudo(ctx sdk.Context, checksum wasmvm.Checksum, e

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.Sudo(checksum, env, sudoMsg, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.Sudo(checksum, env, sudoMsg, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -613,7 +613,7 @@ func (t *TrackingWasmerEngine) Reply(ctx sdk.Context, checksum wasmvm.Checksum,

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.Reply(checksum, env, reply, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.Reply(checksum, env, reply, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -677,7 +677,7 @@ func (t *TrackingWasmerEngine) IBCChannelOpen(ctx sdk.Context, checksum wasmvm.C

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.IBCChannelOpen(checksum, env, channel, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.IBCChannelOpen(checksum, env, channel, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -733,7 +733,7 @@ func (t *TrackingWasmerEngine) IBCChannelConnect(ctx sdk.Context, checksum wasmv

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.IBCChannelConnect(checksum, env, channel, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.IBCChannelConnect(checksum, env, channel, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -789,7 +789,7 @@ func (t *TrackingWasmerEngine) IBCChannelClose(ctx sdk.Context, checksum wasmvm.

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.IBCChannelClose(checksum, env, channel, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.IBCChannelClose(checksum, env, channel, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -845,7 +845,7 @@ func (t *TrackingWasmerEngine) IBCPacketReceive(ctx sdk.Context, checksum wasmvm

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.IBCPacketReceive(checksum, env, packet, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.IBCPacketReceive(checksum, env, packet, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -901,7 +901,7 @@ func (t *TrackingWasmerEngine) IBCPacketAck(ctx sdk.Context, checksum wasmvm.Che

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.IBCPacketAck(checksum, env, ack, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.IBCPacketAck(checksum, env, ack, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down Expand Up @@ -957,7 +957,7 @@ func (t *TrackingWasmerEngine) IBCPacketTimeout(ctx sdk.Context, checksum wasmvm

prefixStore := prefix.NewStore(gaskv.NewStore(store.Store, &contractMeter, stypes.KVGasConfig()), store.PrefixKey)

response, vmGasUsed, err := t.vm.IBCPacketTimeout(checksum, env, packet, prefixStore, goapi, querier, gasMeter, gasLimit, deserCost)
response, vmGasUsed, err := t.vm.IBCPacketTimeout(checksum, env, packet, NewStoreAdapter(prefixStore), goapi, querier, gasMeter, gasLimit, deserCost)

updatedGasInfo, trackingErr := t.getActualGas(ctx, CurrentOperation, contractAddress, GasConsumptionInfo{
SDKGas: 0,
Expand Down

0 comments on commit 7b8038e

Please sign in to comment.