core: fix chain reorged if genesis parentHash not empty

If parentHash in genesis.json is set and not 0x0000... . When chain reorged , processSection will return error ""chain reorged during section processing"
This commit is contained in:
Liu Peng 2018-11-13 10:07:49 +08:00 committed by GitHub
parent 1212c7b844
commit c3e81107e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -325,8 +325,13 @@ func (c *ChainIndexer) updateLoop() {
// Cache the current section count and head to allow unlocking the mutex // Cache the current section count and head to allow unlocking the mutex
section := c.storedSections section := c.storedSections
var oldHead common.Hash var oldHead common.Hash
var initParent common.Hash
if section > 0 { if section > 0 {
oldHead = c.SectionHead(section - 1) oldHead = c.SectionHead(section - 1)
} else if section == 0 {
hash := rawdb.ReadCanonicalHash(c.chainDb, 0)
initParent = rawdb.ReadHeader(c.chainDb, hash, 0).ParentHash
oldHead = initParent
} }
// Process the newly defined section in the background // Process the newly defined section in the background
c.lock.Unlock() c.lock.Unlock()
@ -343,7 +348,7 @@ func (c *ChainIndexer) updateLoop() {
c.lock.Lock() c.lock.Lock()
// If processing succeeded and no reorgs occcurred, mark the section completed // If processing succeeded and no reorgs occcurred, mark the section completed
if err == nil && oldHead == c.SectionHead(section-1) { if err == nil && (section > 0 && oldHead == c.SectionHead(section-1) || (section == 0 && oldHead == initParent)) {
c.setSectionHead(section, newHead) c.setSectionHead(section, newHead)
c.setValidSections(section + 1) c.setValidSections(section + 1)
if c.storedSections == c.knownSections && updating { if c.storedSections == c.knownSections && updating {