Unverified Commit 14bef9a2 authored by Péter Szilágyi's avatar Péter Szilágyi Committed by GitHub

core: fix unnecessary ancestor lookup after a fast sync (#17825)

parent d3a773c2
...@@ -219,15 +219,15 @@ func (c *ChainIndexer) eventLoop(currentHeader *types.Header, events chan ChainE ...@@ -219,15 +219,15 @@ func (c *ChainIndexer) eventLoop(currentHeader *types.Header, events chan ChainE
} }
header := ev.Block.Header() header := ev.Block.Header()
if header.ParentHash != prevHash { if header.ParentHash != prevHash {
// Reorg to the common ancestor (might not exist in light sync mode, skip reorg then) // Reorg to the common ancestor if needed (might not exist in light sync mode, skip reorg then)
// TODO(karalabe, zsfelfoldi): This seems a bit brittle, can we detect this case explicitly? // TODO(karalabe, zsfelfoldi): This seems a bit brittle, can we detect this case explicitly?
// TODO(karalabe): This operation is expensive and might block, causing the event system to if rawdb.ReadCanonicalHash(c.chainDb, prevHeader.Number.Uint64()) != prevHash {
// potentially also lock up. We need to do with on a different thread somehow.
if h := rawdb.FindCommonAncestor(c.chainDb, prevHeader, header); h != nil { if h := rawdb.FindCommonAncestor(c.chainDb, prevHeader, header); h != nil {
c.newHead(h.Number.Uint64(), true) c.newHead(h.Number.Uint64(), true)
} }
} }
}
c.newHead(header.Number.Uint64(), false) c.newHead(header.Number.Uint64(), false)
prevHeader, prevHash = header, header.Hash() prevHeader, prevHash = header, header.Hash()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment