Skip to content

Commit

Permalink
check block exist with comparison of block hash(#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
bysomeone authored and 33cn committed Apr 18, 2022
1 parent 66b8174 commit 3d92813
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions blockchain/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ func (chain *BlockChain) blockExists(hash []byte) bool {
if blockheader == nil || err != nil {
return false
}
//block存在数据库中时,需要进一步确认是否在主链上。不在主链上返回false
//因为maybeAccept会存header,但是如果还没connect执行就重启了,也不能认为存在,需要执行此区块
_, err = chain.blockStore.GetBlockHashByHeight(blockheader.Height)
return err == nil
//assert block hash(not equal for side chain)
storeHash, err := chain.blockStore.GetBlockHashByHeight(blockheader.Height)
return err == nil && bytes.Equal(storeHash, hash)
}

// 尝试接受此block
Expand Down

0 comments on commit 3d92813

Please sign in to comment.