|
1 | 1 | package keeper |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/json" |
5 | 4 | "time" |
6 | 5 |
|
7 | 6 | wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types" |
@@ -37,12 +36,7 @@ func (k Keeper) OnOpenChannel( |
37 | 36 |
|
38 | 37 | sdkCtx := sdk.UnwrapSDKContext(ctx) |
39 | 38 | sdkCtx, discount := k.checkDiscountEligibility(sdkCtx, codeInfo.CodeHash, k.IsPinnedCode(ctx, contractInfo.CodeID)) |
40 | | - msgBz, err := json.Marshal(msg) // this is not great |
41 | | - if err != nil { |
42 | | - // this should never happen, as we just built this message |
43 | | - return "", errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
44 | | - } |
45 | | - setupCost := k.gasRegister.SetupContractCost(discount, len(msgBz)) |
| 39 | + setupCost := k.gasRegister.SetupContractCost(discount, msg.ExpectedJSONSize()) |
46 | 40 | sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-open-channel") |
47 | 41 |
|
48 | 42 | env := types.NewEnv(ctx, contractAddr) |
@@ -91,12 +85,7 @@ func (k Keeper) OnConnectChannel( |
91 | 85 |
|
92 | 86 | sdkCtx := sdk.UnwrapSDKContext(ctx) |
93 | 87 | sdkCtx, discount := k.checkDiscountEligibility(sdkCtx, codeInfo.CodeHash, k.IsPinnedCode(ctx, contractInfo.CodeID)) |
94 | | - msgBz, err := json.Marshal(msg) // this is not great |
95 | | - if err != nil { |
96 | | - // this should never happen, as we just built this message |
97 | | - return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
98 | | - } |
99 | | - setupCost := k.gasRegister.SetupContractCost(discount, len(msgBz)) |
| 88 | + setupCost := k.gasRegister.SetupContractCost(discount, msg.ExpectedJSONSize()) |
100 | 89 | sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-connect-channel") |
101 | 90 |
|
102 | 91 | env := types.NewEnv(ctx, contractAddr) |
@@ -139,12 +128,7 @@ func (k Keeper) OnCloseChannel( |
139 | 128 |
|
140 | 129 | sdkCtx := sdk.UnwrapSDKContext(ctx) |
141 | 130 | sdkCtx, discount := k.checkDiscountEligibility(sdkCtx, codeInfo.CodeHash, k.IsPinnedCode(ctx, contractInfo.CodeID)) |
142 | | - msgBz, err := json.Marshal(msg) // this is not great |
143 | | - if err != nil { |
144 | | - // this should never happen, as we just built this message |
145 | | - return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
146 | | - } |
147 | | - setupCost := k.gasRegister.SetupContractCost(discount, len(msgBz)) |
| 131 | + setupCost := k.gasRegister.SetupContractCost(discount, msg.ExpectedJSONSize()) |
148 | 132 | sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-close-channel") |
149 | 133 |
|
150 | 134 | params := types.NewEnv(ctx, contractAddr) |
@@ -186,12 +170,7 @@ func (k Keeper) OnRecvPacket( |
186 | 170 |
|
187 | 171 | sdkCtx := sdk.UnwrapSDKContext(ctx) |
188 | 172 | sdkCtx, discount := k.checkDiscountEligibility(sdkCtx, codeInfo.CodeHash, k.IsPinnedCode(ctx, contractInfo.CodeID)) |
189 | | - msgBz, err := json.Marshal(msg) // this is not great |
190 | | - if err != nil { |
191 | | - // this should never happen, as we just built this message |
192 | | - return nil, errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
193 | | - } |
194 | | - setupCost := k.gasRegister.SetupContractCost(discount, len(msgBz)) |
| 173 | + setupCost := k.gasRegister.SetupContractCost(discount, msg.ExpectedJSONSize()) |
195 | 174 | sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-recv-packet") |
196 | 175 |
|
197 | 176 | env := types.NewEnv(ctx, contractAddr) |
@@ -269,12 +248,7 @@ func (k Keeper) OnAckPacket( |
269 | 248 |
|
270 | 249 | sdkCtx := sdk.UnwrapSDKContext(ctx) |
271 | 250 | sdkCtx, discount := k.checkDiscountEligibility(sdkCtx, codeInfo.CodeHash, k.IsPinnedCode(ctx, contractInfo.CodeID)) |
272 | | - msgBz, err := json.Marshal(msg) // this is not great |
273 | | - if err != nil { |
274 | | - // this should never happen, as we just built this message |
275 | | - return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
276 | | - } |
277 | | - setupCost := k.gasRegister.SetupContractCost(discount, len(msgBz)) |
| 251 | + setupCost := k.gasRegister.SetupContractCost(discount, msg.ExpectedJSONSize()) |
278 | 252 | sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-ack-packet") |
279 | 253 |
|
280 | 254 | env := types.NewEnv(ctx, contractAddr) |
@@ -314,12 +288,7 @@ func (k Keeper) OnTimeoutPacket( |
314 | 288 |
|
315 | 289 | sdkCtx := sdk.UnwrapSDKContext(ctx) |
316 | 290 | sdkCtx, discount := k.checkDiscountEligibility(sdkCtx, codeInfo.CodeHash, k.IsPinnedCode(ctx, contractInfo.CodeID)) |
317 | | - msgBz, err := json.Marshal(msg) // this is not great |
318 | | - if err != nil { |
319 | | - // this should never happen, as we just built this message |
320 | | - return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
321 | | - } |
322 | | - setupCost := k.gasRegister.SetupContractCost(discount, len(msgBz)) |
| 291 | + setupCost := k.gasRegister.SetupContractCost(discount, msg.ExpectedJSONSize()) |
323 | 292 | sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-timeout-packet") |
324 | 293 |
|
325 | 294 | env := types.NewEnv(ctx, contractAddr) |
@@ -358,12 +327,7 @@ func (k Keeper) IBCSourceCallback( |
358 | 327 |
|
359 | 328 | sdkCtx := sdk.UnwrapSDKContext(ctx) |
360 | 329 | sdkCtx, discount := k.checkDiscountEligibility(sdkCtx, codeInfo.CodeHash, k.IsPinnedCode(ctx, contractInfo.CodeID)) |
361 | | - msgBz, err := json.Marshal(msg) // this is not great |
362 | | - if err != nil { |
363 | | - // this should never happen, as we just built this message |
364 | | - return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
365 | | - } |
366 | | - setupCost := k.gasRegister.SetupContractCost(discount, len(msgBz)) |
| 330 | + setupCost := k.gasRegister.SetupContractCost(discount, msg.ExpectedJSONSize()) |
367 | 331 | sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-source-chain-callback") |
368 | 332 |
|
369 | 333 | env := types.NewEnv(ctx, contractAddr) |
@@ -402,12 +366,7 @@ func (k Keeper) IBCDestinationCallback( |
402 | 366 |
|
403 | 367 | sdkCtx := sdk.UnwrapSDKContext(ctx) |
404 | 368 | sdkCtx, discount := k.checkDiscountEligibility(sdkCtx, codeInfo.CodeHash, k.IsPinnedCode(ctx, contractInfo.CodeID)) |
405 | | - msgBz, err := json.Marshal(msg) // this is not great |
406 | | - if err != nil { |
407 | | - // this should never happen, as we just built this message |
408 | | - return errorsmod.Wrap(types.ErrInvalidMsg, err.Error()) |
409 | | - } |
410 | | - setupCost := k.gasRegister.SetupContractCost(discount, len(msgBz)) |
| 369 | + setupCost := k.gasRegister.SetupContractCost(discount, msg.ExpectedJSONSize()) |
411 | 370 | sdkCtx.GasMeter().ConsumeGas(setupCost, "Loading CosmWasm module: ibc-destination-chain-callback") |
412 | 371 |
|
413 | 372 | env := types.NewEnv(ctx, contractAddr) |
|
0 commit comments