Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Non-Multiplier Gas Meter #46

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/wasm/keeper/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewLimitSimulationGasDecorator(gasLimit *sdk.Gas, gasMeterSetter func(bool,

func DefaultGasMeterSetter() func(bool, sdk.Context, uint64, sdk.Tx) sdk.Context {
return func(simulate bool, ctx sdk.Context, gasLimit uint64, tx sdk.Tx) sdk.Context {
return ctx.WithGasMeter(sdk.NewGasMeter(gasLimit))
return ctx.WithGasMeter(sdk.NewGasMeterWithMultiplier(ctx, gasLimit))
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/legacy_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func queryContractState(ctx sdk.Context, bech, queryMethod string, data []byte,
return keeper.QueryRaw(ctx, contractAddr, data), nil
case QueryMethodContractStateSmart:
// we enforce a subjective gas limit on all queries to avoid infinite loops
ctx = ctx.WithGasMeter(sdk.NewGasMeter(gasLimit))
ctx = ctx.WithGasMeter(sdk.NewGasMeterWithMultiplier(ctx, gasLimit))
msg := types.RawContractMessage(data)
if err := msg.ValidateBasic(); err != nil {
return nil, sdkerrors.Wrap(err, "json msg")
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (d MessageDispatcher) DispatchMessages(ctx sdk.Context, contractAddr sdk.Ac

// dispatchMsgWithGasLimit sends a message with gas limit applied
func (d MessageDispatcher) dispatchMsgWithGasLimit(ctx sdk.Context, contractAddr sdk.AccAddress, ibcPort string, msg wasmvmtypes.CosmosMsg, gasLimit uint64, info wasmvmtypes.MessageInfo, codeInfo types.CodeInfo) (events []sdk.Event, data [][]byte, err error) {
limitedMeter := sdk.NewGasMeter(gasLimit)
limitedMeter := sdk.NewGasMeterWithMultiplier(ctx, gasLimit)
subCtx := ctx.WithGasMeter(limitedMeter)

// catch out of gas panic and just charge the entire gas limit
Expand Down
3 changes: 2 additions & 1 deletion x/wasm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func (q grpcQuerier) SmartContractState(c context.Context, req *types.QuerySmart
if err != nil {
return nil, err
}
ctx := sdk.UnwrapSDKContext(c).WithGasMeter(sdk.NewGasMeter(q.queryGasLimit))
ctx := sdk.UnwrapSDKContext(c)
ctx = ctx.WithGasMeter(sdk.NewGasMeterWithMultiplier(ctx, q.queryGasLimit))
// recover from out-of-gas panic
defer func() {
if r := recover(); r != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/query_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (q QueryHandler) Query(request wasmvmtypes.QueryRequest, gasLimit uint64) (
// set a limit for a subCtx
sdkGas := q.gasRegister.FromWasmVMGas(gasLimit)
// discard all changes/ events in subCtx by not committing the cached context
subCtx, _ := q.Ctx.WithGasMeter(sdk.NewGasMeter(sdkGas)).CacheContext()
subCtx, _ := q.Ctx.WithGasMeter(sdk.NewGasMeterWithMultiplier(q.Ctx, sdkGas)).CacheContext()

// make sure we charge the higher level context even on panic
defer func() {
Expand Down
Loading