aboutsummaryrefslogtreecommitdiffstats
path: root/core/tx_list.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-04-12 17:17:52 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-04-12 17:54:22 +0800
commitdb48d312e44dab3a756aa6976412fe54f8e891ef (patch)
tree0e68f27b9bbd4826f265e31cff1cd2cd184a5379 /core/tx_list.go
parent7e911b8e476e9115d1a154aef5f6d06b954d5ab0 (diff)
downloaddexon-db48d312e44dab3a756aa6976412fe54f8e891ef.tar
dexon-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.gz
dexon-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.bz2
dexon-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.lz
dexon-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.xz
dexon-db48d312e44dab3a756aa6976412fe54f8e891ef.tar.zst
dexon-db48d312e44dab3a756aa6976412fe54f8e891ef.zip
core: txpool stable underprice drop order, perf fixes
Diffstat (limited to 'core/tx_list.go')
-rw-r--r--core/tx_list.go17
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))