Skip to content

Commit 34ec991

Browse files
committed
core: test locals support in txpool queue limits, fix
The commit reworks the transaction pool queue limitation tests to cater for testing local accounts, also testing the nolocal flag. In addition, it also fixes a panic if local transactions exceeded the global queue allowance (no accounts left to drop from) and also fixes queue eviction to operate on all accounts, not just the one being updated.
1 parent 88b4fe7 commit 34ec991

File tree

3 files changed

+197
-83
lines changed

3 files changed

+197
-83
lines changed

core/tx_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo
477477
}
478478

479479
// Discard finds a number of most underpriced transactions, removes them from the
480-
// priced list and returs them for further removal from the entire pool.
480+
// priced list and returns them for further removal from the entire pool.
481481
func (l *txPricedList) Discard(count int, local *accountSet) types.Transactions {
482482
drop := make(types.Transactions, 0, count) // Remote underpriced transactions to drop
483483
save := make(types.Transactions, 0, 64) // Local underpriced transactions to keep

core/tx_pool.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ func (pool *TxPool) promoteExecutables(state *state.StateDB, accounts []common.A
716716
}
717717
}
718718
// Iterate over all accounts and promote any executable transactions
719-
queued := uint64(0)
720719
for _, addr := range accounts {
721720
list := pool.queue[addr]
722721
if list == nil {
@@ -754,8 +753,6 @@ func (pool *TxPool) promoteExecutables(state *state.StateDB, accounts []common.A
754753
log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
755754
}
756755
}
757-
queued += uint64(list.Len())
758-
759756
// Delete the entire queue entry if it became empty.
760757
if list.Empty() {
761758
delete(pool.queue, addr)
@@ -833,19 +830,22 @@ func (pool *TxPool) promoteExecutables(state *state.StateDB, accounts []common.A
833830
pendingRateLimitCounter.Inc(int64(pendingBeforeCap - pending))
834831
}
835832
// If we've queued more transactions than the hard limit, drop oldest ones
833+
queued := uint64(0)
834+
for _, list := range pool.queue {
835+
queued += uint64(list.Len())
836+
}
836837
if queued > pool.config.GlobalQueue {
837838
// Sort all accounts with queued transactions by heartbeat
838839
addresses := make(addresssByHeartbeat, 0, len(pool.queue))
839840
for addr := range pool.queue {
840-
// Don't drop locals
841-
if !pool.locals.contains(addr) {
841+
if !pool.locals.contains(addr) { // don't drop locals
842842
addresses = append(addresses, addressByHeartbeat{addr, pool.beats[addr]})
843843
}
844844
}
845845
sort.Sort(addresses)
846846

847-
// Drop transactions until the total is below the limit
848-
for drop := queued - pool.config.GlobalQueue; drop > 0; {
847+
// Drop transactions until the total is below the limit or only locals remain
848+
for drop := queued - pool.config.GlobalQueue; drop > 0 && len(addresses) > 0; {
849849
addr := addresses[len(addresses)-1]
850850
list := pool.queue[addr.address]
851851

0 commit comments

Comments
 (0)