core/txpool: fix panic in txpool reset

This commit is contained in:
Gary Rong 2025-04-17 13:07:55 +08:00
parent a874ea621f
commit 671ea27fec

View file

@ -245,13 +245,15 @@ func (p *TxPool) loop(head *types.Header) {
// Try to inject a busy marker and start a reset if successful // Try to inject a busy marker and start a reset if successful
select { select {
case resetBusy <- struct{}{}: case resetBusy <- struct{}{}:
statedb, err := p.chain.StateAt(newHead.Root) // Updates the statedb with the new chain head. The head state may be
if err != nil { // unavailable if the initial state sync has not yet completed.
log.Crit("Failed to reset txpool state", "err", err) 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 // Busy marker injected, start a new subpool reset
go func(oldHead, newHead *types.Header) { go func(oldHead, newHead *types.Header) {