Skip to content

Commit 9a69053

Browse files
authored
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.
1 parent 628ff79 commit 9a69053

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

core/txpool/legacypool/legacypool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ type Config struct {
151151
AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account
152152
GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts
153153

154-
Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
154+
Lifetime time.Duration // Maximum amount of time an account can remain stale in the non-executable pool
155155
}
156156

157157
// DefaultConfig contains the default configurations for the transaction pool.
@@ -778,7 +778,7 @@ func (pool *LegacyPool) add(tx *types.Transaction) (replaced bool, err error) {
778778
pool.queueTxEvent(tx)
779779
log.Trace("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To())
780780

781-
// Successful promotion, bump the heartbeat
781+
// Successful replacement. If needed, bump the heartbeat giving more time to queued txs.
782782
pool.queue.bump(from)
783783
return old != nil, nil
784784
}
@@ -871,7 +871,7 @@ func (pool *LegacyPool) promoteTx(addr common.Address, hash common.Hash, tx *typ
871871
// Set the potentially new pending nonce and notify any subsystems of the new tx
872872
pool.pendingNonces.set(addr, tx.Nonce()+1)
873873

874-
// Successful promotion, bump the heartbeat
874+
// Successful promotion, bump the heartbeat, giving more time to queued txs.
875875
pool.queue.bump(addr)
876876
return true
877877
}

core/txpool/legacypool/queue.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ func (q *queue) get(addr common.Address) (*list, bool) {
8888
return l, ok
8989
}
9090

91+
// bump updates the heartbeat for the given account address.
92+
// If the address is unknown, the call is a no-op.
9193
func (q *queue) bump(addr common.Address) {
92-
q.beats[addr] = time.Now()
94+
if _, ok := q.beats[addr]; ok {
95+
q.beats[addr] = time.Now()
96+
}
9397
}
9498

9599
func (q *queue) addresses() []common.Address {

0 commit comments

Comments
 (0)