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

feat: increase min gas price and min fee #3429

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
68 changes: 46 additions & 22 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

disptypes "github.com/Sifchain/sifnode/x/dispensation/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
)

const (
// min gas price for rowan
MIN_GAS_PRICE_UROWAN = "100000000000000" // 0.0001rowan
LOW_MIN_FEE_UROWAN = "20000000000000000000" // 20rowan
HIGH_MIN_FEE_UROWAN = "200000000000000000000" // 200rowan
)

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
Expand Down Expand Up @@ -60,19 +66,42 @@ func (r AdjustGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
adminParams := r.adminKeeper.GetParams(ctx)
submitProposalFee := adminParams.SubmitProposalFee

msgs := tx.GetMsgs()
if len(msgs) == 1 && (strings.Contains(strings.ToLower(sdk.MsgTypeURL(msgs[0])), strings.ToLower(disptypes.MsgTypeCreateDistribution)) ||
strings.Contains(strings.ToLower(sdk.MsgTypeURL(msgs[0])), strings.ToLower(disptypes.MsgTypeRunDistribution))) {
minGasPrice := sdk.DecCoin{
Denom: "rowan",
Amount: sdk.MustNewDecFromStr("0.00000005"),
}
if !minGasPrice.IsValid() {
return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid gas price")
}
ctx = ctx.WithMinGasPrices(sdk.NewDecCoins(minGasPrice))
return next(ctx, tx, simulate)
// Get the symbol of the settlement asset
settlementAssetSymbol := clptypes.GetSettlementAsset().Symbol

if !ctx.MinGasPrices().IsValid() {
return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid gas price")
}

// Define the global minimum gas price
minGasPrice := sdk.DecCoin{
Denom: settlementAssetSymbol,
Amount: sdk.MustNewDecFromStr(MIN_GAS_PRICE_UROWAN),
}
if !minGasPrice.IsValid() {
return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid gas price")
}

// Get current minimum gas prices from context
currentMinGasPrices := ctx.MinGasPrices()

// Check and update context's minimum gas prices if necessary
if currentAssetPrice := currentMinGasPrices.AmountOf(settlementAssetSymbol); currentAssetPrice.LT(minGasPrice.Amount) {
// Replace the current minimum gas price with the new minimum gas price for the asset
updatedMinGasPrices := currentMinGasPrices.Sub(sdk.NewDecCoins().Add(sdk.NewDecCoinFromDec(settlementAssetSymbol, currentAssetPrice))).Add(minGasPrice)
ctx = ctx.WithMinGasPrices(updatedMinGasPrices)
}

highMinFee, ok := sdk.NewIntFromString(HIGH_MIN_FEE_UROWAN)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid high fee amount")
}
lowMinFee, ok := sdk.NewIntFromString(LOW_MIN_FEE_UROWAN)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid low fee amount")
}

