diff --git a/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go b/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go index 5b8478974..4546c1c8f 100644 --- a/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go +++ b/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go @@ -3,14 +3,14 @@ package consensusstatemanager import ( "github.com/kaspanet/kaspad/domain/consensus/model" "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + "github.com/kaspanet/kaspad/infrastructure/logger" ) // AddBlock submits the given block to be added to the // current virtual. This process may result in a new virtual block // getting created func (csm *consensusStateManager) AddBlock(blockHash *externalapi.DomainHash) (*externalapi.SelectedParentChainChanges, error) { - log.Debugf("AddBlock start for block %s", blockHash) - defer log.Debugf("AddBlock end for block %s", blockHash) + logger.LogAndMeasureExecutionTime(log, "csm.AddBlock") log.Debugf("Resolving whether the block %s is the next virtual selected parent", blockHash) isCandidateToBeNextVirtualSelectedParent, err := csm.isCandidateToBeNextVirtualSelectedParent(blockHash) diff --git a/domain/consensus/processes/consensusstatemanager/check_finality_violation.go b/domain/consensus/processes/consensusstatemanager/check_finality_violation.go index 0ecea0242..7f3684894 100644 --- a/domain/consensus/processes/consensusstatemanager/check_finality_violation.go +++ b/domain/consensus/processes/consensusstatemanager/check_finality_violation.go @@ -58,6 +58,7 @@ func (csm *consensusStateManager) isViolatingFinality(blockHash *externalapi.Dom // On IBD it's pretty normal to get blocks in the anticone of the pruning // point, so we don't notify on cases when the pruning point is in the future // of the finality point. + log.Debugf("Block %s violates finality, but kaspad is currently doing IBD, so this is normal", blockHash) return true, false, nil } log.Debugf("Block %s does not violate finality", blockHash) diff --git a/domain/consensus/processes/consensusstatemanager/pick_virtual_parents.go b/domain/consensus/processes/consensusstatemanager/pick_virtual_parents.go index dbb947dad..85e9ba96f 100644 --- a/domain/consensus/processes/consensusstatemanager/pick_virtual_parents.go +++ b/domain/consensus/processes/consensusstatemanager/pick_virtual_parents.go @@ -114,23 +114,33 @@ func (csm *consensusStateManager) selectVirtualSelectedParent( } log.Debugf("The parents of block %s are: %s", selectedParentCandidate, candidateParents) for _, parent := range candidateParents { - parentChildren, err := csm.dagTopologyManager.Children(parent) + allParentChildren, err := csm.dagTopologyManager.Children(parent) if err != nil { return nil, err } + log.Debugf("The children of block %s are: %s", parent, allParentChildren) - // remove virtual from parentChildren if it's there - for i, parentChild := range parentChildren { + // remove virtual and any headers-only blocks from parentChildren if such are there + nonHeadersOnlyParentChildren := make([]*externalapi.DomainHash, 0, len(allParentChildren)) + for _, parentChild := range allParentChildren { if parentChild.Equal(model.VirtualBlockHash) { - parentChildren = append(parentChildren[:i], parentChildren[i+1:]...) - break + continue } - } - log.Debugf("The children of block %s are: %s", parent, parentChildren) - if disqualifiedCandidates.ContainsAllInSlice(parentChildren) { + parentChildStatus, err := csm.blockStatusStore.Get(csm.databaseContext, parentChild) + if err != nil { + return nil, err + } + if parentChildStatus == externalapi.StatusHeaderOnly { + continue + } + nonHeadersOnlyParentChildren = append(nonHeadersOnlyParentChildren, parentChild) + } + log.Debugf("The non-virtual, non-headers-only children of block %s are: %s", parent, nonHeadersOnlyParentChildren) + + if disqualifiedCandidates.ContainsAllInSlice(nonHeadersOnlyParentChildren) { log.Debugf("The disqualified set contains all the "+ - "children of %s. Adding it to the candidate heap", parentChildren) + "children of %s. Adding it to the candidate heap", nonHeadersOnlyParentChildren) err := candidatesHeap.Push(parent) if err != nil { return nil, err