@@ -131,19 +131,6 @@ var (
131
131
reheapTimer = metrics .NewRegisteredTimer ("txpool/reheap" , nil )
132
132
)
133
133
134
- var (
135
- addrsPool = sync.Pool {
136
- New : func () interface {} {
137
- return make ([]common.Address , 0 , 8 )
138
- },
139
- }
140
- addrBeatPool = sync.Pool {
141
- New : func () interface {} {
142
- return make (addressesByHeartbeat , 0 , 8 )
143
- },
144
- }
145
- )
146
-
147
134
// TxStatus is the current status of a transaction as seen by the pool.
148
135
type TxStatus uint
149
136
@@ -283,8 +270,6 @@ type TxPool struct {
283
270
wg sync.WaitGroup // tracks loop, scheduleReorgLoop
284
271
initDoneCh chan struct {} // is closed once the pool is initialized (for tests)
285
272
286
- spammers * prque.Prque
287
-
288
273
changesSinceReorg int // A counter for how many drops we've performed in-between reorg.
289
274
}
290
275
@@ -316,7 +301,6 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
316
301
reorgShutdownCh : make (chan struct {}),
317
302
initDoneCh : make (chan struct {}),
318
303
gasPrice : new (big.Int ).SetUint64 (config .PriceLimit ),
319
- spammers : prque .New (nil ),
320
304
}
321
305
pool .locals = newAccountSet (pool .signer )
322
306
for _ , addr := range config .Locals {
@@ -1218,14 +1202,13 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
1218
1202
}
1219
1203
}
1220
1204
// Reset needs promote for all addresses
1221
- promoteAddrs = addrsPool . Get ().( []common.Address )
1205
+ promoteAddrs = make ( []common.Address , 0 , len ( pool . queue ) )
1222
1206
for addr := range pool .queue {
1223
1207
promoteAddrs = append (promoteAddrs , addr )
1224
1208
}
1225
1209
}
1226
1210
// Check for pending transactions for every account that sent new ones
1227
1211
promoted := pool .promoteExecutables (promoteAddrs )
1228
- defer addrsPool .Put (promoteAddrs [:0 ])
1229
1212
1230
1213
// If a new block appeared, validate the pool of pending transactions. This will
1231
1214
// remove any transaction that has been included in the block or was invalidated
@@ -1465,19 +1448,18 @@ func (pool *TxPool) truncatePending() {
1465
1448
1466
1449
pendingBeforeCap := pending
1467
1450
// Assemble a spam order to penalize large transactors first
1468
- pool . spammers . Reset ( )
1451
+ spammers := prque . New ( nil )
1469
1452
for addr , list := range pool .pending {
1470
1453
// Only evict transactions from high rollers
1471
1454
if ! pool .locals .contains (addr ) && uint64 (list .Len ()) > pool .config .AccountSlots {
1472
- pool . spammers .Push (addr , int64 (list .Len ()))
1455
+ spammers .Push (addr , int64 (list .Len ()))
1473
1456
}
1474
1457
}
1475
1458
// Gradually drop transactions from offenders
1476
- offenders := addrsPool .Get ().([]common.Address )
1477
- defer addrsPool .Put (offenders [:0 ])
1478
- for pending > pool .config .GlobalSlots && ! pool .spammers .Empty () {
1459
+ offenders := []common.Address {}
1460
+ for pending > pool .config .GlobalSlots && ! spammers .Empty () {
1479
1461
// Retrieve the next offender if not local address
1480
- offender , _ := pool . spammers .Pop ()
1462
+ offender , _ := spammers .Pop ()
1481
1463
offenders = append (offenders , offender .(common.Address ))
1482
1464
1483
1465
// Equalize balances until all the same or below threshold
@@ -1550,8 +1532,7 @@ func (pool *TxPool) truncateQueue() {
1550
1532
}
1551
1533
1552
1534
// Sort all accounts with queued transactions by heartbeat
1553
- addresses := addrBeatPool .Get ().(addressesByHeartbeat )
1554
- defer addrBeatPool .Put (addresses [:0 ])
1535
+ addresses := make (addressesByHeartbeat , 0 , len (pool .queue ))
1555
1536
for addr := range pool .queue {
1556
1537
if ! pool .locals .contains (addr ) { // don't drop locals
1557
1538
addresses = append (addresses , addressByHeartbeat {addr , pool .beats [addr ]})
@@ -1701,10 +1682,7 @@ func (as *accountSet) containsTx(tx *types.Transaction) bool {
1701
1682
// add inserts a new address into the set to track.
1702
1683
func (as * accountSet ) add (addr common.Address ) {
1703
1684
as .accounts [addr ] = struct {}{}
1704
- if as .cache != nil {
1705
- addrsPool .Put ((* as .cache )[:0 ])
1706
- as .cache = nil
1707
- }
1685
+ as .cache = nil
1708
1686
}
1709
1687
1710
1688
// addTx adds the sender of tx into the set.
@@ -1718,7 +1696,7 @@ func (as *accountSet) addTx(tx *types.Transaction) {
1718
1696
// reuse. The returned slice should not be changed!
1719
1697
func (as * accountSet ) flatten () []common.Address {
1720
1698
if as .cache == nil {
1721
- accounts := addrsPool . Get ().( []common.Address )
1699
+ accounts := make ( []common.Address , 0 , len ( as . accounts ) )
1722
1700
for account := range as .accounts {
1723
1701
accounts = append (accounts , account )
1724
1702
}
@@ -1732,10 +1710,7 @@ func (as *accountSet) merge(other *accountSet) {
1732
1710
for addr := range other .accounts {
1733
1711
as .accounts [addr ] = struct {}{}
1734
1712
}
1735
- if as .cache != nil {
1736
- addrsPool .Put ((* as .cache )[:0 ])
1737
- as .cache = nil
1738
- }
1713
+ as .cache = nil
1739
1714
}
1740
1715
1741
1716
// txLookup is used internally by TxPool to track transactions while allowing
0 commit comments