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 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
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 test/integration/src/py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def sifchain_fees(sifchain_fees_int):
# See https:/Sifchain/sifnode/pull/1802#discussion_r697403408
@pytest.fixture
def sifchain_fees_int():
return 100000000000000000
return 20000000000000000000


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion test/integration/src/py/test_new_currency_transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def test_can_create_a_new_token_and_peg_it(
new_account_key = ("a" + get_shell_output("uuidgen").replace("-", ""))[:token_length]
token_name = new_account_key
amount = amount_in_wei(9)
currencyAmount = amount_in_wei(10000)
new_currency = create_new_currency(
amount=amount,
amount=currencyAmount,
symbol=new_account_key,
token_name=token_name,
decimals=18,
Expand Down
3 changes: 2 additions & 1 deletion test/integration/src/py/test_random_currency_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def do_currency_test(
solidity_json_path,
):
amount = amount_in_wei(9)
currencyAmount = amount_in_wei(10000)
logging.info(f"create new currency")
new_currency = test_utilities.create_new_currency(
amount,
currencyAmount,
new_currency_symbol,
new_currency_symbol,
18,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def do_currency_test(
rowan_source_integrationtest_env_transfer_request: EthereumToSifchainTransferRequest,
):
amount = amount_in_wei(9)
currencyAmount = amount_in_wei(10000)
logging.info(f"create new currency")
new_currency = test_utilities.create_new_currency(
amount,
currencyAmount,
new_currency_symbol,
new_currency_symbol,
18,
Expand Down
Loading