From 335914a63afae019a2b901d88f13b28eb0d6ca58 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Wed, 5 Jan 2022 16:40:45 +0100 Subject: [PATCH] les: fix serverHandler crash after setHead (#24200) --- les/server_handler.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/les/server_handler.go b/les/server_handler.go index f36a87a513..da06ac315e 100644 --- a/les/server_handler.go +++ b/les/server_handler.go @@ -421,7 +421,10 @@ func (h *serverHandler) broadcastLoop() { } var reorg uint64 if lastHead != nil { - reorg = lastHead.Number.Uint64() - rawdb.FindCommonAncestor(h.chainDb, header, lastHead).Number.Uint64() + // If a setHead has been performed, the common ancestor can be nil. + if ancestor := rawdb.FindCommonAncestor(h.chainDb, header, lastHead); ancestor != nil { + reorg = lastHead.Number.Uint64() - ancestor.Number.Uint64() + } } lastHead, lastTd = header, td log.Debug("Announcing block to peers", "number", number, "hash", hash, "td", td, "reorg", reorg)