[NOD-79] Detach parents from block template node after CheckConnectBlockTemplate (#226)

* [NOD-79] Detach parents from block template node after CheckConnectBlockTemplate

* [NOD-79] Fix typo
This commit is contained in:
Ori Newman 2019-03-25 14:45:33 +02:00 committed by stasatdaglabs
parent 0a30837aac
commit 6225728138
2 changed files with 10 additions and 2 deletions

View File

@ -1201,7 +1201,7 @@ func (dag *BlockDAG) CheckConnectBlockTemplate(block *util.Block) error {
header := block.MsgBlock().Header
parentHashes := header.ParentHashes
if !tips.hashesEqual(parentHashes) {
str := fmt.Sprintf("parent blocks must be the currents tips %s, "+
str := fmt.Sprintf("parent blocks must be the current tips %s, "+
"instead got %v", tips, parentHashes)
return ruleError(ErrParentBlockNotCurrentTips, str)
}
@ -1221,7 +1221,10 @@ func (dag *BlockDAG) CheckConnectBlockTemplate(block *util.Block) error {
return err
}
_, err = dag.checkConnectToPastUTXO(newBlockNode(&header, dag.virtual.tips(), dag.dagParams.K),
templateNode := newBlockNode(&header, dag.virtual.tips(), dag.dagParams.K)
defer templateNode.detachFromParents()
_, err = dag.checkConnectToPastUTXO(templateNode,
dag.UTXOSet(), block.Transactions(), false)
return err

View File

@ -121,6 +121,11 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
"block 4: %v", err)
}
blockNode3 := dag.index.LookupNode(blocks[3].Hash())
if blockNode3.children.containsHash(blocks[4].Hash()) {
t.Errorf("Block 4 wasn't successfully detached as a child from block3")
}
// Block 3a should fail to connect since does not build on chain tip.
err = dag.CheckConnectBlockTemplate(blocks[5])
if err == nil {