Skip to content

Commit

Permalink
fix(logic)!: remove max gas module parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Jul 24, 2024
1 parent e354a2d commit db9164b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 171 deletions.
10 changes: 0 additions & 10 deletions proto/logic/v1beta2/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ message Params {
message Limits {
option (gogoproto.goproto_stringer) = true;

// max_gas specifies the maximum amount of computing power, measured in "gas," that is allowed to be consumed when
// executing a request by the interpreter. The interpreter calculates the gas consumption based on the number and type
// of operations that are executed, as well as, in some cases, the complexity of the processed data.
// nil value remove max gas limitation.
string max_gas = 1 [
(gogoproto.moretags) = "yaml:\"max_gas\",omitempty",
(gogoproto.customtype) = "cosmossdk.io/math.Uint",
(gogoproto.nullable) = true
];

// max_size specifies the maximum size, in bytes, that is accepted for a program.
// nil value remove size limitation.
string max_size = 3 [
Expand Down
22 changes: 10 additions & 12 deletions x/logic/keeper/grpc_query_ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
goctx "context"


errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
Expand All @@ -17,18 +18,11 @@ import (
var defaultSolutionsLimit = sdkmath.OneUint()

func (k Keeper) Ask(ctx goctx.Context, req *types.QueryServiceAskRequest) (response *types.QueryServiceAskResponse, err error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

if req == nil {
return nil, errorsmod.Wrap(types.InvalidArgument, "request is nil")
}

limits := k.limits(ctx)
if err := checkLimits(req, limits); err != nil {
return nil, err
}

sdkCtx = withGasMeter(sdkCtx, limits)
sdkCtx := withSafeGasMeter(sdk.UnwrapSDKContext(ctx))
defer func() {
if r := recover(); r != nil {
if gasError, ok := r.(storetypes.ErrorOutOfGas); ok {
Expand All @@ -42,7 +36,11 @@ func (k Keeper) Ask(ctx goctx.Context, req *types.QueryServiceAskRequest) (respo
panic(r)
}
}()
sdkCtx.GasMeter().ConsumeGas(sdkCtx.GasMeter().GasConsumed(), types.ModuleName)

limits := k.limits(ctx)
if err := checkLimits(req, limits); err != nil {
return nil, err
}

return k.execute(
sdkCtx,
Expand All @@ -51,10 +49,10 @@ func (k Keeper) Ask(ctx goctx.Context, req *types.QueryServiceAskRequest) (respo
util.DerefOrDefault(req.Limit, defaultSolutionsLimit))
}

// withGasMeter returns a new context with a gas meter that has the given limit.
// withSafeGasMeter returns a new context with a gas meter that has the given limit.
// The gas meter is go-router-safe.
func withGasMeter(sdkCtx sdk.Context, limits types.Limits) sdk.Context {
gasMeter := meter.WithSafeMeter(storetypes.NewGasMeter(limits.MaxGas.Uint64()))
func withSafeGasMeter(sdkCtx sdk.Context) sdk.Context {
gasMeter := meter.WithSafeMeter(sdkCtx.GasMeter())

return sdkCtx.WithGasMeter(gasMeter)
}
3 changes: 0 additions & 3 deletions x/logic/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package types

// DefaultIndex is the default global index.
const DefaultIndex uint64 = 1

// DefaultGenesis returns the default genesis state.
func DefaultGenesis() *GenesisState {
return &GenesisState{
Expand Down
17 changes: 1 addition & 16 deletions x/logic/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ import (

// Parameter store keys.
var (
ParamsKey = []byte("Params")
KeyInterpreter = []byte("Interpreter")
KeyLimits = []byte("Limits")
ParamsKey = []byte("Params")
)

var (
DefaultPredicatesWhitelist = make([]string, 0)
DefaultPredicatesBlacklist = make([]string, 0)
DefaultBootstrap = ""
DefaultMaxGas = math.NewUint(uint64(100000))
DefaultMaxSize = math.NewUint(uint64(5000))
DefaultMaxResultCount = math.NewUint(uint64(1))
)
Expand Down Expand Up @@ -129,13 +125,6 @@ func validateInterpreter(i interface{}) error {
// LimitsOption is a functional option for configuring the Limits.
type LimitsOption func(*Limits)

// WithMaxGas sets the max gas limits for interpreter.
func WithMaxGas(maxGas math.Uint) LimitsOption {
return func(i *Limits) {
i.MaxGas = &maxGas
}
}

// WithMaxSize sets the max size limits accepted for a prolog program.
func WithMaxSize(maxSize math.Uint) LimitsOption {
return func(i *Limits) {
Expand Down Expand Up @@ -164,10 +153,6 @@ func NewLimits(opts ...LimitsOption) Limits {
opt(&l)
}

if l.MaxGas == nil {
l.MaxGas = &DefaultMaxGas
}

if l.MaxSize == nil {
l.MaxSize = &DefaultMaxSize
}
Expand Down
153 changes: 47 additions & 106 deletions x/logic/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions x/logic/types/params_legacy.go

This file was deleted.

0 comments on commit db9164b

Please sign in to comment.