Correct internal node children on reorg.

Previously the code was only adding a new block node as a child in the
inernal node index for the cases it extended the main chain or a side
chain and not for a node which caused a reorg.  This resulted in the block
node pruning code not clearing the parent link of reorged nodes which
ultimately led to a sanity check error accordingly.

This commit resolves the issue by ensuring new block nodes are added as
children of their respective parents in all cases.

Closes #4.
This commit is contained in:
Dave Collins 2014-01-28 13:34:42 -06:00
parent ad65bee735
commit 7390a62a8d

View file

@ -825,7 +825,6 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error
if err != nil {
return err
}
}
// Disconnect blocks from the main chain.
@ -918,13 +917,13 @@ func (b *BlockChain) connectBestChain(node *blockNode, block *btcutil.Block, fas
b.blockCache[*node.hash] = block
b.index[*node.hash] = node
// Connect the parent node to this node.
node.inMainChain = false
node.parent.children = append(node.parent.children, node)
// We're extending (or creating) a side chain, but the cumulative
// work for this new side chain is not enough to make it the new chain.
if node.workSum.Cmp(b.bestChain.workSum) <= 0 {
// Connect the parent node to this node.
node.inMainChain = false
node.parent.children = append(node.parent.children, node)
// Find the fork point.
fork := node
for ; fork.parent != nil; fork = fork.parent {