Skip to content

Commit

Permalink
fix mempool logic to restrict gas limit for oracle txs
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed Apr 14, 2021
1 parent ae4f805 commit 061a344
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
8 changes: 6 additions & 2 deletions custom/auth/ante/spamming_prevention.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions custom/auth/ante/tax.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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
}

0 comments on commit 061a344

Please sign in to comment.