mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[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:
parent
0a30837aac
commit
6225728138
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user