core/txpool/legacypool: release after truncate

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2025-10-06 12:05:42 +02:00
parent 0d41d250ce
commit 1ed0e5e95d
No known key found for this signature in database
GPG key ID: 0FE274EE8C95166E
2 changed files with 21 additions and 5 deletions

View file

@ -1512,10 +1512,18 @@ func (pool *LegacyPool) truncatePending() {
// truncateQueue drops the oldest transactions in the queue if the pool is above the global queue limit.
func (pool *LegacyPool) truncateQueue() {
removed := pool.queue.truncate()
removed, removedAddresses := pool.queue.truncate()
// remove all removable transactions
for _, hash := range removed {
pool.removeTx(hash, true, false)
pool.all.Remove(hash)
}
for _, addr := range removedAddresses {
_, hasPending := pool.pending[addr]
if !hasPending {
pool.reserver.Release(addr)
}
}
}

View file

@ -201,13 +201,17 @@ func (q *queue) promoteExecutables(accounts []common.Address, gasLimit uint64, c
return promotable, dropped
}
func (q *queue) truncate() []common.Hash {
// truncate drops the oldest transactions from the queue until the total
// number is below the configured limit.
// Returns the hashes of all dropped transactions, and the addresses of
// accounts that became empty due to the truncation.
func (q *queue) truncate() ([]common.Hash, []common.Address) {
queued := uint64(0)
for _, list := range q.queued {
queued += uint64(list.Len())
}
if queued <= q.config.GlobalQueue {
return nil
return nil, nil
}
// Sort all accounts with queued transactions by heartbeat
@ -217,6 +221,7 @@ func (q *queue) truncate() []common.Hash {
}
sort.Sort(sort.Reverse(addresses))
removed := make([]common.Hash, 0)
removedAddresses := make([]common.Address, 0)
// Drop transactions until the total is below the limit
for drop := queued - q.config.GlobalQueue; drop > 0 && len(addresses) > 0; {
@ -233,6 +238,7 @@ func (q *queue) truncate() []common.Hash {
}
drop -= size
queuedRateLimitMeter.Mark(int64(size))
removedAddresses = append(removedAddresses, addr.address)
continue
}
// Otherwise drop only last few transactions
@ -244,7 +250,9 @@ func (q *queue) truncate() []common.Hash {
queuedRateLimitMeter.Mark(1)
}
}
return removed
// no need to clear empty accounts, removeTx already does that
return removed, removedAddresses
}
// addressByHeartbeat is an account address tagged with its last activity timestamp.