Skip to content

Commit

Permalink
core: test locals support in txpool queue limits, fix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
karalabe committed Jul 6, 2017
1 parent 88b4fe7 commit 34ec991
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 83 deletions.
2 changes: 1 addition & 1 deletion core/tx_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo
}

// Discard finds a number of most underpriced transactions, removes them from the
// priced list and returs them for further removal from the entire pool.
// priced list and returns them for further removal from the entire pool.
func (l *txPricedList) Discard(count int, local *accountSet) types.Transactions {
drop := make(types.Transactions, 0, count) // Remote underpriced transactions to drop
save := make(types.Transactions, 0, 64) // Local underpriced transactions to keep
Expand Down
14 changes: 7 additions & 7 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ func (pool *TxPool) promoteExecutables(state *state.StateDB, accounts []common.A
}
}
// Iterate over all accounts and promote any executable transactions
queued := uint64(0)
for _, addr := range accounts {
list := pool.queue[addr]
if list == nil {
Expand Down Expand Up @@ -754,8 +753,6 @@ func (pool *TxPool) promoteExecutables(state *state.StateDB, accounts []common.A
log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
}
}
queued += uint64(list.Len())

// Delete the entire queue entry if it became empty.
if list.Empty() {
delete(pool.queue, addr)
Expand Down Expand Up @@ -833,19 +830,22 @@ func (pool *TxPool) promoteExecutables(state *state.StateDB, accounts []common.A
pendingRateLimitCounter.Inc(int64(pendingBeforeCap - pending))
}
// If we've queued more transactions than the hard limit, drop oldest ones
queued := uint64(0)
for _, list := range pool.queue {
queued += uint64(list.Len())
}
if queued > pool.config.GlobalQueue {
// Sort all accounts with queued transactions by heartbeat
addresses := make(addresssByHeartbeat, 0, len(pool.queue))
for addr := range pool.queue {
// Don't drop locals
if !pool.locals.contains(addr) {
if !pool.locals.contains(addr) { // don't drop locals
addresses = append(addresses, addressByHeartbeat{addr, pool.beats[addr]})
}
}
sort.Sort(addresses)

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

Expand Down
Loading

0 comments on commit 34ec991

Please sign in to comment.