diff --git a/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go b/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go index 629a4bd4b..e4ea5ccbb 100644 --- a/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go +++ b/domain/consensus/processes/consensusstatemanager/add_block_to_virtual.go @@ -129,7 +129,8 @@ func (csm *consensusStateManager) calculateNewTips( if err != nil { return nil, err } - log.Debugf("The current tips are: %s", currentTips) + log.Debugf("The number of tips is: %d", len(currentTips)) + log.Tracef("The current tips are: %s", currentTips) newTipParents, err := csm.dagTopologyManager.Parents(stagingArea, newTipHash) if err != nil { @@ -151,7 +152,8 @@ func (csm *consensusStateManager) calculateNewTips( newTips = append(newTips, currentTip) } } - log.Debugf("The calculated new tips are: %s", newTips) + log.Debugf("The new number of tips is: %d", len(newTips)) + log.Tracef("The new tips are: %s", newTips) return newTips, nil } diff --git a/domain/consensus/processes/consensusstatemanager/pick_virtual_parents.go b/domain/consensus/processes/consensusstatemanager/pick_virtual_parents.go index c49ddfd83..40be9ed06 100644 --- a/domain/consensus/processes/consensusstatemanager/pick_virtual_parents.go +++ b/domain/consensus/processes/consensusstatemanager/pick_virtual_parents.go @@ -2,6 +2,7 @@ package consensusstatemanager import ( "github.com/kaspanet/kaspad/infrastructure/logger" + "github.com/kaspanet/kaspad/util/math" "github.com/pkg/errors" "github.com/kaspanet/kaspad/domain/consensus/model" @@ -34,7 +35,16 @@ func (csm *consensusStateManager) pickVirtualParents(stagingArea *model.StagingA } log.Debugf("The selected parent of the virtual is: %s", virtualSelectedParent) - candidates := candidatesHeap.ToSlice() + // Limit to maxBlockParents*3 candidates, that way we don't go over thousands of tips when the network isn't healthy. + // There's no specific reason for a factor of 3, and its not a consensus rule, just an estimation saying we probably + // don't want to consider and calculate 3 times the amount of candidates for the set of parents. + maxCandidates := int(csm.maxBlockParents) * 3 + candidateAllocationSize := math.MinInt(maxCandidates, candidatesHeap.Len()) + candidates := make([]*externalapi.DomainHash, 0, candidateAllocationSize) + for len(candidates) < maxCandidates && candidatesHeap.Len() > 0 { + candidates = append(candidates, candidatesHeap.Pop()) + } + // prioritize half the blocks with highest blueWork and half with lowest, so the network will merge splits faster. if len(candidates) >= int(csm.maxBlockParents) { // We already have the selectedParent, so we're left with csm.maxBlockParents-1. @@ -45,12 +55,6 @@ func (csm *consensusStateManager) pickVirtualParents(stagingArea *model.StagingA end-- } } - // Limit to maxBlockParents*3 candidates, that way we don't go over thousands of tips when the network isn't healthy. - // There's no specific reason for a factor of 3, and its not a consensus rule, just an estimation saying we probably - // don't want to consider and calculate 3 times the amount of candidates for the set of parents. - if len(candidates) > int(csm.maxBlockParents)*3 { - candidates = candidates[:int(csm.maxBlockParents)*3] - } selectedVirtualParents := []*externalapi.DomainHash{virtualSelectedParent} mergeSetSize := uint64(1) // starts counting from 1 because selectedParent is already in the mergeSet diff --git a/stability-tests/run/run-fast.sh b/stability-tests/run/run-fast.sh index 93c442958..d50cb4c2f 100755 --- a/stability-tests/run/run-fast.sh +++ b/stability-tests/run/run-fast.sh @@ -38,6 +38,10 @@ echo "Running reorg" cd "${PROJECT_ROOT}/reorg/run" && ./run.sh || failedTests+=("reorg") echo "Done running reorg" +echo "Running many-tips" +cd "${PROJECT_ROOT}/many-tips/run" && ./run.sh || failedTests+=("many-tips") +echo "Done running many-tips" + echo "Running netsync - fast" cd "${PROJECT_ROOT}/netsync/run" && ./run-fast.sh || failedTests+=("netsync") echo "Done running netsync - fast" diff --git a/stability-tests/run/run-slow.sh b/stability-tests/run/run-slow.sh index 509404eb5..94d4cc19d 100755 --- a/stability-tests/run/run-slow.sh +++ b/stability-tests/run/run-slow.sh @@ -34,6 +34,10 @@ echo "Running orphans" cd "${PROJECT_ROOT}/orphans/run" && ./run.sh || failedTests+=("orphans") echo "Done running orphans" +echo "Running many-tips" +cd "${PROJECT_ROOT}/many-tips/run" && ./run.sh || failedTests+=("many-tips") +echo "Done running many-tips" + echo "Running reorg" cd "${PROJECT_ROOT}/reorg/run" && ./run-full-finality-window-reorg.sh || failedTests+=("reorg") echo "Done running reorg"