Skip to content
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
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ require (
github.com/firefart/nonamedreturns v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fzipp/gocyclo v0.5.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gin-gonic/gin v1.7.7 // indirect
github.com/go-critic/go-critic v0.6.3 // indirect
github.com/go-kit/kit v0.12.0 // indirect
Expand Down Expand Up @@ -142,7 +141,6 @@ require (
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
Expand Down Expand Up @@ -209,7 +207,6 @@ require (
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/rs/xid v1.3.0 // indirect
github.com/ryancurrah/gomodguard v1.2.3 // indirect
github.com/ryanrolds/sqlclosecheck v0.3.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ github.com/fullstorydev/grpcurl v1.6.0/go.mod h1:ZQ+ayqbKMJNhzLmbpCiurTVlaK2M/3n
github.com/fzipp/gocyclo v0.5.1 h1:L66amyuYogbxl0j2U+vGqJXusPF2IkduvXLnYD5TFgw=
github.com/fzipp/gocyclo v0.5.1/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand Down Expand Up @@ -681,8 +679,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 h1:t7uX3JBHdVwAi3G7sSSdbsk8NfgA+LnUS88V/2EKaA0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0/go.mod h1:4OGVnY4qf2+gw+ssiHbW+pq4mo2yko94YxxMmXZ7jCA=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
Expand Down
8 changes: 8 additions & 0 deletions proto/dex/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
uint64 begin_block_gas_limit = 3 [
(gogoproto.jsontag) = "begin_block_gas_limit",
(gogoproto.moretags) = "yaml:\"begin_block_gas_limit\""
];
uint64 end_block_gas_limit = 4 [
(gogoproto.jsontag) = "end_block_gas_limit",
(gogoproto.moretags) = "yaml:\"end_block_gas_limit\""
];
}
6 changes: 3 additions & 3 deletions x/dex/contract/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func EndBlockerAtomic(ctx sdk.Context, keeper *keeper.Keeper, validContractsInfo
spanCtx, span := (*tracer).Start(tracingInfo.TracerContext, "DexEndBlockerAtomic")
defer span.End()
env := newEnv(ctx, validContractsInfo, keeper)
cachedCtx, msCached := cacheAndDecorateContext(ctx, env)
cachedCtx, msCached := cacheAndDecorateContext(ctx, env, keeper.GetParams(ctx).EndBlockGasLimit)
memStateCopy := dexutils.GetMemState(cachedCtx.Context()).DeepCopy()

handleDeposits(cachedCtx, env, keeper, tracer)
Expand Down Expand Up @@ -99,11 +99,11 @@ func newEnv(ctx sdk.Context, validContractsInfo []types.ContractInfoV2, keeper *
}
}

func cacheAndDecorateContext(ctx sdk.Context, env *environment) (sdk.Context, sdk.CacheMultiStore) {
func cacheAndDecorateContext(ctx sdk.Context, env *environment, gasLimit uint64) (sdk.Context, sdk.CacheMultiStore) {
cachedCtx, msCached := store.GetCachedContext(ctx)
goCtx := context.WithValue(cachedCtx.Context(), dexcache.CtxKeyExecTermSignal, env.executionTerminationSignals)
cachedCtx = cachedCtx.WithContext(goCtx)
decoratedCtx := cachedCtx.WithGasMeter(seisync.NewGasWrapper(sdk.NewInfiniteGasMeter())).WithBlockGasMeter(
decoratedCtx := cachedCtx.WithGasMeter(seisync.NewGasWrapper(dexutils.GetGasMeterForLimit(gasLimit))).WithBlockGasMeter(
seisync.NewGasWrapper(cachedCtx.BlockGasMeter()),
)
return decoratedCtx, msCached
Expand Down
7 changes: 6 additions & 1 deletion x/dex/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/sei-protocol/sei-chain/x/dex/migrations"
"github.com/sei-protocol/sei-chain/x/dex/types"
dexutils "github.com/sei-protocol/sei-chain/x/dex/utils"
"github.com/sei-protocol/sei-chain/x/store"
)

var (
Expand Down Expand Up @@ -229,9 +230,13 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
if isNewEpoch {
am.keeper.SetEpoch(ctx, currentEpoch)
}
cachedCtx, cachedStore := store.GetCachedContext(ctx)
cachedCtx = cachedCtx.WithGasMeter(dexutils.GetGasMeterForLimit(am.keeper.GetParams(ctx).BeginBlockGasLimit))
for _, contract := range am.getAllContractInfo(ctx) {
am.beginBlockForContract(ctx, contract, int64(currentEpoch))
am.beginBlockForContract(cachedCtx, contract, int64(currentEpoch))
}
// only write if all contracts have been processed
cachedStore.Write()
}

func (am AppModule) beginBlockForContract(ctx sdk.Context, contract types.ContractInfoV2, epoch int64) {
Expand Down
28 changes: 27 additions & 1 deletion x/dex/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import (
var (
KeyPriceSnapshotRetention = []byte("PriceSnapshotRetention") // number of epochs to retain price snapshots for
KeySudoCallGasPrice = []byte("KeySudoCallGasPrice") // gas price for sudo calls from endblock
KeyBeginBlockGasLimit = []byte("KeyBeginBlockGasLimit")
KeyEndBlockGasLimit = []byte("KeyEndBlockGasLimit")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we using this in the endblock rn?

)

const (
DefaultPriceSnapshotRetention = 24 * 3600 // default to one day
DefaultPriceSnapshotRetention = 24 * 3600 // default to one day
DefaultBeginBlockGasLimit = 200000000 // 200M
DefaultEndBlockGasLimit = 1000000000 // 1B
)

var DefaultSudoCallGasPrice = sdk.ZeroDec() // 0
Expand All @@ -36,6 +40,8 @@ func DefaultParams() Params {
return Params{
PriceSnapshotRetention: DefaultPriceSnapshotRetention,
SudoCallGasPrice: DefaultSudoCallGasPrice,
BeginBlockGasLimit: DefaultBeginBlockGasLimit,
EndBlockGasLimit: DefaultEndBlockGasLimit,
}
}

Expand All @@ -44,6 +50,8 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyPriceSnapshotRetention, &p.PriceSnapshotRetention, validatePriceSnapshotRetention),
paramtypes.NewParamSetPair(KeySudoCallGasPrice, &p.SudoCallGasPrice, validateSudoCallGasPrice),
paramtypes.NewParamSetPair(KeyBeginBlockGasLimit, &p.BeginBlockGasLimit, validateBeginBlockGasLimit),
paramtypes.NewParamSetPair(KeyEndBlockGasLimit, &p.EndBlockGasLimit, validateEndBlockGasLimit),
}
}

Expand Down Expand Up @@ -74,3 +82,21 @@ func validatePriceSnapshotRetention(i interface{}) error {
func validateSudoCallGasPrice(i interface{}) error {
return nil
}

func validateBeginBlockGasLimit(i interface{}) error {
_, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

return nil
}

func validateEndBlockGasLimit(i interface{}) error {
_, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

return nil
}
121 changes: 101 additions & 20 deletions x/dex/types/params.pb.go

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

12 changes: 12 additions & 0 deletions x/dex/utils/gas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package utils

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func GetGasMeterForLimit(limit uint64) sdk.GasMeter {
if limit == 0 {
return sdk.NewInfiniteGasMeter()
}
return sdk.NewGasMeter(limit)
}