Skip to content

Commit ad13618

Browse files
committed
tx gas limit validation
1 parent 5795143 commit ad13618

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

core/txpool/txpool.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package txpool
1818

1919
import (
2020
"errors"
21+
"fmt"
2122
"math"
2223
"math/big"
2324
"sort"
@@ -581,14 +582,16 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
581582
// rules, but does not check state-dependent validation such as sufficient balance.
582583
// This check is meant as an early check which only needs to be performed once,
583584
// and does not require the pool mutex to be held.
584-
func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
585+
func (pool *TxPool) validateTxBasics(tx *types.Transaction, head *types.Header, local bool) error {
585586
// Reject transactions over defined size to prevent DOS attacks
586587
if tx.Size() > txMaxSize {
587588
return ErrOversizedData
588589
}
589-
//if pool.chainconfig.IsOsaka && tx.Gas() > params.MaxTxGas {
590-
// return fmt.Errorf("%w (cap: %d, tx: %d)", core.ErrGasLimitTooHigh, params.MaxTxGas, tx.Gas())
591-
//}
590+
rules := pool.chainconfig.Rules(head.Number, true, head.Time)
591+
//if pool.chainconfig.IsOsaka(head.Number, head.Time) && tx.Gas() > params.MaxTxGas {
592+
if rules.IsOsaka && tx.Gas() > params.MaxTxGas {
593+
return fmt.Errorf("%w (cap: %d, tx: %d)", core.ErrGasLimitTooHigh, params.MaxTxGas, tx.Gas())
594+
}
592595
// Transactions can't be negative. This may never happen using RLP decoded
593596
// transactions but may occur if you create a transaction using the RPC.
594597
if tx.Value().Sign() < 0 {
@@ -961,7 +964,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
961964
// insufficient intrinsic gas as soon as possible and cache senders
962965
// in transactions before obtaining lock
963966

964-
if err := pool.validateTxBasics(tx, local); err != nil {
967+
if err := pool.validateTxBasics(tx, pool.chain.CurrentBlock().Header(), local); err != nil {
965968
errs[i] = err
966969
invalidTxMeter.Mark(1)
967970
continue

params/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
650650
if chainID == nil {
651651
chainID = new(big.Int)
652652
}
653-
return Rules{ChainID: new(big.Int).Set(chainID), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num), IsByzantium: c.IsByzantium(num), IsPetersburg: c.IsPetersburg(num), IsIstanbul: c.IsIstanbul(num), IsNeo: c.IsNeo(num), IsMerge: isMerge, IsOsaka: isMerge && c.IsOsaka(num, timestamp)}
653+
return Rules{ChainID: new(big.Int).Set(chainID), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num), IsByzantium: c.IsByzantium(num), IsPetersburg: c.IsPetersburg(num), IsIstanbul: c.IsIstanbul(num), IsNeo: c.IsNeo(num), IsMerge: c.IsMerge(num), IsOsaka: c.IsOsaka(num, timestamp)}
654654
}
655655

656656
// Get Mature Block

0 commit comments

Comments
 (0)