Filter headers-only blocks out of parentChildren when selecting virtualSelectedParent (#1337)

This commit is contained in:
Svarog 2021-01-03 14:35:03 +02:00 committed by GitHub
parent 1abffd472c
commit d6fe9a3017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 11 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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