Skip to content

Commit 335914a

Browse files
authored
les: fix serverHandler crash after setHead (#24200)
1 parent 3ccd6b6 commit 335914a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

les/server_handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,10 @@ func (h *serverHandler) broadcastLoop() {
421421
}
422422
var reorg uint64
423423
if lastHead != nil {
424-
reorg = lastHead.Number.Uint64() - rawdb.FindCommonAncestor(h.chainDb, header, lastHead).Number.Uint64()
424+
// If a setHead has been performed, the common ancestor can be nil.
425+
if ancestor := rawdb.FindCommonAncestor(h.chainDb, header, lastHead); ancestor != nil {
426+
reorg = lastHead.Number.Uint64() - ancestor.Number.Uint64()
427+
}
425428
}
426429
lastHead, lastTd = header, td
427430
log.Debug("Announcing block to peers", "number", number, "hash", hash, "td", td, "reorg", reorg)

0 commit comments

Comments
 (0)