core/txpool: improve transaction validate (#1921)

This commit is contained in:
Daniel Liu 2026-01-16 18:15:07 +08:00 committed by GitHub
parent 86cbf4a897
commit 939225bd87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -93,24 +93,22 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
if tx.Nonce()+1 < tx.Nonce() {
return core.ErrNonceMax
}
isSpecial := tx.IsSpecialTransaction()
// Ensure the gasprice is high enough to cover the requirement of
// the calling pool and/or block producer
if tx.GasTipCapIntCmp(opts.MinTip) < 0 {
// For special transactions, only check if the sender is not a signer
// For regular transactions, always check (to preserve old logic)
if !isSpecial || opts.NotSigner(from) {
// Skip further validation for special transactions
if tx.IsSpecialTransaction() {
if opts.NotSigner(from) {
return fmt.Errorf("%w: tip needed %v, tip permitted %v", ErrUnderpriced, opts.MinTip, tx.GasTipCap())
}
}
// Skip further checks for special transactions
if isSpecial {
return nil
}
// Check zero gas price.
if tx.GasPrice().Sign() == 0 {
return ErrZeroGasPrice
}
// Ensure the gas price is high enough to cover the requirement of the calling
// pool and/or block producer
if tx.GasTipCapIntCmp(opts.MinTip) < 0 {
return fmt.Errorf("%w: tip needed %v, tip permitted %v", ErrUnderpriced, opts.MinTip, tx.GasTipCap())
}
// Ensure the transaction has more gas than the bare minimum needed to
// cover the transaction metadata
intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, true, opts.Config.IsEIP1559(head.Number))