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

Add gas param for data bytes in orders #869

Merged
merged 1 commit into from
Jun 12, 2023
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: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ 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/go-critic/go-critic v0.6.3 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
Expand Down Expand Up @@ -140,6 +141,7 @@ 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.16.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
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ 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/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 @@ -598,6 +599,8 @@ 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.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
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
4 changes: 4 additions & 0 deletions proto/dex/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ message Params {
(gogoproto.jsontag) = "max_pairs_per_contract",
(gogoproto.moretags) = "yaml:\"max_pairs_per_contract\""
];
uint64 default_gas_per_order_data_byte = 14 [
(gogoproto.jsontag) = "default_gas_per_order_data_byte",
(gogoproto.moretags) = "yaml:\"default_gas_per_order_data_byte\""
];
}
3 changes: 3 additions & 0 deletions x/dex/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func (d CheckDexGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
case *types.MsgPlaceOrders:
numDependencies := len(memState.GetContractToDependencies(ctx, m.ContractAddr, d.dexKeeper.GetContractWithoutGasCharge))
dexGasRequired += params.DefaultGasPerOrder * uint64(len(m.Orders)*numDependencies)
for _, order := range m.Orders {
dexGasRequired += params.DefaultGasPerOrderDataByte * uint64(len(order.Data))
}
case *types.MsgCancelOrders:
numDependencies := len(memState.GetContractToDependencies(ctx, m.ContractAddr, d.dexKeeper.GetContractWithoutGasCharge))
dexGasRequired += params.DefaultGasPerCancel * uint64(len(m.Cancellations)*numDependencies)
Expand Down
20 changes: 20 additions & 0 deletions x/dex/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ func TestCheckDexGasDecorator(t *testing.T) {
}
_, err = decorator.AnteHandle(ctx, tx, false, terminator)
require.Nil(t, err)

// with data (insufficient fee)
tx = TestTx{
msgs: []sdk.Msg{
types.NewMsgPlaceOrders("someone", []*types.Order{{Data: "data"}, {}}, keepertest.TestContract, sdk.NewCoins()),
},
fee: sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(11011))),
}
_, err = decorator.AnteHandle(ctx, tx, false, terminator)
require.NotNil(t, err)

// with data (sufficient fee)
tx = TestTx{
msgs: []sdk.Msg{
types.NewMsgPlaceOrders("someone", []*types.Order{{Data: "data"}, {}}, keepertest.TestContract, sdk.NewCoins()),
},
fee: sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(11012))),
}
_, err = decorator.AnteHandle(ctx, tx, false, terminator)
require.Nil(t, err)
}

func TestTickSizeMultipleDecorator(t *testing.T) {
Expand Down
15 changes: 15 additions & 0 deletions x/dex/migrations/v15_to_v16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package migrations

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/x/dex/keeper"
"github.com/sei-protocol/sei-chain/x/dex/types"
)

func V15ToV16(ctx sdk.Context, dexkeeper keeper.Keeper) error {
// This isn't the cleanest migration since it could potentially revert any dex params we have changed
// but we haven't, so we'll just do this.
defaultParams := types.DefaultParams()
dexkeeper.SetParams(ctx, defaultParams)
return nil
}
24 changes: 24 additions & 0 deletions x/dex/migrations/v15_to_v16_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package migrations_test

import (
"testing"

keepertest "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/dex/migrations"
"github.com/sei-protocol/sei-chain/x/dex/types"
"github.com/stretchr/testify/require"
)

func TestMigrate15to16(t *testing.T) {
dexkeeper, ctx := keepertest.DexKeeper(t)
// write old params
prevParams := types.DefaultParams()
prevParams.DefaultGasPerOrderDataByte = 0
dexkeeper.SetParams(ctx, prevParams)

// migrate to default params
err := migrations.V15ToV16(ctx, *dexkeeper)
require.NoError(t, err)
params := dexkeeper.GetParams(ctx)
require.Equal(t, params.DefaultGasPerOrderDataByte, uint64(30))
}
80 changes: 42 additions & 38 deletions x/dex/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,36 @@ 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")
KeyDefaultGasPerOrder = []byte("KeyDefaultGasPerOrder")
KeyDefaultGasPerCancel = []byte("KeyDefaultGasPerCancel")
KeyMinRentDeposit = []byte("KeyMinRentDeposit")
KeyGasAllowancePerSettlement = []byte("KeyGasAllowancePerSettlement")
KeyMinProcessableRent = []byte("KeyMinProcessableRent")
KeyOrderBookEntriesPerLoad = []byte("KeyOrderBookEntriesPerLoad")
KeyContractUnsuspendCost = []byte("KeyContractUnsuspendCost")
KeyMaxOrderPerPrice = []byte("KeyMaxOrderPerPrice")
KeyMaxPairsPerContract = []byte("KeyMaxPairsPerContract")
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")
KeyDefaultGasPerOrder = []byte("KeyDefaultGasPerOrder")
KeyDefaultGasPerCancel = []byte("KeyDefaultGasPerCancel")
KeyMinRentDeposit = []byte("KeyMinRentDeposit")
KeyGasAllowancePerSettlement = []byte("KeyGasAllowancePerSettlement")
KeyMinProcessableRent = []byte("KeyMinProcessableRent")
KeyOrderBookEntriesPerLoad = []byte("KeyOrderBookEntriesPerLoad")
KeyContractUnsuspendCost = []byte("KeyContractUnsuspendCost")
KeyMaxOrderPerPrice = []byte("KeyMaxOrderPerPrice")
KeyMaxPairsPerContract = []byte("KeyMaxPairsPerContract")
KeyDefaultGasPerOrderDataByte = []byte("KeyDefaultGasPerOrderDataByte")
)

