Skip to content

Commit f44bc8a

Browse files
committed
Adjust SmartContractState query gas limit
1 parent 5b1b179 commit f44bc8a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

x/wasm/keeper/querier.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ func (q GrpcQuerier) SmartContractState(c context.Context, req *types.QuerySmart
200200
if err != nil {
201201
return nil, err
202202
}
203-
ctx := sdk.UnwrapSDKContext(c).WithGasMeter(storetypes.NewGasMeter(q.queryGasLimit))
203+
204+
// limit the gas to the queryGasLimit or the remaining gas, whichever is smaller
205+
ctx := sdk.UnwrapSDKContext(c)
206+
gasLimit := min(uint64(ctx.GasMeter().GasRemaining()), q.queryGasLimit)
207+
ctx = ctx.WithGasMeter(storetypes.NewGasMeter(gasLimit))
204208
// recover from out-of-gas panic
205209
defer func() {
206210
if r := recover(); r != nil {

0 commit comments

Comments
 (0)