diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-04-12 17:17:52 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-04-12 17:54:22 +0800 |
commit | db48d312e44dab3a756aa6976412fe54f8e891ef (patch) | |
tree | 0e68f27b9bbd4826f265e31cff1cd2cd184a5379 /core/tx_list.go | |
parent | 7e911b8e476e9115d1a154aef5f6d06b954d5ab0 (diff) | |
download | go-tangerine-db48d312e44dab3a756aa6976412fe54f8e891ef.tar go-tangerine-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.gz go-tangerine-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.bz2 go-tangerine-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.lz go-tangerine-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.xz go-tangerine-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.zst go-tangerine-db48d312e44dab3a756aa6976412fe54f8e891ef.zip |
core: txpool stable underprice drop order, perf fixes
Diffstat (limited to 'core/tx_list.go')
-rw-r--r-- | core/tx_list.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/core/tx_list.go b/core/tx_list.go index 55fc42617..ea6ee7019 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -367,9 +367,20 @@ func (l *txList) Flatten() types.Transactions { // price-sorted transactions to discard when the pool fills up. type priceHeap []*types.Transaction -func (h priceHeap) Len() int { return len(h) } -func (h priceHeap) Less(i, j int) bool { return h[i].GasPrice().Cmp(h[j].GasPrice()) < 0 } -func (h priceHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } +func (h priceHeap) Len() int { return len(h) } +func (h priceHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } + +func (h priceHeap) Less(i, j int) bool { + // Sort primarily by price, returning the cheaper one + switch h[i].GasPrice().Cmp(h[j].GasPrice()) { + case -1: + return true + case 1: + return false + } + // If the prices match, stabilize via nonces (high nonce is worse) + return h[i].Nonce() > h[j].Nonce() +} func (h *priceHeap) Push(x interface{}) { *h = append(*h, x.(*types.Transaction)) |