Skip to content

Commit ada603f

Browse files
authored
core: don't cache zero nonce in txNoncer (#25603)
This changes the nonce cache used by TxPool to not store cached nonces for non-existing accounts.
1 parent 8ade5e6 commit ada603f

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

core/tx_noncer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func (txn *txNoncer) get(addr common.Address) uint64 {
4949
defer txn.lock.Unlock()
5050

5151
if _, ok := txn.nonces[addr]; !ok {
52-
txn.nonces[addr] = txn.fallback.GetNonce(addr)
52+
if nonce := txn.fallback.GetNonce(addr); nonce != 0 {
53+
txn.nonces[addr] = nonce
54+
}
5355
}
5456
return txn.nonces[addr]
5557
}
@@ -70,7 +72,9 @@ func (txn *txNoncer) setIfLower(addr common.Address, nonce uint64) {
7072
defer txn.lock.Unlock()
7173

7274
if _, ok := txn.nonces[addr]; !ok {
73-
txn.nonces[addr] = txn.fallback.GetNonce(addr)
75+
if nonce := txn.fallback.GetNonce(addr); nonce != 0 {
76+
txn.nonces[addr] = nonce
77+
}
7478
}
7579
if txn.nonces[addr] <= nonce {
7680
return

core/tx_pool.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ func (pool *TxPool) SetGasPrice(price *big.Int) {
463463
// Nonce returns the next nonce of an account, with all transactions executable
464464
// by the pool already applied on top.
465465
func (pool *TxPool) Nonce(addr common.Address) uint64 {
466-
pool.mu.RLock()
467-
defer pool.mu.RUnlock()
468-
469466
return pool.pendingNonces.get(addr)
470467
}
471468

0 commit comments

Comments
 (0)