diff --git a/custom/auth/ante/spamming_prevention.go b/custom/auth/ante/spamming_prevention.go index 9a9526de4..de2d65231 100644 --- a/custom/auth/ante/spamming_prevention.go +++ b/custom/auth/ante/spamming_prevention.go @@ -30,8 +30,12 @@ func NewSpammingPreventionDecorator(oracleKeeper OracleKeeper) SpammingPreventio // AnteHandle handles msg tax fee checking func (spd SpammingPreventionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - if ctx.IsCheckTx() { - if !simulate && !ctx.IsReCheckTx() { + if ctx.IsReCheckTx() { + return next(ctx, tx, simulate) + } + + if !simulate { + if ctx.IsCheckTx() { err := spd.CheckOracleSpamming(ctx, tx.GetMsgs()) if err != nil { return ctx, err diff --git a/custom/auth/ante/tax.go b/custom/auth/ante/tax.go index 1a0a18e45..8161dc3c2 100644 --- a/custom/auth/ante/tax.go +++ b/custom/auth/ante/tax.go @@ -10,9 +10,13 @@ import ( core "github.com/terra-project/core/types" marketexported "github.com/terra-project/core/x/market/exported" msgauthexported "github.com/terra-project/core/x/msgauth/exported" + oracleexported "github.com/terra-project/core/x/oracle/exported" wasmexported "github.com/terra-project/core/x/wasm/exported" ) +// MaxOracleMsgGasUsage is constant expected oracle msg gas cost +const MaxOracleMsgGasUsage = uint64(100_000) + // TaxFeeDecorator will check if the transaction's fee is at least as large // as tax + the local validator's minimum gasFee (defined in validator config) // and record tax proceeds to treasury module to track tax proceeds. @@ -40,13 +44,16 @@ func (tfd TaxFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, feeCoins := feeTx.GetFee() gas := feeTx.GetGas() + msgs := feeTx.GetMsgs() if !simulate { // Compute taxes - taxes := FilterMsgAndComputeTax(ctx, tfd.treasuryKeeper, feeTx.GetMsgs()...) + taxes := FilterMsgAndComputeTax(ctx, tfd.treasuryKeeper, msgs...) // Mempool fee validation - if ctx.IsCheckTx() { + // No fee validation for oracle txs + if ctx.IsCheckTx() && + !(isOracleTx(ctx, msgs) && gas <= uint64(len(msgs))*MaxOracleMsgGasUsage) { if err := EnsureSufficientMempoolFees(ctx, gas, feeCoins, taxes); err != nil { return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, err.Error()) } @@ -160,3 +167,18 @@ func computeTax(ctx sdk.Context, tk TreasuryKeeper, principal sdk.Coins) sdk.Coi return taxes } + +func isOracleTx(ctx sdk.Context, msgs []sdk.Msg) bool { + for _, msg := range msgs { + switch msg.(type) { + case *oracleexported.MsgAggregateExchangeRatePrevote: + continue + case *oracleexported.MsgAggregateExchangeRateVote: + continue + default: + return false + } + } + + return true +}