Ensure height is set on block as well as the node.
Even though the code currently makes heavy use of nodes which will have the appropriate height, blocks which did not come from the database will not have a height set. As a result, this could possibly result in a height of 0 being used when unintended. By setting the block height in the block as soon as its known (regardless of the source), we can future proof against bugs that would likely be hard to track down.
This commit is contained in:
parent
6409879e14
commit
882d1c1687
1 changed files with 1 additions and 0 deletions
|
@ -28,6 +28,7 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block) error {
|
||||||
if prevNode != nil {
|
if prevNode != nil {
|
||||||
blockHeight = prevNode.height + 1
|
blockHeight = prevNode.height + 1
|
||||||
}
|
}
|
||||||
|
block.SetHeight(blockHeight)
|
||||||
|
|
||||||
// Ensure the difficulty specified in the block header matches the
|
// Ensure the difficulty specified in the block header matches the
|
||||||
// calculated difficulty based on the previous block and difficulty
|
// calculated difficulty based on the previous block and difficulty
|
||||||
|
|
Loading…
Reference in a new issue