diff --git a/app/ante.go b/app/ante.go index 2571f86781..51365edf0c 100644 --- a/app/ante.go +++ b/app/ante.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante" ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" + "github.com/sei-protocol/sei-chain/app/antedecorators" "github.com/sei-protocol/sei-chain/utils/tracing" "github.com/sei-protocol/sei-chain/x/dex" dexkeeper "github.com/sei-protocol/sei-chain/x/dex/keeper" @@ -77,6 +78,8 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { ante.NewValidateMemoDecorator(options.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), + // PriorityDecorator must be called after DeductFeeDecorator which sets tx priority based on tx fees + antedecorators.NewPriorityDecorator(), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewSetPubKeyDecorator(options.AccountKeeper), ante.NewValidateSigCountDecorator(options.AccountKeeper), diff --git a/app/antedecorators/priority.go b/app/antedecorators/priority.go new file mode 100644 index 0000000000..a8d741bcb5 --- /dev/null +++ b/app/antedecorators/priority.go @@ -0,0 +1,52 @@ +package antedecorators + +import ( + "math" + + sdk "github.com/cosmos/cosmos-sdk/types" + oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" +) + +type PriorityDecorator struct{} + +func NewPriorityDecorator() PriorityDecorator { + return PriorityDecorator{} +} + +func intMin(a, b int64) int64 { + if a < b { + return a + } + return b +} + +// Assigns higher priority to certain types of transactions including oracle +func (pd PriorityDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { + // Cap priority to MAXINT64 - 1000 + // Use higher priorities for tiers including oracle tx's + priority := intMin(ctx.Priority(), math.MaxInt64-1000) + + if isOracleTx(tx) { + priority = math.MaxInt64 - 100 + } + + newCtx := ctx.WithPriority(priority) + + return next(newCtx, tx, simulate) +} + +func isOracleTx(tx sdk.Tx) bool { + if len(tx.GetMsgs()) == 0 { + // empty TX isn't oracle + return false + } + for _, msg := range tx.GetMsgs() { + switch msg.(type) { + case *oracletypes.MsgAggregateExchangeRateVote: + continue + default: + return false + } + } + return true +}