Skip to content

Commit

Permalink
Lower Evm max priority (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbhat1 authored Apr 5, 2024
1 parent a1e7beb commit 05ec7c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/antedecorators/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
const (
OraclePriority = math.MaxInt64 - 100
EVMAssociatePriority = math.MaxInt64 - 101
// This is the max priority a non oracle or associate tx can take
MaxPriority = math.MaxInt64 - 1000
)

type PriorityDecorator struct{}
Expand All @@ -27,9 +29,9 @@ func intMin(a, b int64) int64 {

// 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
// Cap priority
// Use higher priorities for tiers including oracle tx's
priority := intMin(ctx.Priority(), math.MaxInt64-1000)
priority := intMin(ctx.Priority(), MaxPriority)

if isOracleTx(tx) {
priority = OraclePriority
Expand Down
5 changes: 3 additions & 2 deletions x/evm/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/sei-protocol/sei-chain/app/antedecorators"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/x/evm/derived"
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
Expand Down Expand Up @@ -84,8 +85,8 @@ func (fc EVMFeeCheckDecorator) getMinimumFee(ctx sdk.Context) *big.Int {
func (fc EVMFeeCheckDecorator) CalculatePriority(ctx sdk.Context, txData ethtx.TxData) *big.Int {
gp := txData.EffectiveGasPrice(utils.Big0)
priority := new(big.Int).Quo(gp, fc.evmKeeper.GetPriorityNormalizer(ctx).RoundInt().BigInt())
if priority.Cmp(utils.BigMaxI64) > 0 {
priority = utils.BigMaxI64
if priority.Cmp(big.NewInt(antedecorators.MaxPriority)) > 0 {
priority = big.NewInt(antedecorators.MaxPriority)
}
return priority
}
4 changes: 3 additions & 1 deletion x/evm/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256"
"github.com/sei-protocol/sei-chain/app/antedecorators"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/ante"
"github.com/sei-protocol/sei-chain/x/evm/state"
Expand Down Expand Up @@ -178,6 +179,7 @@ func TestCalculatePriorityScenarios(t *testing.T) {
_1_1gwei := big.NewInt(1100000000000)
_2gwei := big.NewInt(200000000000)
maxInt := big.NewInt(math.MaxInt64)
maxPriority := big.NewInt(antedecorators.MaxPriority)

scenarios := []struct {
name string
Expand Down Expand Up @@ -236,7 +238,7 @@ func TestCalculatePriorityScenarios(t *testing.T) {
GasTipCap: new(big.Int).Add(maxInt, big.NewInt(1)),
Value: big.NewInt(1000000000),
},
expectedPriority: maxInt,
expectedPriority: maxPriority,
},
{
name: "LegacyTx has priority with gas price",
Expand Down

0 comments on commit 05ec7c1

Please sign in to comment.