core/txpool/legacypool: clarify and fix non-executable tx heartbeat (#33704)

Heartbeats are used to drop non-executable transactions from the queue.
The timeout mechanism was not clearly documented, and it was updates
also when not necessary.
This commit is contained in:
Csaba Kiraly 2026-01-29 10:53:55 +01:00 committed by GitHub
parent 628ff79be3
commit 9a6905318a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -151,7 +151,7 @@ type Config struct {
AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account
GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts
Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
Lifetime time.Duration // Maximum amount of time an account can remain stale in the non-executable pool
}
// DefaultConfig contains the default configurations for the transaction pool.
@ -778,7 +778,7 @@ func (pool *LegacyPool) add(tx *types.Transaction) (replaced bool, err error) {
pool.queueTxEvent(tx)
log.Trace("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To())
// Successful promotion, bump the heartbeat
// Successful replacement. If needed, bump the heartbeat giving more time to queued txs.
pool.queue.bump(from)
return old != nil, nil
}
@ -871,7 +871,7 @@ func (pool *LegacyPool) promoteTx(addr common.Address, hash common.Hash, tx *typ
// Set the potentially new pending nonce and notify any subsystems of the new tx
pool.pendingNonces.set(addr, tx.Nonce()+1)
// Successful promotion, bump the heartbeat
// Successful promotion, bump the heartbeat, giving more time to queued txs.
pool.queue.bump(addr)
return true
}

View file

@ -88,8 +88,12 @@ func (q *queue) get(addr common.Address) (*list, bool) {
return l, ok
}
// bump updates the heartbeat for the given account address.
// If the address is unknown, the call is a no-op.
func (q *queue) bump(addr common.Address) {
q.beats[addr] = time.Now()
if _, ok := q.beats[addr]; ok {
q.beats[addr] = time.Now()
}
}
func (q *queue) addresses() []common.Address {