Skip to content

Commit 671ea27

Browse files
committed
core/txpool: fix panic in txpool reset
1 parent a874ea6 commit 671ea27

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

core/txpool/txpool.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,15 @@ func (p *TxPool) loop(head *types.Header) {
245245
// Try to inject a busy marker and start a reset if successful
246246
select {
247247
case resetBusy <- struct{}{}:
248-
statedb, err := p.chain.StateAt(newHead.Root)
249-
if err != nil {
250-
log.Crit("Failed to reset txpool state", "err", err)
248+
// Updates the statedb with the new chain head. The head state may be
249+
// unavailable if the initial state sync has not yet completed.
250+
if statedb, err := p.chain.StateAt(newHead.Root); err != nil {
251+
log.Error("Failed to reset txpool state", "err", err)
252+
} else {
253+
p.stateLock.Lock()
254+
p.state = statedb
255+
p.stateLock.Unlock()
251256
}
252-
p.stateLock.Lock()
253-
p.state = statedb
254-
p.stateLock.Unlock()
255257

256258
// Busy marker injected, start a new subpool reset
257259
go func(oldHead, newHead *types.Header) {

0 commit comments

Comments
 (0)