diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-07-06 16:51:59 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-07-06 16:51:59 +0800 |
commit | 34ec9913f628180d0ace740abfe1362995879c93 (patch) | |
tree | ab65a577014ed72b7307b59e42fe9ded25c3420b /core/tx_pool.go | |
parent | 88b4fe7d21bf03bbe01961dc49508bcf4edafb51 (diff) | |
download | dexon-34ec9913f628180d0ace740abfe1362995879c93.tar dexon-34ec9913f628180d0ace740abfe1362995879c93.tar.gz dexon-34ec9913f628180d0ace740abfe1362995879c93.tar.bz2 dexon-34ec9913f628180d0ace740abfe1362995879c93.tar.lz dexon-34ec9913f628180d0ace740abfe1362995879c93.tar.xz dexon-34ec9913f628180d0ace740abfe1362995879c93.tar.zst dexon-34ec9913f628180d0ace740abfe1362995879c93.zip |
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.
Diffstat (limited to 'core/tx_pool.go')
-rw-r--r-- | core/tx_pool.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/core/tx_pool.go b/core/tx_pool.go index 46b09c8af..8e2d1b31d 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -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 { @@ -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) @@ -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] |