瀏覽代碼

core: avoid write existing block again (#14849)

Mark 8 年之前
父節點
當前提交
4f9789b28d
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      core/blockchain.go

+ 5 - 0
core/blockchain.go

@@ -827,6 +827,11 @@ func (bc *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err er
 	bc.mu.Lock()
 	defer bc.mu.Unlock()
 
+	if bc.HasBlock(block.Hash()) {
+		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)