From e4660a1181d19c6c50ebf77eb3ff3865948c2d63 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 19 Jun 2023 01:58:04 -0400 Subject: [PATCH] core/txpool/legacypool: handle missing head in reset (#27479) Fixes #27301, a crash that could occur during txpool reorg handling. --- core/txpool/legacypool/legacypool.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index fc6fc43bdd10..3464fe212f56 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1283,6 +1283,14 @@ func (pool *LegacyPool) reset(oldHead, newHead *types.Header) { "old", oldHead.Hash(), "oldnum", oldNum, "new", newHead.Hash(), "newnum", newNum) // We still need to update the current state s.th. the lost transactions can be readded by the user } else { + if add == nil { + // if the new head is nil, it means that something happened between + // the firing of newhead-event and _now_: most likely a + // reorg caused by sync-reversion or explicit sethead back to an + // earlier block. + log.Warn("New head missing in txpool reset", "number", newHead.Number, "hash", newHead.Hash()) + return + } for rem.NumberU64() > add.NumberU64() { discarded = append(discarded, rem.Transactions()...) if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil {