@@ -34,6 +34,7 @@ import (
3434 "github.com/ethereum/go-ethereum/core/types"
3535 "github.com/ethereum/go-ethereum/event"
3636 "github.com/ethereum/go-ethereum/log"
37+ metaminer "github.com/ethereum/go-ethereum/metadium/miner"
3738 "github.com/ethereum/go-ethereum/metrics"
3839 "github.com/ethereum/go-ethereum/params"
3940)
9596var (
9697 evictionInterval = time .Minute // Time interval to check for evictable transactions
9798 statsReportInterval = 8 * time .Second // Time interval to report transaction pool stats
99+ // Add TRS
100+ trsTickerInterval = 3 * time .Hour // Time interval to check for TRS transactions
98101)
99102
100103var (
@@ -250,6 +253,9 @@ type TxPool struct {
250253 eip1559 bool // Fork indicator whether we are using EIP-1559 type transactions.
251254 // fee delegation
252255 feedelegation bool // Fork indicator whether we are using fee delegation type transactions.
256+ // Add TRS
257+ trsListMap map [common.Address ]bool
258+ trsSubscribe bool
253259
254260 currentState * state.StateDB // Current state in the blockchain head
255261 pendingNonces * txNoncer // Pending state tracking virtual nonces
@@ -356,12 +362,16 @@ func (pool *TxPool) loop() {
356362 report = time .NewTicker (statsReportInterval )
357363 evict = time .NewTicker (evictionInterval )
358364 journal = time .NewTicker (pool .config .Rejournal )
365+ // Add TRS
366+ trsTicker = time .NewTicker (trsTickerInterval )
359367 // Track the previous head headers for transaction reorgs
360368 head = pool .chain .CurrentBlock ()
361369 )
362370 defer report .Stop ()
363371 defer evict .Stop ()
364372 defer journal .Stop ()
373+ // Add TRS
374+ defer trsTicker .Stop ()
365375
366376 // Notify tests that the init phase is done
367377 close (pool .initDoneCh )
@@ -433,6 +443,25 @@ func (pool *TxPool) loop() {
433443 }
434444 pool .mu .Unlock ()
435445 }
446+ // Add TRS
447+ case <- trsTicker .C :
448+ // Removes the transaction included in trsList regardless of TRS subscription.
449+ if ! metaminer .IsPoW () {
450+ if len (pool .trsListMap ) > 0 {
451+ pool .mu .Lock ()
452+ for addr := range pool .pending {
453+ list := pool .pending [addr ].Flatten ()
454+ for _ , tx := range list {
455+ if pool .trsListMap [addr ] || (tx .To () != nil && pool .trsListMap [* tx .To ()]) {
456+ log .Debug ("Discard pending transaction included in trsList" , "hash" , tx .Hash (), "addr" , addr )
457+ pool .removeTx (tx .Hash (), true )
458+ pendingDiscardMeter .Mark (int64 (1 ))
459+ }
460+ }
461+ }
462+ pool .mu .Unlock ()
463+ }
464+ }
436465 }
437466 }
438467}
@@ -701,6 +730,16 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
701730 if pool .currentState .GetNonce (from ) > tx .Nonce () {
702731 return ErrNonceTooLow
703732 }
733+ // Add TRS
734+ // Only nodes that subscribe to TRS removes transactions included in trsList.
735+ if ! metaminer .IsPoW () {
736+ if len (pool .trsListMap ) > 0 && pool .trsSubscribe {
737+ if pool .trsListMap [from ] || (tx .To () != nil && pool .trsListMap [* tx .To ()]) {
738+ return ErrIncludedTRSList
739+ }
740+ }
741+ }
742+
704743 // Transactor should have enough funds to cover the costs
705744 // cost == V + GP * GL
706745
@@ -1400,6 +1439,13 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
14001439 pool .eip1559 = pool .chainconfig .IsLondon (next )
14011440 // fee delegation
14021441 pool .feedelegation = pool .chainconfig .IsApplepie (next )
1442+ // Add TRS
1443+ if ! metaminer .IsPoW () {
1444+ pool .trsListMap , pool .trsSubscribe , _ = metaminer .GetTRSListMap (newHead .Number )
1445+ } else {
1446+ pool .trsListMap = nil
1447+ pool .trsSubscribe = false
1448+ }
14031449}
14041450
14051451// promoteExecutables moves transactions that have become processable from the
@@ -1425,13 +1471,25 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
14251471 // Drop all transactions that are too costly (low balance or out of gas)
14261472 drops , _ := list .Filter (pool .currentState .GetBalance (addr ), pool .currentMaxGas )
14271473
1428- // fee delegation
1429- if pool .feedelegation {
1474+ // Add TRS
1475+ // Only nodes that subscribe to TRS removes transactions included in trsList.
1476+ doTrs := ! metaminer .IsPoW () && len (pool .trsListMap ) > 0 && pool .trsSubscribe
1477+ if pool .feedelegation || doTrs {
14301478 for _ , tx := range list .Flatten () {
1431- if tx .Type () == types .FeeDelegateDynamicFeeTxType && tx .FeePayer () != nil {
1432- feePayer := * tx .FeePayer ()
1433- if pool .currentState .GetBalance (feePayer ).Cmp (tx .FeePayerCost ()) < 0 {
1434- log .Trace ("promoteExecutables" , "hash" , tx .Hash ().String ())
1479+ if pool .feedelegation {
1480+ if tx .Type () == types .FeeDelegateDynamicFeeTxType && tx .FeePayer () != nil {
1481+ feePayer := * tx .FeePayer ()
1482+ if pool .currentState .GetBalance (feePayer ).Cmp (tx .FeePayerCost ()) < 0 {
1483+ log .Trace ("Removed queued fee delegation transaction" , "hash" , tx .Hash ().String ())
1484+ list .Remove (tx )
1485+ drops = append (drops , tx )
1486+ continue
1487+ }
1488+ }
1489+ }
1490+ if doTrs {
1491+ if pool .trsListMap [addr ] || (tx .To () != nil && pool .trsListMap [* tx .To ()]) {
1492+ log .Trace ("Removed queued transaction included in trsList" , "hash" , tx .Hash (), "addr" , addr )
14351493 list .Remove (tx )
14361494 drops = append (drops , tx )
14371495 }
@@ -1637,13 +1695,25 @@ func (pool *TxPool) demoteUnexecutables() {
16371695 // Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
16381696 drops , invalids := list .Filter (pool .currentState .GetBalance (addr ), pool .currentMaxGas )
16391697
1640- // fee delegation
1641- if pool .feedelegation {
1698+ // Add TRS
1699+ // Only nodes that subscribe to TRS removes transactions included in trsList.
1700+ doTrs := ! metaminer .IsPoW () && len (pool .trsListMap ) > 0 && pool .trsSubscribe
1701+ if pool .feedelegation || doTrs {
16421702 for _ , tx := range list .Flatten () {
1643- if tx .Type () == types .FeeDelegateDynamicFeeTxType && tx .FeePayer () != nil {
1644- feePayer := * tx .FeePayer ()
1645- if pool .currentState .GetBalance (feePayer ).Cmp (tx .FeePayerCost ()) < 0 {
1646- log .Trace ("demoteUnexecutables" , "hash" , tx .Hash ().String ())
1703+ if pool .feedelegation {
1704+ if tx .Type () == types .FeeDelegateDynamicFeeTxType && tx .FeePayer () != nil {
1705+ feePayer := * tx .FeePayer ()
1706+ if pool .currentState .GetBalance (feePayer ).Cmp (tx .FeePayerCost ()) < 0 {
1707+ log .Trace ("Removed pending fee delegation transaction" , "hash" , tx .Hash ().String ())
1708+ list .Remove (tx )
1709+ drops = append (drops , tx )
1710+ continue
1711+ }
1712+ }
1713+ }
1714+ if doTrs {
1715+ if pool .trsListMap [addr ] || (tx .To () != nil && pool .trsListMap [* tx .To ()]) {
1716+ log .Trace ("Removed pending transaction included in trsList" , "hash" , tx .Hash (), "addr" , addr )
16471717 list .Remove (tx )
16481718 drops = append (drops , tx )
16491719 }
0 commit comments