Skip to content

Commit

Permalink
core: don't cache zero nonce in txNoncer (#25603)
Browse files Browse the repository at this point in the history
This changes the nonce cache used by TxPool to not store cached
nonces for non-existing accounts.
  • Loading branch information
dbadoy authored Sep 16, 2022
1 parent 8ade5e6 commit ada603f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 6 additions & 2 deletions core/tx_noncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func (txn *txNoncer) get(addr common.Address) uint64 {
defer txn.lock.Unlock()

if _, ok := txn.nonces[addr]; !ok {
txn.nonces[addr] = txn.fallback.GetNonce(addr)
if nonce := txn.fallback.GetNonce(addr); nonce != 0 {
txn.nonces[addr] = nonce
}
}
return txn.nonces[addr]
}
Expand All @@ -70,7 +72,9 @@ func (txn *txNoncer) setIfLower(addr common.Address, nonce uint64) {
defer txn.lock.Unlock()

if _, ok := txn.nonces[addr]; !ok {
txn.nonces[addr] = txn.fallback.GetNonce(addr)
if nonce := txn.fallback.GetNonce(addr); nonce != 0 {
txn.nonces[addr] = nonce
}
}
if txn.nonces[addr] <= nonce {
return
Expand Down
3 changes: 0 additions & 3 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,6 @@ func (pool *TxPool) SetGasPrice(price *big.Int) {
// Nonce returns the next nonce of an account, with all transactions executable
// by the pool already applied on top.
func (pool *TxPool) Nonce(addr common.Address) uint64 {
pool.mu.RLock()
defer pool.mu.RUnlock()

return pool.pendingNonces.get(addr)
}

Expand Down

0 comments on commit ada603f

Please sign in to comment.