Skip to content

Commit 753faea

Browse files
mergify[bot]DimitrisJimdamiannolan
authored
Use global wasm VM instead of keeping an additional reference in keeper. (backport #5146) (#5248)
* Use global wasm VM instead of keeping an additional reference in keeper. (#5146) (cherry picked from commit 595e1a9) # Conflicts: # modules/light-clients/08-wasm/keeper/genesis.go # modules/light-clients/08-wasm/keeper/keeper.go # modules/light-clients/08-wasm/keeper/snapshotter.go * Fix conflicts. * linter stuff as per usual. * fix: use StoreCodeUnchecked in snapshot restore func --------- Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com> Co-authored-by: Damian Nolan <damiannolan@gmail.com>
1 parent 55f3b8f commit 753faea

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

modules/light-clients/08-wasm/keeper/genesis.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package keeper
33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55

6+
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/internal/ibcwasm"
67
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
78
)
89

910
// InitGenesis initializes the 08-wasm module's state from a provided genesis
1011
// state.
1112
func (k Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState) error {
1213
for _, contract := range gs.Contracts {
13-
_, err := k.storeWasmCode(ctx, contract.CodeBytes, k.wasmVM.StoreCodeUnchecked)
14+
_, err := k.storeWasmCode(ctx, contract.CodeBytes, ibcwasm.GetVM().StoreCodeUnchecked)
1415
if err != nil {
1516
return err
1617
}
@@ -29,7 +30,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState {
2930
// Grab code from wasmVM and add to genesis state.
3031
var genesisState types.GenesisState
3132
for _, checksum := range checksums {
32-
code, err := k.wasmVM.GetCode(checksum)
33+
code, err := ibcwasm.GetVM().GetCode(checksum)
3334
if err != nil {
3435
panic(err)
3536
}

modules/light-clients/08-wasm/keeper/grpc_query.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
sdk "github.com/cosmos/cosmos-sdk/types"
1313

14+
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/internal/ibcwasm"
1415
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
1516
)
1617

@@ -32,7 +33,7 @@ func (k Keeper) Code(goCtx context.Context, req *types.QueryCodeRequest) (*types
3233
return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrWasmChecksumNotFound, req.Checksum).Error())
3334
}
3435

35-
code, err := k.wasmVM.GetCode(checksum)
36+
code, err := ibcwasm.GetVM().GetCode(checksum)
3637
if err != nil {
3738
return nil, status.Error(codes.NotFound, errorsmod.Wrap(types.ErrWasmChecksumNotFound, req.Checksum).Error())
3839
}

modules/light-clients/08-wasm/keeper/keeper.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ type Keeper struct {
2525
// implements gRPC QueryServer interface
2626
types.QueryServer
2727

28-
cdc codec.BinaryCodec
29-
wasmVM ibcwasm.WasmEngine
28+
cdc codec.BinaryCodec
3029

3130
clientKeeper types.ClientKeeper
3231

@@ -60,7 +59,6 @@ func NewKeeperWithVM(
6059

6160
return Keeper{
6261
cdc: cdc,
63-
wasmVM: vm,
6462
clientKeeper: clientKeeper,
6563
authority: authority,
6664
}
@@ -127,7 +125,7 @@ func (k Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wa
127125
}
128126

129127
// pin the code to the vm in-memory cache
130-
if err := k.wasmVM.Pin(vmChecksum); err != nil {
128+
if err := ibcwasm.GetVM().Pin(vmChecksum); err != nil {
131129
return nil, errorsmod.Wrapf(err, "failed to pin contract with checksum (%s) to vm cache", hex.EncodeToString(vmChecksum))
132130
}
133131

modules/light-clients/08-wasm/keeper/msg_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (k Keeper) RemoveChecksum(goCtx context.Context, msg *types.MsgRemoveChecks
5151
}
5252

5353
// unpin the code from the vm in-memory cache
54-
if err := k.wasmVM.Unpin(msg.Checksum); err != nil {
54+
if err := ibcwasm.GetVM().Unpin(msg.Checksum); err != nil {
5555
return nil, errorsmod.Wrapf(err, "failed to unpin contract with checksum (%s) from vm cache", hex.EncodeToString(msg.Checksum))
5656
}
5757

modules/light-clients/08-wasm/keeper/snapshotter.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
1313

14+
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/internal/ibcwasm"
1415
"github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
1516
)
1617

@@ -71,7 +72,7 @@ func (ws *WasmSnapshotter) SnapshotExtension(height uint64, payloadWriter snapsh
7172
}
7273

7374
for _, checksum := range checksums {
74-
wasmCode, err := ws.keeper.wasmVM.GetCode(checksum)
75+
wasmCode, err := ibcwasm.GetVM().GetCode(checksum)
7576
if err != nil {
7677
return err
7778
}
@@ -100,7 +101,7 @@ func (ws *WasmSnapshotter) RestoreExtension(height uint64, format uint32, payloa
100101
return errorsmod.Wrapf(snapshot.ErrUnknownFormat, "expected %d, got %d", ws.SnapshotFormat(), format)
101102
}
102103

103-
func restoreV1(_ sdk.Context, k *Keeper, compressedCode []byte) error {
104+
func restoreV1(_ sdk.Context, _ *Keeper, compressedCode []byte) error {
104105
if !types.IsGzip(compressedCode) {
105106
return errorsmod.Wrap(types.ErrInvalidData, "expected wasm code is not gzip format")
106107
}
@@ -110,12 +111,12 @@ func restoreV1(_ sdk.Context, k *Keeper, compressedCode []byte) error {
110111
return errorsmod.Wrap(err, "failed to uncompress wasm code")
111112
}
112113

113-
checksum, err := k.wasmVM.StoreCodeUnchecked(wasmCode)
114+
checksum, err := ibcwasm.GetVM().StoreCodeUnchecked(wasmCode)
114115
if err != nil {
115116
return errorsmod.Wrap(err, "failed to store wasm code")
116117
}
117118

118-
if err := k.wasmVM.Pin(checksum); err != nil {
119+
if err := ibcwasm.GetVM().Pin(checksum); err != nil {
119120
return errorsmod.Wrapf(err, "failed to pin checksum: %s to in-memory cache", hex.EncodeToString(checksum))
120121
}
121122

0 commit comments

Comments
 (0)