core: verify state too when deduping existing blocks

This commit is contained in:
Péter Szilágyi 2017-10-03 15:08:58 +03:00
parent c2d93ded35
commit a26f669e34
No known key found for this signature in database
GPG key ID: E9AE538CEDF8293D

View file

@ -792,15 +792,14 @@ func (bc *BlockChain) WriteBlockAndState(block *types.Block, receipts []*types.R
if ptd == nil {
return NonStatTy, consensus.ErrUnknownAncestor
}
// If the block is already known, skip it
if bc.HasBlockAndState(block.Hash()) {
return SideStatTy, nil
}
// Make sure no inconsistent state is leaked during insertion
bc.mu.Lock()
defer bc.mu.Unlock()
if bc.HasBlock(block.Hash(), block.NumberU64()) {
log.Trace("Block existed", "hash", block.Hash())
return
}
localTd := bc.GetTd(bc.currentBlock.Hash(), bc.currentBlock.NumberU64())
externTd := new(big.Int).Add(block.Difficulty(), ptd)