From 671ea27fec162fc70d0417c0b311371dd3b2337e Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 17 Apr 2025 13:07:55 +0800 Subject: [PATCH] core/txpool: fix panic in txpool reset --- core/txpool/txpool.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 083aac92c6..fbfcf5e149 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -245,13 +245,15 @@ func (p *TxPool) loop(head *types.Header) { // Try to inject a busy marker and start a reset if successful select { case resetBusy <- struct{}{}: - statedb, err := p.chain.StateAt(newHead.Root) - if err != nil { - log.Crit("Failed to reset txpool state", "err", err) + // Updates the statedb with the new chain head. The head state may be + // unavailable if the initial state sync has not yet completed. + if statedb, err := p.chain.StateAt(newHead.Root); err != nil { + log.Error("Failed to reset txpool state", "err", err) + } else { + p.stateLock.Lock() + p.state = statedb + p.stateLock.Unlock() } - p.stateLock.Lock() - p.state = statedb - p.stateLock.Unlock() // Busy marker injected, start a new subpool reset go func(oldHead, newHead *types.Header) {