From a26f669e341664aec752095000b8c7a1d5741b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 3 Oct 2017 15:08:58 +0300 Subject: [PATCH] core: verify state too when deduping existing blocks --- core/blockchain.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 235c1f3da2..c896408b33 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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)