aboutsummaryrefslogtreecommitdiffstats
path: root/core/tx_pool.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_pool.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_pool.go')
-rw-r--r--core/tx_pool.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/core/tx_pool.go b/core/tx_pool.go
index 089bd215a..a554f6611 100644
--- a/core/tx_pool.go
+++ b/core/tx_pool.go
@@ -320,7 +320,7 @@ func (pool *TxPool) loop() {
// Any non-locals old enough should be removed
if time.Since(pool.beats[addr]) > pool.config.Lifetime {
for _, tx := range pool.queue[addr].Flatten() {
- pool.removeTx(tx.Hash())
+ pool.removeTx(tx.Hash(), true)
}
}
}
@@ -468,7 +468,7 @@ func (pool *TxPool) SetGasPrice(price *big.Int) {
pool.gasPrice = price
for _, tx := range pool.priced.Cap(price, pool.locals) {
- pool.removeTx(tx.Hash())
+ pool.removeTx(tx.Hash(), false)
}
log.Info("Transaction pool price threshold updated", "price", price)
}
@@ -630,7 +630,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
for _, tx := range drop {
log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice())
underpricedTxCounter.Inc(1)
- pool.removeTx(tx.Hash())
+ pool.removeTx(tx.Hash(), false)
}
}
// If the transaction is replacing an already pending one, do directly
@@ -695,8 +695,10 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) (bool, er
pool.priced.Removed()
queuedReplaceCounter.Inc(1)
}
- pool.all[hash] = tx
- pool.priced.Put(tx)
+ if pool.all[hash] == nil {
+ pool.all[hash] = tx
+ pool.priced.Put(tx)
+ }
return old != nil, nil
}
@@ -862,7 +864,7 @@ func (pool *TxPool) Get(hash common.Hash) *types.Transaction {
// removeTx removes a single transaction from the queue, moving all subsequent
// transactions back to the future queue.
-func (pool *TxPool) removeTx(hash common.Hash) {
+func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
// Fetch the transaction we wish to delete
tx, ok := pool.all[hash]
if !ok {
@@ -872,8 +874,9 @@ func (pool *TxPool) removeTx(hash common.Hash) {
// Remove it from the list of known transactions
delete(pool.all, hash)
- pool.priced.Removed()
-
+ if outofbound {
+ pool.priced.Removed()
+ }
// Remove the transaction from the pending lists and reset the account nonce
if pending := pool.pending[addr]; pending != nil {
if removed, invalids := pending.Remove(tx); removed {
@@ -1052,7 +1055,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
// Drop all transactions if they are less than the overflow
if size := uint64(list.Len()); size <= drop {
for _, tx := range list.Flatten() {
- pool.removeTx(tx.Hash())
+ pool.removeTx(tx.Hash(), true)
}
drop -= size
queuedRateLimitCounter.Inc(int64(size))
@@ -1061,7 +1064,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
// Otherwise drop only last few transactions
txs := list.Flatten()
for i := len(txs) - 1; i >= 0 && drop > 0; i-- {
- pool.removeTx(txs[i].Hash())
+ pool.removeTx(txs[i].Hash(), true)
drop--
queuedRateLimitCounter.Inc(1)
}