Skip to content

Commit

Permalink
chore: cleanup custom ante-handler godocs (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Mar 4, 2022
1 parent 84da2c5 commit ba140a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 10 additions & 7 deletions ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package ante
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

oracletypes "github.com/umee-network/umee/x/oracle/types"
)

// MaxOracleMsgGasUsage is constant expected oracle msg gas cost
// MaxOracleMsgGasUsage defines the maximum gas allowed for an oracle transaction.
const MaxOracleMsgGasUsage = uint64(100000)

// MempoolFeeDecorator will check if the transaction's fee is at least as large
// as the local validator's minimum gasFee (defined in validator config).
// If fee is too low, decorator returns error and tx is rejected from mempool.
// Note this only applies when ctx.CheckTx = true
// If fee is high enough or not CheckTx, then call next AnteHandler
// CONTRACT: Tx must implement FeeTx to use MempoolFeeDecorator
// MempoolFeeDecorator defines a custom Umee AnteHandler decorator that is
// responsible for allowing oracle transactions from oracle feeders to bypass
// the minimum fee CheckTx check. However, if an oracle transaction's gas limit
// is beyond the accepted threshold, the minimum fee check is still applied.
//
// For non-oracle transactions, the minimum fee check is applied.
type MempoolFeeDecorator struct{}

func NewMempoolFeeDecorator() MempoolFeeDecorator {
Expand Down Expand Up @@ -71,8 +72,10 @@ func isOracleTx(msgs []sdk.Msg) bool {
switch msg.(type) {
case *oracletypes.MsgAggregateExchangeRatePrevote:
continue

case *oracletypes.MsgAggregateExchangeRateVote:
continue

default:
return false
}
Expand Down
13 changes: 8 additions & 5 deletions ante/spam_prevention.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
oracletypes "github.com/umee-network/umee/x/oracle/types"
)

// SpamPreventionDecorator will check if the transaction's gas is smaller than
// configured hard cap.
// SpamPreventionDecorator defines a custom Umee AnteHandler decorator that is
// responsible for preventing oracle message spam. Specifically, it prohibits
// oracle feeders from submitting multiple oracle messages in a single block.
type SpamPreventionDecorator struct {
oracleKeeper OracleKeeper
oraclePrevoteMap map[string]int64
oracleVoteMap map[string]int64
mu sync.Mutex
}

// NewSpamPreventionDecorator returns new spamming prevention decorator instance
func NewSpamPreventionDecorator(oracleKeeper OracleKeeper) *SpamPreventionDecorator {
return &SpamPreventionDecorator{
oracleKeeper: oracleKeeper,
Expand All @@ -28,7 +28,6 @@ func NewSpamPreventionDecorator(oracleKeeper OracleKeeper) *SpamPreventionDecora
}
}

// AnteHandle handles msg tax fee checking
func (spd *SpamPreventionDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
Expand All @@ -48,7 +47,9 @@ func (spd *SpamPreventionDecorator) AnteHandle(
return next(ctx, tx, simulate)
}

// CheckOracleSpam check whether the msgs are spamming on purpose or not
// CheckOracleSpam performs the check of whether or not we've seen an oracle
// message from an oracle feeder in the current block or not. If we have, we
// return an error which prohibits the transaction from being processed.
func (spd *SpamPreventionDecorator) CheckOracleSpam(ctx sdk.Context, msgs []sdk.Msg) error {
spd.mu.Lock()
defer spd.mu.Unlock()
Expand Down Expand Up @@ -81,6 +82,7 @@ func (spd *SpamPreventionDecorator) CheckOracleSpam(ctx sdk.Context, msgs []sdk.

spd.oraclePrevoteMap[msg.Validator] = curHeight
continue

case *oracletypes.MsgAggregateExchangeRateVote:
feederAddr, err := sdk.AccAddressFromBech32(msg.Feeder)
if err != nil {
Expand All @@ -106,6 +108,7 @@ func (spd *SpamPreventionDecorator) CheckOracleSpam(ctx sdk.Context, msgs []sdk.

spd.oracleVoteMap[msg.Validator] = curHeight
continue

default:
return nil
}
Expand Down

0 comments on commit ba140a7

Please sign in to comment.