mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core: reorg tx promotion/demotion to avoid weird pending gaps
This commit is contained in:
parent
0dbe8bdc02
commit
29f12ab28a
1 changed files with 16 additions and 17 deletions
|
|
@ -1001,6 +1001,7 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
|
||||||
promoteAddrs = append(promoteAddrs, addr)
|
promoteAddrs = append(promoteAddrs, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check for pending transactions for every account that sent new ones
|
||||||
promoted := pool.promoteExecutables(promoteAddrs)
|
promoted := pool.promoteExecutables(promoteAddrs)
|
||||||
for _, tx := range promoted {
|
for _, tx := range promoted {
|
||||||
addr, _ := types.Sender(pool.signer, tx)
|
addr, _ := types.Sender(pool.signer, tx)
|
||||||
|
|
@ -1009,6 +1010,21 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
|
||||||
}
|
}
|
||||||
events[addr].Put(tx)
|
events[addr].Put(tx)
|
||||||
}
|
}
|
||||||
|
// If a new block appeared, validate the pool of pending transactions. This will
|
||||||
|
// remove any transaction that has been included in the block or was invalidated
|
||||||
|
// because of another transaction (e.g. higher gas price).
|
||||||
|
if reset != nil {
|
||||||
|
pool.demoteUnexecutables()
|
||||||
|
}
|
||||||
|
// Ensure pool.queue and pool.pending sizes stay within the configured limits.
|
||||||
|
pool.truncatePending()
|
||||||
|
pool.truncateQueue()
|
||||||
|
|
||||||
|
// Update all accounts to the latest known pending nonce
|
||||||
|
for addr, list := range pool.pending {
|
||||||
|
txs := list.Flatten() // Heavy but will be cached and is needed by the miner anyway
|
||||||
|
pool.pendingState.SetNonce(addr, txs[len(txs)-1].Nonce()+1)
|
||||||
|
}
|
||||||
pool.mu.Unlock()
|
pool.mu.Unlock()
|
||||||
|
|
||||||
// Notify subsystems for newly added transactions
|
// Notify subsystems for newly added transactions
|
||||||
|
|
@ -1103,18 +1119,6 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
|
||||||
log.Debug("Reinjecting stale transactions", "count", len(reinject))
|
log.Debug("Reinjecting stale transactions", "count", len(reinject))
|
||||||
senderCacher.recover(pool.signer, reinject)
|
senderCacher.recover(pool.signer, reinject)
|
||||||
pool.addTxsLocked(reinject, false)
|
pool.addTxsLocked(reinject, false)
|
||||||
|
|
||||||
// validate the pool of pending transactions, this will remove
|
|
||||||
// any transactions that have been included in the block or
|
|
||||||
// have been invalidated because of another transaction (e.g.
|
|
||||||
// higher gas price)
|
|
||||||
pool.demoteUnexecutables()
|
|
||||||
|
|
||||||
// Update all accounts to the latest known pending nonce
|
|
||||||
for addr, list := range pool.pending {
|
|
||||||
txs := list.Flatten() // Heavy but will be cached and is needed by the miner anyway
|
|
||||||
pool.pendingState.SetNonce(addr, txs[len(txs)-1].Nonce()+1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// promoteExecutables moves transactions that have become processable from the
|
// promoteExecutables moves transactions that have become processable from the
|
||||||
|
|
@ -1179,11 +1183,6 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
|
||||||
delete(pool.queue, addr)
|
delete(pool.queue, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure pool.queue and pool.pending sizes stay within the configured limits.
|
|
||||||
pool.truncatePending()
|
|
||||||
pool.truncateQueue()
|
|
||||||
|
|
||||||
return promoted
|
return promoted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue