Skip to content

Commit e4df15c

Browse files
authored
Merge pull request #2344 from CortexFoundation/dev
refactor truncatePending
2 parents 95e067d + 3a9fb78 commit e4df15c

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

core/txpool/txpool.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,22 +1407,20 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
14071407
// equal number for all for accounts with many pending transactions.
14081408
func (pool *TxPool) truncatePending() {
14091409
pending := uint64(0)
1410-
for _, list := range pool.pending {
1411-
pending += uint64(list.Len())
1412-
}
1413-
if pending <= pool.config.GlobalSlots {
1414-
return
1415-
}
1416-
1417-
pendingBeforeCap := pending
14181410
// Assemble a spam order to penalize large transactors first
1419-
spammers := prque.New[int64, common.Address](nil)
1411+
spammers := prque.New[uint64, common.Address](nil)
14201412
for addr, list := range pool.pending {
14211413
// Only evict transactions from high rollers
1422-
if !pool.locals.contains(addr) && uint64(list.Len()) > pool.config.AccountSlots {
1423-
spammers.Push(addr, int64(list.Len()))
1414+
length := uint64(list.Len())
1415+
pending += length
1416+
if length > pool.config.AccountSlots {
1417+
spammers.Push(addr, length)
14241418
}
14251419
}
1420+
if pending <= pool.config.GlobalSlots {
1421+
return
1422+
}
1423+
pendingBeforeCap := pending
14261424
// Gradually drop transactions from offenders
14271425
offenders := []common.Address{}
14281426
for pending > pool.config.GlobalSlots && !spammers.Empty() {

0 commit comments

Comments
 (0)