Skip to content

Commit 31a4b73

Browse files
committed
check block exist with comparison of block hash(33cn#1236)
1 parent ec1bead commit 31a4b73

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

blockchain/process.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ func (chain *BlockChain) blockExists(hash []byte) bool {
137137
if blockheader == nil || err != nil {
138138
return false
139139
}
140-
//block存在数据库中时,需要进一步确认是否在主链上。不在主链上返回false
141-
//因为maybeAccept会存header,但是如果还没connect执行就重启了,也不能认为存在,需要执行此区块
142-
_, err = chain.blockStore.GetBlockHashByHeight(blockheader.Height)
143-
return err == nil
140+
//assert block hash(not equal for side chain)
141+
storeHash, err := chain.blockStore.GetBlockHashByHeight(blockheader.Height)
142+
return err == nil && bytes.Equal(storeHash, hash)
144143
}
145144

146145
// 尝试接受此block

0 commit comments

Comments
 (0)