teaandcode / TestChain

TestChain C++ tutorial
MIT License
94 stars 71 forks source link

A small bug fix #3

Closed s0sasaki closed 5 years ago

knasher commented 5 years ago

What bug does this code fix? The hash is already calculated on instantiation of the block, you change will mean the hash will be calculated twice before it is checked; which would waste both time and computational resources.

s0sasaki commented 5 years ago

@knasher A new block's sPrevHash is changed in Blockchain::AddBlock after Block::Block and before Block::MineBlock. If sHash is not calculated in Block::MineBlock, it can be incompatible with sPrevHash.

knasher commented 5 years ago

Ah yes, well spotted! In that case, it might be worth removing the initial CalculateHash call from the constructor, what do you think?

s0sasaki commented 5 years ago

@knasher I think we should keep the initial calculateHash for the genesis block!