mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-76] Allow blocks that do not connect directly to all tips in CheckConnectBlockTemplate (#236)
* [NOD-76] Allow blocks that do not connect directly to all tips in CheckConnectBlockTemplate * [NOD-76] Fix typos in comments
This commit is contained in:
parent
20e24e3a23
commit
66fb7513f2
@ -1185,7 +1185,7 @@ func countSpentOutputs(block *util.Block) int {
|
||||
|
||||
// CheckConnectBlockTemplateWithLock fully validates that connecting the passed block to
|
||||
// the DAG does not violate any consensus rules, aside from the proof of
|
||||
// work requirement. The block must connect to the current tip of the main dag.
|
||||
// work requirement.
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (dag *BlockDAG) CheckConnectBlockTemplateWithLock(block *util.Block) error {
|
||||
@ -1202,16 +1202,7 @@ func (dag *BlockDAG) CheckConnectBlockTemplate(block *util.Block) error {
|
||||
// Skip the proof of work check as this is just a block template.
|
||||
flags := BFNoPoWCheck
|
||||
|
||||
// This only checks whether the block can be connected to the tip of the
|
||||
// current dag.
|
||||
tips := dag.virtual.tips()
|
||||
header := block.MsgBlock().Header
|
||||
parentHashes := header.ParentHashes
|
||||
if !tips.hashesEqual(parentHashes) {
|
||||
str := fmt.Sprintf("parent blocks must be the current tips %s, "+
|
||||
"instead got %v", tips, parentHashes)
|
||||
return ruleError(ErrParentBlockNotCurrentTips, str)
|
||||
}
|
||||
|
||||
err := dag.checkBlockSanity(block, flags)
|
||||
if err != nil {
|
||||
|
@ -121,11 +121,17 @@ func TestCheckConnectBlockTemplate(t *testing.T) {
|
||||
"block 4: %v", err)
|
||||
}
|
||||
|
||||
// Block 3a should fail to connect since does not build on chain tip.
|
||||
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 connect even though it does not build on dag tips.
|
||||
blocks[5].SetHeight(3) // set height manually because it was set to 0 in loadBlocks
|
||||
err = dag.CheckConnectBlockTemplate(blocks[5])
|
||||
if err == nil {
|
||||
t.Fatal("CheckConnectBlockTemplate: Did not received expected error " +
|
||||
"on block 3a")
|
||||
if err != nil {
|
||||
t.Fatal("CheckConnectBlockTemplate: Recieved unexpected error on " +
|
||||
"block 3a that connects below the tips")
|
||||
}
|
||||
|
||||
// Block 4 should connect even if proof of work is invalid.
|
||||
|
Loading…
x
Reference in New Issue
Block a user