|
1 | 1 | package keeper |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "time" |
5 | 6 |
|
6 | 7 | wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types" |
@@ -29,11 +30,20 @@ func (k Keeper) OnOpenChannel( |
29 | 30 | msg wasmvmtypes.IBCChannelOpenMsg, |
30 | 31 | ) (string, error) { |
31 | 32 | defer telemetry.MeasureSince(time.Now(), "wasm", "contract", "ibc-open-channel") |
32 | | - _, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddr) |
| 33 | + contractInfo, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddr) |
33 | 34 | if err != nil { |
34 | 35 | return "", err |
35 | 36 | } |
36 | 37 |
|
| 38 | + msgBz, err := json.Marshal(msg) // this is not great |
| 39 | + if err != nil { |
| 40 | + // this should never happen, as we just built this message |
| 41 | + return "", errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
| 42 | + } |
| 43 | + sdkCtx := sdk.UnwrapSDKContext(ctx) |
| 44 | + setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(ctx, contractInfo.CodeID), len(msgBz)) |
| 45 | + sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-open-channel") |
| 46 | + |
37 | 47 | env := types.NewEnv(ctx, contractAddr) |
38 | 48 | querier := k.newQueryHandler(ctx, contractAddr) |
39 | 49 |
|
@@ -78,6 +88,15 @@ func (k Keeper) OnConnectChannel( |
78 | 88 | return err |
79 | 89 | } |
80 | 90 |
|
| 91 | + msgBz, err := json.Marshal(msg) // this is not great |
| 92 | + if err != nil { |
| 93 | + // this should never happen, as we just built this message |
| 94 | + return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
| 95 | + } |
| 96 | + sdkCtx := sdk.UnwrapSDKContext(ctx) |
| 97 | + setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(ctx, contractInfo.CodeID), len(msgBz)) |
| 98 | + sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-connect-channel") |
| 99 | + |
81 | 100 | env := types.NewEnv(ctx, contractAddr) |
82 | 101 | querier := k.newQueryHandler(ctx, contractAddr) |
83 | 102 |
|
@@ -116,6 +135,15 @@ func (k Keeper) OnCloseChannel( |
116 | 135 | return err |
117 | 136 | } |
118 | 137 |
|
| 138 | + msgBz, err := json.Marshal(msg) // this is not great |
| 139 | + if err != nil { |
| 140 | + // this should never happen, as we just built this message |
| 141 | + return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
| 142 | + } |
| 143 | + sdkCtx := sdk.UnwrapSDKContext(ctx) |
| 144 | + setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(ctx, contractInfo.CodeID), len(msgBz)) |
| 145 | + sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-close-channel") |
| 146 | + |
119 | 147 | params := types.NewEnv(ctx, contractAddr) |
120 | 148 | querier := k.newQueryHandler(ctx, contractAddr) |
121 | 149 |
|
@@ -153,6 +181,15 @@ func (k Keeper) OnRecvPacket( |
153 | 181 | return nil, err |
154 | 182 | } |
155 | 183 |
|
| 184 | + msgBz, err := json.Marshal(msg) // this is not great |
| 185 | + if err != nil { |
| 186 | + // this should never happen, as we just built this message |
| 187 | + return nil, errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
| 188 | + } |
| 189 | + sdkCtx := sdk.UnwrapSDKContext(ctx) |
| 190 | + setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(ctx, contractInfo.CodeID), len(msgBz)) |
| 191 | + sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-recv-packet") |
| 192 | + |
156 | 193 | env := types.NewEnv(ctx, contractAddr) |
157 | 194 | querier := k.newQueryHandler(ctx, contractAddr) |
158 | 195 |
|
@@ -226,6 +263,15 @@ func (k Keeper) OnAckPacket( |
226 | 263 | return err |
227 | 264 | } |
228 | 265 |
|
| 266 | + msgBz, err := json.Marshal(msg) // this is not great |
| 267 | + if err != nil { |
| 268 | + // this should never happen, as we just built this message |
| 269 | + return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
| 270 | + } |
| 271 | + sdkCtx := sdk.UnwrapSDKContext(ctx) |
| 272 | + setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(ctx, contractInfo.CodeID), len(msgBz)) |
| 273 | + sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-ack-packet") |
| 274 | + |
229 | 275 | env := types.NewEnv(ctx, contractAddr) |
230 | 276 | querier := k.newQueryHandler(ctx, contractAddr) |
231 | 277 |
|
@@ -261,6 +307,15 @@ func (k Keeper) OnTimeoutPacket( |
261 | 307 | return err |
262 | 308 | } |
263 | 309 |
|
| 310 | + msgBz, err := json.Marshal(msg) // this is not great |
| 311 | + if err != nil { |
| 312 | + // this should never happen, as we just built this message |
| 313 | + return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
| 314 | + } |
| 315 | + sdkCtx := sdk.UnwrapSDKContext(ctx) |
| 316 | + setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(ctx, contractInfo.CodeID), len(msgBz)) |
| 317 | + sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-timeout-packet") |
| 318 | + |
264 | 319 | env := types.NewEnv(ctx, contractAddr) |
265 | 320 | querier := k.newQueryHandler(ctx, contractAddr) |
266 | 321 |
|
@@ -295,6 +350,15 @@ func (k Keeper) IBCSourceCallback( |
295 | 350 | return err |
296 | 351 | } |
297 | 352 |
|
| 353 | + msgBz, err := json.Marshal(msg) // this is not great |
| 354 | + if err != nil { |
| 355 | + // this should never happen, as we just built this message |
| 356 | + return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
| 357 | + } |
| 358 | + sdkCtx := sdk.UnwrapSDKContext(ctx) |
| 359 | + setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(ctx, contractInfo.CodeID), len(msgBz)) |
| 360 | + sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-source-chain-callback") |
| 361 | + |
298 | 362 | env := types.NewEnv(ctx, contractAddr) |
299 | 363 | querier := k.newQueryHandler(ctx, contractAddr) |
300 | 364 |
|
@@ -329,6 +393,15 @@ func (k Keeper) IBCDestinationCallback( |
329 | 393 | return err |
330 | 394 | } |
331 | 395 |
|
| 396 | + msgBz, err := json.Marshal(msg) // this is not great |
| 397 | + if err != nil { |
| 398 | + // this should never happen, as we just built this message |
| 399 | + return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
| 400 | + } |
| 401 | + sdkCtx := sdk.UnwrapSDKContext(ctx) |
| 402 | + setupCost := k.gasRegister.SetupContractCost(k.IsPinnedCode(ctx, contractInfo.CodeID), len(msgBz)) |
| 403 | + sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-destination-chain-callback") |
| 404 | + |
332 | 405 | env := types.NewEnv(ctx, contractAddr) |
333 | 406 | querier := k.newQueryHandler(ctx, contractAddr) |
334 | 407 |
|
|
0 commit comments