@@ -29,24 +29,40 @@ func (k Keeper) OnOpenChannel(
29
29
msg wasmvmtypes.IBCChannelOpenMsg ,
30
30
) (string , error ) {
31
31
defer telemetry .MeasureSince (time .Now (), "wasm" , "contract" , "ibc-open-channel" )
32
- _ , codeInfo , prefixStore , err := k .contractInstance (ctx , contractAddr )
32
+ contractInfo , codeInfo , prefixStore , err := k .contractInstance (ctx , contractAddr )
33
33
if err != nil {
34
34
return "" , err
35
35
}
36
36
37
+ sdkCtx := sdk .UnwrapSDKContext (ctx )
38
+ sdkCtx , discount := k .checkDiscountEligibility (sdkCtx , codeInfo .CodeHash , k .IsPinnedCode (ctx , contractInfo .CodeID ))
39
+ setupCost := k .gasRegister .SetupContractCost (discount , msg .ExpectedJSONSize ())
40
+ sdkCtx .GasMeter ().ConsumeGas (setupCost , "Loading CosmWasm module: ibc-open-channel" )
41
+
37
42
env := types .NewEnv (ctx , k .txHash , contractAddr )
38
43
querier := k .newQueryHandler (ctx , contractAddr )
39
44
40
45
gasLeft := k .runtimeGasForContract (ctx )
41
46
res , gasUsed , execErr := k .wasmVM .IBCChannelOpen (codeInfo .CodeHash , env , msg , prefixStore , cosmwasmAPI , querier , ctx .GasMeter (), gasLeft , costJSONDeserialization )
42
47
k .consumeRuntimeGas (ctx , gasUsed )
48
+ // check if contract panicked / VM failed
43
49
if execErr != nil {
44
50
return "" , errorsmod .Wrap (types .ErrExecuteFailed , execErr .Error ())
45
51
}
46
- if res != nil && res .Ok != nil {
47
- return res .Ok .Version , nil
52
+ if res == nil {
53
+ // If this gets executed, that's a bug in wasmvm
54
+ return "" , errorsmod .Wrap (types .ErrVMError , "internal wasmvm error" )
55
+ }
56
+ // check contract result
57
+ if res .Err != "" {
58
+ return "" , types .MarkErrorDeterministic (errorsmod .Wrap (types .ErrExecuteFailed , res .Err ))
59
+ }
60
+ if res .Ok == nil {
61
+ // a nil "ok" value is a valid response and means the contract accepts the incoming channel version
62
+ // see https://docs.rs/cosmwasm-std/2.2.2/cosmwasm_std/type.IbcChannelOpenResponse.html
63
+ return "" , nil
48
64
}
49
- return "" , nil
65
+ return res . Ok . Version , nil
50
66
}
51
67
52
68
// OnConnectChannel calls the contract to let it know the IBC channel was established.
@@ -67,6 +83,11 @@ func (k Keeper) OnConnectChannel(
67
83
return err
68
84
}
69
85
86
+ sdkCtx := sdk .UnwrapSDKContext (ctx )
87
+ sdkCtx , discount := k .checkDiscountEligibility (sdkCtx , codeInfo .CodeHash , k .IsPinnedCode (ctx , contractInfo .CodeID ))
88
+ setupCost := k .gasRegister .SetupContractCost (discount , msg .ExpectedJSONSize ())
89
+ sdkCtx .GasMeter ().ConsumeGas (setupCost , "Loading CosmWasm module: ibc-connect-channel" )
90
+
70
91
env := types .NewEnv (ctx , k .txHash , contractAddr )
71
92
querier := k .newQueryHandler (ctx , contractAddr )
72
93
@@ -105,6 +126,11 @@ func (k Keeper) OnCloseChannel(
105
126
return err
106
127
}
107
128
129
+ sdkCtx := sdk .UnwrapSDKContext (ctx )
130
+ sdkCtx , discount := k .checkDiscountEligibility (sdkCtx , codeInfo .CodeHash , k .IsPinnedCode (ctx , contractInfo .CodeID ))
131
+ setupCost := k .gasRegister .SetupContractCost (discount , msg .ExpectedJSONSize ())
132
+ sdkCtx .GasMeter ().ConsumeGas (setupCost , "Loading CosmWasm module: ibc-close-channel" )
133
+
108
134
params := types .NewEnv (ctx , k .txHash , contractAddr )
109
135
querier := k .newQueryHandler (ctx , contractAddr )
110
136
@@ -142,6 +168,11 @@ func (k Keeper) OnRecvPacket(
142
168
return nil , err
143
169
}
144
170
171
+ sdkCtx := sdk .UnwrapSDKContext (ctx )
172
+ sdkCtx , discount := k .checkDiscountEligibility (sdkCtx , codeInfo .CodeHash , k .IsPinnedCode (ctx , contractInfo .CodeID ))
173
+ setupCost := k .gasRegister .SetupContractCost (discount , msg .ExpectedJSONSize ())
174
+ sdkCtx .GasMeter ().ConsumeGas (setupCost , "Loading CosmWasm module: ibc-recv-packet" )
175
+
145
176
env := types .NewEnv (ctx , k .txHash , contractAddr )
146
177
querier := k .newQueryHandler (ctx , contractAddr )
147
178
@@ -215,6 +246,11 @@ func (k Keeper) OnAckPacket(
215
246
return err
216
247
}
217
248
249
+ sdkCtx := sdk .UnwrapSDKContext (ctx )
250
+ sdkCtx , discount := k .checkDiscountEligibility (sdkCtx , codeInfo .CodeHash , k .IsPinnedCode (ctx , contractInfo .CodeID ))
251
+ setupCost := k .gasRegister .SetupContractCost (discount , msg .ExpectedJSONSize ())
252
+ sdkCtx .GasMeter ().ConsumeGas (setupCost , "Loading CosmWasm module: ibc-ack-packet" )
253
+
218
254
env := types .NewEnv (ctx , k .txHash , contractAddr )
219
255
querier := k .newQueryHandler (ctx , contractAddr )
220
256
@@ -250,6 +286,11 @@ func (k Keeper) OnTimeoutPacket(
250
286
return err
251
287
}
252
288
289
+ sdkCtx := sdk .UnwrapSDKContext (ctx )
290
+ sdkCtx , discount := k .checkDiscountEligibility (sdkCtx , codeInfo .CodeHash , k .IsPinnedCode (ctx , contractInfo .CodeID ))
291
+ setupCost := k .gasRegister .SetupContractCost (discount , msg .ExpectedJSONSize ())
292
+ sdkCtx .GasMeter ().ConsumeGas (setupCost , "Loading CosmWasm module: ibc-timeout-packet" )
293
+
253
294
env := types .NewEnv (ctx , k .txHash , contractAddr )
254
295
querier := k .newQueryHandler (ctx , contractAddr )
255
296
@@ -284,6 +325,11 @@ func (k Keeper) IBCSourceCallback(
284
325
return err
285
326
}
286
327
328
+ sdkCtx := sdk .UnwrapSDKContext (ctx )
329
+ sdkCtx , discount := k .checkDiscountEligibility (sdkCtx , codeInfo .CodeHash , k .IsPinnedCode (ctx , contractInfo .CodeID ))
330
+ setupCost := k .gasRegister .SetupContractCost (discount , msg .ExpectedJSONSize ())
331
+ sdkCtx .GasMeter ().ConsumeGas (setupCost , "Loading CosmWasm module: ibc-source-chain-callback" )
332
+
287
333
env := types .NewEnv (ctx , k .txHash , contractAddr )
288
334
querier := k .newQueryHandler (ctx , contractAddr )
289
335
@@ -318,6 +364,11 @@ func (k Keeper) IBCDestinationCallback(
318
364
return err
319
365
}
320
366
367
+ sdkCtx := sdk .UnwrapSDKContext (ctx )
368
+ sdkCtx , discount := k .checkDiscountEligibility (sdkCtx , codeInfo .CodeHash , k .IsPinnedCode (ctx , contractInfo .CodeID ))
369
+ setupCost := k .gasRegister .SetupContractCost (discount , msg .ExpectedJSONSize ())
370
+ sdkCtx .GasMeter ().ConsumeGas (setupCost , "Loading CosmWasm module: ibc-destination-chain-callback" )
371
+
321
372
env := types .NewEnv (ctx , k .txHash , contractAddr )
322
373
querier := k .newQueryHandler (ctx , contractAddr )
323
374
0 commit comments