const (
DefaultPriceSnapshotRetention = 24 * 3600 // default to one day
DefaultBeginBlockGasLimit = 200000000 // 200M
DefaultEndBlockGasLimit = 1000000000 // 1B
DefaultDefaultGasPerOrder = 55000
DefaultDefaultGasPerCancel = 53000
DefaultMinRentDeposit = 10000000 // 10 sei
DefaultGasAllowancePerSettlement = 10000
DefaultMinProcessableRent = 100000
DefaultOrderBookEntriesPerLoad = 10
DefaultContractUnsuspendCost = 1000000
DefaultMaxOrderPerPrice = 10000
DefaultMaxPairsPerContract = 100
DefaultPriceSnapshotRetention = 24 * 3600 // default to one day
DefaultBeginBlockGasLimit = 200000000 // 200M
DefaultEndBlockGasLimit = 1000000000 // 1B
DefaultDefaultGasPerOrder = 55000
DefaultDefaultGasPerCancel = 53000
DefaultMinRentDeposit = 10000000 // 10 sei
DefaultGasAllowancePerSettlement = 10000
DefaultMinProcessableRent = 100000
DefaultOrderBookEntriesPerLoad = 10
DefaultContractUnsuspendCost = 1000000
DefaultMaxOrderPerPrice = 10000
DefaultMaxPairsPerContract = 100
DefaultDefaultGasPerOrderDataByte = 30
)

var DefaultSudoCallGasPrice = sdk.NewDecWithPrec(1, 1) // 0.1
Expand All @@ -51,19 +53,20 @@ func ParamKeyTable() paramtypes.KeyTable {
// DefaultParams returns a default set of parameters
func DefaultParams() Params {
return Params{
PriceSnapshotRetention: DefaultPriceSnapshotRetention,
SudoCallGasPrice: DefaultSudoCallGasPrice,
BeginBlockGasLimit: DefaultBeginBlockGasLimit,
EndBlockGasLimit: DefaultEndBlockGasLimit,
DefaultGasPerOrder: DefaultDefaultGasPerOrder,
DefaultGasPerCancel: DefaultDefaultGasPerCancel,
MinRentDeposit: DefaultMinRentDeposit,
GasAllowancePerSettlement: DefaultGasAllowancePerSettlement,
MinProcessableRent: DefaultMinProcessableRent,
OrderBookEntriesPerLoad: DefaultOrderBookEntriesPerLoad,
ContractUnsuspendCost: DefaultContractUnsuspendCost,
MaxOrderPerPrice: DefaultMaxOrderPerPrice,
MaxPairsPerContract: DefaultMaxPairsPerContract,
PriceSnapshotRetention: DefaultPriceSnapshotRetention,
SudoCallGasPrice: DefaultSudoCallGasPrice,
BeginBlockGasLimit: DefaultBeginBlockGasLimit,
EndBlockGasLimit: DefaultEndBlockGasLimit,
DefaultGasPerOrder: DefaultDefaultGasPerOrder,
DefaultGasPerCancel: DefaultDefaultGasPerCancel,
MinRentDeposit: DefaultMinRentDeposit,
GasAllowancePerSettlement: DefaultGasAllowancePerSettlement,
MinProcessableRent: DefaultMinProcessableRent,
OrderBookEntriesPerLoad: DefaultOrderBookEntriesPerLoad,
ContractUnsuspendCost: DefaultContractUnsuspendCost,
MaxOrderPerPrice: DefaultMaxOrderPerPrice,
MaxPairsPerContract: DefaultMaxPairsPerContract,
DefaultGasPerOrderDataByte: DefaultDefaultGasPerOrderDataByte,
}
}

Expand All @@ -83,6 +86,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyContractUnsuspendCost, &p.ContractUnsuspendCost, validateUint64Param),
paramtypes.NewParamSetPair(KeyMaxOrderPerPrice, &p.MaxOrderPerPrice, validateUint64Param),
paramtypes.NewParamSetPair(KeyMaxPairsPerContract, &p.MaxPairsPerContract, validateUint64Param),
paramtypes.NewParamSetPair(KeyDefaultGasPerOrderDataByte, &p.DefaultGasPerOrderDataByte, validateUint64Param),
}
}

Expand Down
Loading