Skip to content

Commit

Permalink
Add effective-gas-tip at leastat min-tip check in legacypool validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ezdac committed Dec 12, 2024
1 parent 36610a9 commit 3e13b30
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions core/txpool/celo_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import (
"github.com/ethereum/go-ethereum/params"
)

// ErrGasPriceDoesNotExceedBaseFeeFloor is returned if the gas price specified is
// lower than the configured base-fee-floor
var ErrGasPriceDoesNotExceedBaseFeeFloor = errors.New("gas-price is less than the base-fee-floor")
var (

// ErrGasPriceDoesNotExceedBaseFeeFloor is returned if the gas price specified is
// lower than the configured base-fee-floor
ErrGasPriceDoesNotExceedBaseFeeFloor = errors.New("gas-price is less than the base-fee-floor")
ErrMinimumEffectiveGasTipBelowMinTip = errors.New("effective gas tip at base-fee-floor is below threshold")
)

// AcceptSet is a set of accepted transaction types for a transaction subpool.
type AcceptSet = map[uint8]struct{}
Expand Down Expand Up @@ -61,16 +65,34 @@ func CeloValidateTransaction(tx *types.Transaction, head *types.Header,
return exchange.ErrUnregisteredFeeCurrency
}

celoGasPrice, err := exchange.ConvertCurrencyToCelo(
currencyCtx.ExchangeRates,
tx.FeeCurrency(),
tx.GasFeeCap(),
)
if err != nil {
return err
}

if opts.Config.Celo != nil {
// Make sure that the effective gas tip at the base fee floor is at least the
// requested min-tip.
// The min-tip for local transactions is set to 0, we can skip checking here.
if opts.MinTip != nil && opts.MinTip.Cmp(new(big.Int)) != 0 {
// If not, this would never be included, so we can reject early.
minTip, err := exchange.ConvertCeloToCurrency(currencyCtx.ExchangeRates, tx.FeeCurrency(), opts.MinTip)
if err != nil {
return err
}
minBaseFee, err := exchange.ConvertCeloToCurrency(currencyCtx.ExchangeRates, tx.FeeCurrency(), new(big.Int).SetUint64(opts.Config.Celo.EIP1559BaseFeeFloor))
if err != nil {
return err
}
if tx.EffectiveGasTipIntCmp(minTip, minBaseFee) < 0 {
return ErrUnderpriced
}
}

celoGasPrice, err := exchange.ConvertCurrencyToCelo(
currencyCtx.ExchangeRates,
tx.FeeCurrency(),
tx.GasFeeCap(),
)
if err != nil {
return err
}

if new(big.Int).SetUint64(opts.Config.Celo.EIP1559BaseFeeFloor).Cmp(celoGasPrice) == 1 {
return ErrGasPriceDoesNotExceedBaseFeeFloor
}
Expand Down

0 comments on commit 3e13b30

Please sign in to comment.