Skip to content

Commit 208e314

Browse files
committed
fix: fixed compiler complaints
1 parent b45b605 commit 208e314

File tree

5 files changed

+40
-39
lines changed

5 files changed

+40
-39
lines changed

modules/light-clients/08-wasm/internal/ibcwasm/gas_register.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
package types
1+
package ibcwasm
22

33
import (
4+
"errors"
5+
46
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
57

68
errorsmod "cosmossdk.io/errors"
@@ -160,23 +162,23 @@ func (g WasmGasRegister) NewContractInstanceCosts(pinned bool, msgLen int) store
160162
// CompileCosts costs to persist and "compile" a new wasm contract
161163
func (g WasmGasRegister) CompileCosts(byteLength int) storetypes.Gas {
162164
if byteLength < 0 {
163-
panic(errorsmod.Wrap(ErrInvalid, "negative length"))
165+
panic(errors.New("negative length"))
164166
}
165167
return g.c.CompileCost * uint64(byteLength)
166168
}
167169

168170
// UncompressCosts costs to unpack a new wasm contract
169171
func (g WasmGasRegister) UncompressCosts(byteLength int) storetypes.Gas {
170172
if byteLength < 0 {
171-
panic(errorsmod.Wrap(ErrInvalid, "negative length"))
173+
panic(errors.New("negative length"))
172174
}
173175
return g.c.UncompressCost.Mul(uint64(byteLength)).Floor()
174176
}
175177

176178
// InstantiateContractCosts costs when interacting with a wasm contract
177179
func (g WasmGasRegister) InstantiateContractCosts(pinned bool, msgLen int) storetypes.Gas {
178180
if msgLen < 0 {
179-
panic(errorsmod.Wrap(ErrInvalid, "negative length"))
181+
panic(errors.New("negative length"))
180182
}
181183
dataCosts := storetypes.Gas(msgLen) * g.c.ContractMessageDataCost
182184
if pinned {

modules/light-clients/08-wasm/internal/ibcwasm/gas_register_custom.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package types
1+
package ibcwasm
22

33
import (
44
"math"
@@ -19,12 +19,12 @@ const (
1919
DefaultDeserializationCostPerByte = 1
2020
)
2121

22-
var costJSONDeserialization = wasmvmtypes.UFraction{
22+
var CostJSONDeserialization = wasmvmtypes.UFraction{
2323
Numerator: DefaultDeserializationCostPerByte * DefaultGasMultiplier,
2424
Denominator: 1,
2525
}
2626

27-
func (g WasmGasRegister) runtimeGasForContract(ctx sdk.Context) uint64 {
27+
func (g WasmGasRegister) RuntimeGasForContract(ctx sdk.Context) uint64 {
2828
meter := ctx.GasMeter()
2929
if meter.IsOutOfGas() {
3030
return 0
@@ -36,7 +36,7 @@ func (g WasmGasRegister) runtimeGasForContract(ctx sdk.Context) uint64 {
3636
return g.ToWasmVMGas(meter.Limit() - meter.GasConsumedToLimit())
3737
}
3838

39-
func (g WasmGasRegister) consumeRuntimeGas(ctx sdk.Context, gas uint64) {
39+
func (g WasmGasRegister) ConsumeRuntimeGas(ctx sdk.Context, gas uint64) {
4040
consumed := g.FromWasmVMGas(gas)
4141
ctx.GasMeter().ConsumeGas(consumed, "wasm contract")
4242
// throw OutOfGas error if we ran out (got exactly to zero due to better limit enforcing)

modules/light-clients/08-wasm/internal/ibcwasm/wasm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var (
1414

1515
querier wasmvm.Querier
1616

17+
VMGasRegister = NewDefaultWasmGasRegister()
18+
1719
// state management
1820
Schema collections.Schema
1921
Checksums collections.KeySet[[]byte]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (Keeper) Logger(ctx sdk.Context) log.Logger {
106106
func (Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wasmvm.WasmCode) (wasmvm.Checksum, error)) ([]byte, error) {
107107
var err error
108108
if types.IsGzip(code) {
109-
ctx.GasMeter().ConsumeGas(types.VMGasRegister.UncompressCosts(len(code)), "Uncompress gzip bytecode")
109+
ctx.GasMeter().ConsumeGas(ibcwasm.VMGasRegister.UncompressCosts(len(code)), "Uncompress gzip bytecode")
110110
code, err = types.Uncompress(code, types.MaxWasmByteSize())
111111
if err != nil {
112112
return nil, errorsmod.Wrap(err, "failed to store contract")
@@ -129,7 +129,7 @@ func (Keeper) storeWasmCode(ctx sdk.Context, code []byte, storeFn func(code wasm
129129
}
130130

131131
// create the code in the vm
132-
ctx.GasMeter().ConsumeGas(types.VMGasRegister.CompileCosts(len(code)), "Compiling wasm bytecode")
132+
ctx.GasMeter().ConsumeGas(ibcwasm.VMGasRegister.CompileCosts(len(code)), "Compiling wasm bytecode")
133133
vmChecksum, err := storeFn(code)
134134
if err != nil {
135135
return nil, errorsmod.Wrap(err, "failed to store contract")

modules/light-clients/08-wasm/types/vm.go

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,18 @@ import (
2121
"github.com/cosmos/ibc-go/v8/modules/core/exported"
2222
)
2323

24-
var (
25-
VMGasRegister = NewDefaultWasmGasRegister()
26-
// wasmvmAPI is a wasmvm.GoAPI implementation that is passed to the wasmvm, it
27-
// doesn't implement any functionality, directly returning an error.
28-
wasmvmAPI = wasmvm.GoAPI{
29-
HumanAddress: humanAddress,
30-
CanonicalAddress: canonicalAddress,
31-
}
32-
)
24+
// wasmvmAPI is a wasmvm.GoAPI implementation that is passed to the wasmvm, it
25+
// doesn't implement any functionality, directly returning an error.
26+
var wasmvmAPI = wasmvm.GoAPI{
27+
HumanAddress: humanAddress,
28+
CanonicalAddress: canonicalAddress,
29+
}
3330

3431
// instantiateContract calls vm.Instantiate with appropriate arguments.
3532
func instantiateContract(ctx sdk.Context, clientStore storetypes.KVStore, checksum Checksum, msg []byte) (*wasmvmtypes.Response, error) {
3633
sdkGasMeter := ctx.GasMeter()
37-
multipliedGasMeter := NewMultipliedGasMeter(sdkGasMeter, VMGasRegister)
38-
gasLimit := VMGasRegister.runtimeGasForContract(ctx)
34+
multipliedGasMeter := ibcwasm.NewMultipliedGasMeter(sdkGasMeter, ibcwasm.VMGasRegister)
35+
gasLimit := ibcwasm.VMGasRegister.RuntimeGasForContract(ctx)
3936

4037
clientID, err := getClientID(clientStore)
4138
if err != nil {
@@ -48,59 +45,59 @@ func instantiateContract(ctx sdk.Context, clientStore storetypes.KVStore, checks
4845
Funds: nil,
4946
}
5047

51-
ctx.GasMeter().ConsumeGas(VMGasRegister.NewContractInstanceCosts(true, len(msg)), "Loading CosmWasm module: instantiate")
52-
response, gasUsed, err := ibcwasm.GetVM().Instantiate(checksum, env, msgInfo, msg, newStoreAdapter(clientStore), wasmvmAPI, ibcwasm.GetQuerier(), multipliedGasMeter, gasLimit, costJSONDeserialization)
53-
VMGasRegister.consumeRuntimeGas(ctx, gasUsed)
48+
ctx.GasMeter().ConsumeGas(ibcwasm.VMGasRegister.NewContractInstanceCosts(true, len(msg)), "Loading CosmWasm module: instantiate")
49+
response, gasUsed, err := ibcwasm.GetVM().Instantiate(checksum, env, msgInfo, msg, newStoreAdapter(clientStore), wasmvmAPI, ibcwasm.GetQuerier(), multipliedGasMeter, gasLimit, ibcwasm.CostJSONDeserialization)
50+
ibcwasm.VMGasRegister.ConsumeRuntimeGas(ctx, gasUsed)
5451
return response, err
5552
}
5653

5754
// callContract calls vm.Sudo with internally constructed gas meter and environment.
5855
func callContract(ctx sdk.Context, clientStore storetypes.KVStore, checksum Checksum, msg []byte) (*wasmvmtypes.Response, error) {
5956
sdkGasMeter := ctx.GasMeter()
60-
multipliedGasMeter := NewMultipliedGasMeter(sdkGasMeter, VMGasRegister)
61-
gasLimit := VMGasRegister.runtimeGasForContract(ctx)
57+
multipliedGasMeter := ibcwasm.NewMultipliedGasMeter(sdkGasMeter, ibcwasm.VMGasRegister)
58+
gasLimit := ibcwasm.VMGasRegister.RuntimeGasForContract(ctx)
6259

6360
clientID, err := getClientID(clientStore)
6461
if err != nil {
6562
return nil, errorsmod.Wrap(err, "failed to retrieve clientID for wasm contract call")
6663
}
6764
env := getEnv(ctx, clientID)
6865

69-
ctx.GasMeter().ConsumeGas(VMGasRegister.InstantiateContractCosts(true, len(msg)), "Loading CosmWasm module: sudo")
70-
resp, gasUsed, err := ibcwasm.GetVM().Sudo(checksum, env, msg, newStoreAdapter(clientStore), wasmvmAPI, ibcwasm.GetQuerier(), multipliedGasMeter, gasLimit, costJSONDeserialization)
71-
VMGasRegister.consumeRuntimeGas(ctx, gasUsed)
66+
ctx.GasMeter().ConsumeGas(ibcwasm.VMGasRegister.InstantiateContractCosts(true, len(msg)), "Loading CosmWasm module: sudo")
67+
resp, gasUsed, err := ibcwasm.GetVM().Sudo(checksum, env, msg, newStoreAdapter(clientStore), wasmvmAPI, ibcwasm.GetQuerier(), multipliedGasMeter, gasLimit, ibcwasm.CostJSONDeserialization)
68+
ibcwasm.VMGasRegister.ConsumeRuntimeGas(ctx, gasUsed)
7269
return resp, err
7370
}
7471

7572
// migrateContract calls vm.Migrate with internally constructed gas meter and environment.
7673
func migrateContract(ctx sdk.Context, clientID string, clientStore storetypes.KVStore, checksum Checksum, msg []byte) (*wasmvmtypes.Response, error) {
7774
sdkGasMeter := ctx.GasMeter()
78-
multipliedGasMeter := NewMultipliedGasMeter(sdkGasMeter, VMGasRegister)
79-
gasLimit := VMGasRegister.runtimeGasForContract(ctx)
75+
multipliedGasMeter := ibcwasm.NewMultipliedGasMeter(sdkGasMeter, ibcwasm.VMGasRegister)
76+
gasLimit := ibcwasm.VMGasRegister.RuntimeGasForContract(ctx)
8077

8178
env := getEnv(ctx, clientID)
8279

83-
ctx.GasMeter().ConsumeGas(VMGasRegister.InstantiateContractCosts(true, len(msg)), "Loading CosmWasm module: migrate")
84-
resp, gasUsed, err := ibcwasm.GetVM().Migrate(checksum, env, msg, newStoreAdapter(clientStore), wasmvmAPI, ibcwasm.GetQuerier(), multipliedGasMeter, gasLimit, costJSONDeserialization)
85-
VMGasRegister.consumeRuntimeGas(ctx, gasUsed)
80+
ctx.GasMeter().ConsumeGas(ibcwasm.VMGasRegister.InstantiateContractCosts(true, len(msg)), "Loading CosmWasm module: migrate")
81+
resp, gasUsed, err := ibcwasm.GetVM().Migrate(checksum, env, msg, newStoreAdapter(clientStore), wasmvmAPI, ibcwasm.GetQuerier(), multipliedGasMeter, gasLimit, ibcwasm.CostJSONDeserialization)
82+
ibcwasm.VMGasRegister.ConsumeRuntimeGas(ctx, gasUsed)
8683
return resp, err
8784
}
8885

8986
// queryContract calls vm.Query.
9087
func queryContract(ctx sdk.Context, clientStore storetypes.KVStore, checksum Checksum, msg []byte) ([]byte, error) {
9188
sdkGasMeter := ctx.GasMeter()
92-
multipliedGasMeter := NewMultipliedGasMeter(sdkGasMeter, VMGasRegister)
93-
gasLimit := VMGasRegister.runtimeGasForContract(ctx)
89+
multipliedGasMeter := ibcwasm.NewMultipliedGasMeter(sdkGasMeter, ibcwasm.VMGasRegister)
90+
gasLimit := ibcwasm.VMGasRegister.RuntimeGasForContract(ctx)
9491

9592
clientID, err := getClientID(clientStore)
9693
if err != nil {
9794
return nil, errorsmod.Wrap(err, "failed to retrieve clientID for wasm contract query")
9895
}
9996
env := getEnv(ctx, clientID)
10097

101-
ctx.GasMeter().ConsumeGas(VMGasRegister.InstantiateContractCosts(true, len(msg)), "Loading CosmWasm module: query")
102-
resp, gasUsed, err := ibcwasm.GetVM().Query(checksum, env, msg, newStoreAdapter(clientStore), wasmvmAPI, ibcwasm.GetQuerier(), multipliedGasMeter, gasLimit, costJSONDeserialization)
103-
VMGasRegister.consumeRuntimeGas(ctx, gasUsed)
98+
ctx.GasMeter().ConsumeGas(ibcwasm.VMGasRegister.InstantiateContractCosts(true, len(msg)), "Loading CosmWasm module: query")
99+
resp, gasUsed, err := ibcwasm.GetVM().Query(checksum, env, msg, newStoreAdapter(clientStore), wasmvmAPI, ibcwasm.GetQuerier(), multipliedGasMeter, gasLimit, ibcwasm.CostJSONDeserialization)
100+
ibcwasm.VMGasRegister.ConsumeRuntimeGas(ctx, gasUsed)
104101
return resp, err
105102
}
106103

0 commit comments

Comments
 (0)