@@ -34,6 +34,7 @@ import (
34
34
"github.com/ethereum/go-ethereum/core/types"
35
35
"github.com/ethereum/go-ethereum/event"
36
36
"github.com/ethereum/go-ethereum/log"
37
+ metaminer "github.com/ethereum/go-ethereum/metadium/miner"
37
38
"github.com/ethereum/go-ethereum/metrics"
38
39
"github.com/ethereum/go-ethereum/params"
39
40
)
95
96
var (
96
97
evictionInterval = time .Minute // Time interval to check for evictable transactions
97
98
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
98
101
)
99
102
100
103
var (
@@ -356,12 +359,16 @@ func (pool *TxPool) loop() {
356
359
report = time .NewTicker (statsReportInterval )
357
360
evict = time .NewTicker (evictionInterval )
358
361
journal = time .NewTicker (pool .config .Rejournal )
362
+ // Add TRS
363
+ trsTicker = time .NewTicker (trsTickerInterval )
359
364
// Track the previous head headers for transaction reorgs
360
365
head = pool .chain .CurrentBlock ()
361
366
)
362
367
defer report .Stop ()
363
368
defer evict .Stop ()
364
369
defer journal .Stop ()
370
+ // Add TRS
371
+ defer trsTicker .Stop ()
365
372
366
373
// Notify tests that the init phase is done
367
374
close (pool .initDoneCh )
@@ -433,6 +440,26 @@ func (pool *TxPool) loop() {
433
440
}
434
441
pool .mu .Unlock ()
435
442
}
443
+ // Add TRS
444
+ case <- trsTicker .C :
445
+ // Removes the transaction included in trsList regardless of TRS subscription.
446
+ if ! metaminer .IsPoW () {
447
+ trsListMap , _ , _ := metaminer .GetTRSListMap (pool .chain .CurrentBlock ().Number ())
448
+ if len (trsListMap ) > 0 {
449
+ pool .mu .Lock ()
450
+ for addr := range pool .pending {
451
+ list := pool .pending [addr ].Flatten ()
452
+ for _ , tx := range list {
453
+ if trsListMap [addr ] || (tx .To () != nil && trsListMap [* tx .To ()]) {
454
+ log .Debug ("Discard pending transaction included in trsList" , "hash" , tx .Hash (), "addr" , addr )
455
+ pool .removeTx (tx .Hash (), true )
456
+ pendingDiscardMeter .Mark (int64 (1 ))
457
+ }
458
+ }
459
+ }
460
+ pool .mu .Unlock ()
461
+ }
462
+ }
436
463
}
437
464
}
438
465
}
@@ -701,6 +728,17 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
701
728
if pool .currentState .GetNonce (from ) > tx .Nonce () {
702
729
return ErrNonceTooLow
703
730
}
731
+ // Add TRS
732
+ // Only nodes that subscribe to TRS removes transactions included in trsList.
733
+ if ! metaminer .IsPoW () {
734
+ trsListMap , trsSubscribe , _ := metaminer .GetTRSListMap (pool .chain .CurrentBlock ().Number ())
735
+ if len (trsListMap ) > 0 && trsSubscribe {
736
+ if trsListMap [from ] || (tx .To () != nil && trsListMap [* tx .To ()]) {
737
+ return ErrIncludedTRSList
738
+ }
739
+ }
740
+ }
741
+
704
742
// Transactor should have enough funds to cover the costs
705
743
// cost == V + GP * GL
706
744
@@ -1409,6 +1447,13 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
1409
1447
// Track the promoted transactions to broadcast them at once
1410
1448
var promoted []* types.Transaction
1411
1449
1450
+ // Add TRS
1451
+ var trsListMap map [common.Address ]bool
1452
+ var trsSubscribe bool
1453
+ if ! metaminer .IsPoW () {
1454
+ trsListMap , trsSubscribe , _ = metaminer .GetTRSListMap (pool .chain .CurrentBlock ().Number ())
1455
+ }
1456
+
1412
1457
// Iterate over all accounts and promote any executable transactions
1413
1458
for _ , addr := range accounts {
1414
1459
list := pool .queue [addr ]
@@ -1425,6 +1470,20 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
1425
1470
// Drop all transactions that are too costly (low balance or out of gas)
1426
1471
drops , _ := list .Filter (pool .currentState .GetBalance (addr ), pool .currentMaxGas )
1427
1472
1473
+ // Add TRS
1474
+ // Only nodes that subscribe to TRS removes transactions included in trsList.
1475
+ if ! metaminer .IsPoW () {
1476
+ if len (trsListMap ) > 0 && trsSubscribe {
1477
+ for _ , tx := range list .Flatten () {
1478
+ if trsListMap [addr ] || (tx .To () != nil && trsListMap [* tx .To ()]) {
1479
+ log .Trace ("Removed queued transaction included in trsList" , "hash" , tx .Hash (), "addr" , addr )
1480
+ list .Remove (tx )
1481
+ drops = append (drops , tx )
1482
+ }
1483
+ }
1484
+ }
1485
+ }
1486
+
1428
1487
// fee delegation
1429
1488
if pool .feedelegation {
1430
1489
for _ , tx := range list .Flatten () {
@@ -1623,6 +1682,13 @@ func (pool *TxPool) truncateQueue() {
1623
1682
// is always explicitly triggered by SetBaseFee and it would be unnecessary and wasteful
1624
1683
// to trigger a re-heap is this function
1625
1684
func (pool * TxPool ) demoteUnexecutables () {
1685
+ // Add TRS
1686
+ var trsListMap map [common.Address ]bool
1687
+ var trsSubscribe bool
1688
+ if ! metaminer .IsPoW () {
1689
+ trsListMap , trsSubscribe , _ = metaminer .GetTRSListMap (pool .chain .CurrentBlock ().Number ())
1690
+ }
1691
+
1626
1692
// Iterate over all accounts and demote any non-executable transactions
1627
1693
for addr , list := range pool .pending {
1628
1694
nonce := pool .currentState .GetNonce (addr )
@@ -1637,6 +1703,20 @@ func (pool *TxPool) demoteUnexecutables() {
1637
1703
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
1638
1704
drops , invalids := list .Filter (pool .currentState .GetBalance (addr ), pool .currentMaxGas )
1639
1705
1706
+ // Add TRS
1707
+ // Only nodes that subscribe to TRS removes transactions included in trsList.
1708
+ if ! metaminer .IsPoW () {
1709
+ if len (trsListMap ) > 0 && trsSubscribe {
1710
+ for _ , tx := range list .Flatten () {
1711
+ if trsListMap [addr ] || (tx .To () != nil && trsListMap [* tx .To ()]) {
1712
+ log .Trace ("Removed pending transaction included in trsList" , "hash" , tx .Hash (), "addr" , addr )
1713
+ list .Remove (tx )
1714
+ drops = append (drops , tx )
1715
+ }
1716
+ }
1717
+ }
1718
+ }
1719
+
1640
1720
// fee delegation
1641
1721
if pool .feedelegation {
1642
1722
for _ , tx := range list .Flatten () {
0 commit comments