mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Filter headers-only blocks out of parentChildren when selecting virtualSelectedParent (#1337)
This commit is contained in:
parent
1abffd472c
commit
d6fe9a3017
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user