From af93ad5e3014f839cb18f2e265506c4c5181dbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 25 Oct 2017 11:59:07 +0300 Subject: [PATCH] core: add a workaround for light sync --- core/chain_indexer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/chain_indexer.go b/core/chain_indexer.go index b8c588efe3..7e7500dc85 100644 --- a/core/chain_indexer.go +++ b/core/chain_indexer.go @@ -201,7 +201,11 @@ func (c *ChainIndexer) eventLoop(currentHeader *types.Header, events chan ChainE } header := ev.Block.Header() if header.ParentHash != prevHash { - c.newHead(FindCommonAncestor(c.chainDb, prevHeader, header).Number.Uint64(), true) + // Reorg to the common ancestor (might not exist in light sync mode, skip reorg then) + // TODO(karalabe, zsfelfoldi): This seems a bit brittle, can we detect this case explicitly? + if h := FindCommonAncestor(c.chainDb, prevHeader, header); h != nil { + c.newHead(h.Number.Uint64(), true) + } } c.newHead(header.Number.Uint64(), false)