@@ -231,6 +231,10 @@ func (config *Config) sanitize() Config {
231231 return conf
232232}
233233
234+ type PendingFilter struct {
235+ GasLimitCap uint64 // Maximum gas can be used for a single transaction execution (0 means no limit)
236+ }
237+
234238// TxPool contains all currently known transactions. Transactions
235239// enter the pool when they are received from the network or submitted
236240// locally. They exit the pool when they are included in the blockchain.
@@ -524,13 +528,27 @@ func (pool *TxPool) ContentFrom(addr common.Address) (types.Transactions, types.
524528// Pending retrieves all currently processable transactions, grouped by origin
525529// account and sorted by nonce. The returned transaction set is a copy and can be
526530// freely modified by calling code.
527- func (pool * TxPool ) Pending (enforceTips bool ) map [common.Address ]types.Transactions {
531+ func (pool * TxPool ) Pending (filter PendingFilter ) map [common.Address ]types.Transactions {
528532 pool .mu .Lock ()
529533 defer pool .mu .Unlock ()
530534
531535 pending := make (map [common.Address ]types.Transactions , len (pool .pending ))
532536 for addr , list := range pool .pending {
533- pending [addr ] = list .Flatten ()
537+ //pending[addr] = list.Flatten()
538+ txs := list .Flatten ()
539+ if filter .GasLimitCap != 0 {
540+ for i , tx := range txs {
541+ if filter .GasLimitCap != 0 {
542+ if tx .Gas () > filter .GasLimitCap {
543+ txs = txs [:i ]
544+ break
545+ }
546+ }
547+ }
548+ }
549+ if len (txs ) > 0 {
550+ pending [addr ] = txs
551+ }
534552 }
535553 return pending
536554}
@@ -568,6 +586,9 @@ func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
568586 if tx .Size () > txMaxSize {
569587 return ErrOversizedData
570588 }
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+ //}
571592 // Transactions can't be negative. This may never happen using RLP decoded
572593 // transactions but may occur if you create a transaction using the RPC.
573594 if tx .Value ().Sign () < 0 {
@@ -1191,6 +1212,21 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
11911212 }
11921213 pool .mu .Lock ()
11931214 if reset != nil {
1215+ if reset .newHead != nil && reset .oldHead != nil {
1216+ // Discard the transactions with the gas limit higher than the cap.
1217+ if pool .chainconfig .IsOsaka (reset .newHead .Number , reset .newHead .Time ) && ! pool .chainconfig .IsOsaka (reset .oldHead .Number , reset .oldHead .Time ) {
1218+ var hashes []common.Hash
1219+ pool .all .Range (func (hash common.Hash , tx * types.Transaction , local bool ) bool {
1220+ if tx .Gas () > params .MaxTxGas {
1221+ hashes = append (hashes , hash )
1222+ }
1223+ return true
1224+ }, false , true )
1225+ for _ , hash := range hashes {
1226+ pool .removeTx (hash , true )
1227+ }
1228+ }
1229+ }
11941230 // Reset from the old head to the new, rescheduling any reorged transactions
11951231 pool .reset (reset .oldHead , reset .newHead )
11961232
0 commit comments