msgs := tx.GetMsgs()
minFee := sdk.ZeroInt()
for i := range msgs {
msgTypeURLLower := strings.ToLower(sdk.MsgTypeURL(msgs[i]))
Expand All @@ -83,11 +112,11 @@ func (r AdjustGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
strings.Contains(msgTypeURLLower, "removeliquidity") ||
strings.Contains(msgTypeURLLower, "removeliquidityunits") ||
strings.Contains(msgTypeURLLower, "addliquidity") {
minFee = sdk.NewInt(100000000000000000) // 0.1
minFee = sdk.MaxInt(minFee, highMinFee)
} else if strings.Contains(msgTypeURLLower, "transfer") && minFee.LTE(sdk.NewInt(10000000000000000)) {
minFee = sdk.NewInt(10000000000000000) // 0.01
minFee = sdk.MaxInt(minFee, lowMinFee)
} else if strings.Contains(msgTypeURLLower, "submitproposal") || strings.Contains(msgTypeURLLower, govtypes.TypeMsgSubmitProposal) {
minFee = sdk.NewIntFromBigInt(submitProposalFee.BigInt())
minFee = sdk.MaxInt(minFee, sdk.NewIntFromBigInt(submitProposalFee.BigInt()))
}
}
if minFee.Equal(sdk.ZeroInt()) {
Expand All @@ -98,12 +127,7 @@ func (r AdjustGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx must be a FeeTx")
}
fees := feeTx.GetFee()
rowanFee := sdk.ZeroInt()
for j := range fees {
if clptypes.StringCompare(clptypes.GetSettlementAsset().Symbol, fees[j].Denom) {
rowanFee = fees[j].Amount
}
}
rowanFee := fees.AmountOf(settlementAssetSymbol)
if rowanFee.LTE(sdk.ZeroInt()) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "unsupported fee asset")
}
Expand Down
30 changes: 14 additions & 16 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ func TestAdjustGasPriceDecorator_AnteHandle(t *testing.T) {
initTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)
addrs := sifapp.AddTestAddrs(app, ctx, 6, initTokens)
decorator := ante.NewAdjustGasPriceDecorator(app.AdminKeeper)
highGasPrice := sdk.DecCoin{
gasPrice := sdk.DecCoin{
Denom: "rowan",
Amount: sdk.MustNewDecFromStr("0.5"),
Amount: sdk.MustNewDecFromStr(ante.MIN_GAS_PRICE_UROWAN),
}
loweredGasPrice := sdk.DecCoin{
Denom: "rowan",
Amount: sdk.MustNewDecFromStr("0.00000005"),
}
ctx = ctx.WithMinGasPrices(sdk.NewDecCoins(highGasPrice))
// ctx = ctx.WithMinGasPrices(sdk.NewDecCoins(highGasPrice))
dispensationCreateMsg := dispensationtypes.NewMsgCreateDistribution(addrs[0], dispensationtypes.DistributionType_DISTRIBUTION_TYPE_AIRDROP, []banktypes.Output{}, "")
dispensationRunMsg := dispensationtypes.NewMsgRunDistribution(addrs[0].String(), "airdrop", dispensationtypes.DistributionType_DISTRIBUTION_TYPE_AIRDROP, 10)
otherMsg := banktypes.NewMsgSend(addrs[0], addrs[1], sdk.NewCoins(sdk.NewCoin("rowan", sdk.NewIntFromUint64(100))))
Expand All @@ -44,13 +40,13 @@ func TestAdjustGasPriceDecorator_AnteHandle(t *testing.T) {
expectedGasPrice sdk.DecCoin
err bool
}{
{"no messages", ctx, []sdk.Msg{}, highGasPrice, false},
{"dispensation create", ctx, []sdk.Msg{&dispensationCreateMsg}, loweredGasPrice, false},
{"dispensation create with extra msg", ctx, []sdk.Msg{&dispensationCreateMsg, otherMsg}, highGasPrice, true},
{"dispensation run", ctx, []sdk.Msg{&dispensationRunMsg}, loweredGasPrice, false},
{"dispensation run with extra msg", ctx, []sdk.Msg{&dispensationRunMsg, otherMsg}, highGasPrice, true},
{"other message without dispensation", ctx, []sdk.Msg{otherMsg}, highGasPrice, true},
{"other messages without dispensation", ctx, []sdk.Msg{otherMsg, otherMsg}, highGasPrice, true},
{"no messages", ctx, []sdk.Msg{}, gasPrice, false},
{"dispensation create", ctx, []sdk.Msg{&dispensationCreateMsg}, gasPrice, false},
{"dispensation create with extra msg", ctx, []sdk.Msg{&dispensationCreateMsg, otherMsg}, gasPrice, true},
{"dispensation run", ctx, []sdk.Msg{&dispensationRunMsg}, gasPrice, false},
{"dispensation run with extra msg", ctx, []sdk.Msg{&dispensationRunMsg, otherMsg}, gasPrice, true},
{"other message without dispensation", ctx, []sdk.Msg{otherMsg}, gasPrice, true},
{"other messages without dispensation", ctx, []sdk.Msg{otherMsg, otherMsg}, gasPrice, true},
}
for _, tc := range tt {
tc := tc
Expand All @@ -77,8 +73,10 @@ func TestAdjustGasPriceDecorator_AnteHandle_MinFee(t *testing.T) {
initTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)
addrs := sifapp.AddTestAddrs(app, ctx, 6, initTokens)
decorator := ante.NewAdjustGasPriceDecorator(app.AdminKeeper)
highFee := sdk.NewCoins(sdk.NewCoin("rowan", sdk.NewInt(100000000000000000))) // 0.1
lowFee := sdk.NewCoins(sdk.NewCoin("rowan", sdk.NewInt(10000000000000000))) // 0.01
highFeeInt, _ := sdk.NewIntFromString(ante.HIGH_MIN_FEE_UROWAN)
lowFeeInt, _ := sdk.NewIntFromString(ante.LOW_MIN_FEE_UROWAN)
highFee := sdk.NewCoins(sdk.NewCoin("rowan", highFeeInt))
lowFee := sdk.NewCoins(sdk.NewCoin("rowan", lowFeeInt))

sendMsg := banktypes.NewMsgSend(addrs[0], addrs[1], sdk.NewCoins(sdk.NewCoin("rowan", sdk.NewIntFromUint64(100))))
addLiquidityMsg := &clptypes.MsgAddLiquidity{}
Expand Down
2 changes: 1 addition & 1 deletion app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const releaseVersion = "1.2.0-beta"
const releaseVersion = "1.3.0-beta"

func SetupHandlers(app *SifchainApp) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, _ types.Plan, vm m.VersionMap) (m.VersionMap, error) {
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0-beta
1.3.0-beta
Loading