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:
parent
ad65bee735
commit
7390a62a8d
1 changed files with 4 additions and 5 deletions
7
chain.go
7
chain.go
|
@ -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
|
||||
|
||||
// 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)
|
||||
|
||||
// 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 {
|
||||
// Find the fork point.
|
||||
fork := node
|
||||
for ; fork.parent != nil; fork = fork.parent {
|
||||
|
|
Loading…
Add table
Reference in a new issue