mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-08-23 11:03:16 +00:00

* Modify DefaultTimeout to 120 seconds A temporary workaround for nodes having trouble to sync (currently the download of pruning point related data during IBD takes more than 30 seconds) * Cache existence in reachability store * Cache block level in the header * Fix IBD indication on submit block * Add hardForkOmitGenesisFromParentsDAAScore logic * Fix NumThreads bug in the wallet * Get rid of ParentsAtLevel header method * Fix a bug in BuildPruningPointProof * Increase race detector timeout * Add cache to BuildPruningPointProof * Add comments and temp comment out go vet * Fix ParentsAtLevel * Dont fill empty parents * Change HardForkOmitGenesisFromParentsDAAScore in fast netsync test * Add --allow-submit-block-when-not-synced in stability tests * Fix TestPruning * Return fast tests * Fix off by one error on kaspawallet * Fetch only one block with trusted data at a time * Update fork DAA score * Don't ban for unexpected message type * Fix tests Co-authored-by: Michael Sutton <mikisiton2@gmail.com> Co-authored-by: Ori Newman <>
94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
package consensusstatemanager
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domain/consensus/model"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
|
"github.com/kaspanet/kaspad/util/staging"
|
|
"sort"
|
|
)
|
|
|
|
func (csm *consensusStateManager) ResolveVirtual(maxBlocksToResolve uint64) (bool, error) {
|
|
onEnd := logger.LogAndMeasureExecutionTime(log, "csm.ResolveVirtual")
|
|
defer onEnd()
|
|
|
|
readStagingArea := model.NewStagingArea()
|
|
tips, err := csm.consensusStateStore.Tips(readStagingArea, csm.databaseContext)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
var sortErr error
|
|
sort.Slice(tips, func(i, j int) bool {
|
|
selectedParent, err := csm.ghostdagManager.ChooseSelectedParent(readStagingArea, tips[i], tips[j])
|
|
if err != nil {
|
|
sortErr = err
|
|
return false
|
|
}
|
|
|
|
return selectedParent.Equal(tips[i])
|
|
})
|
|
if sortErr != nil {
|
|
return false, sortErr
|
|
}
|
|
|
|
var selectedTip *externalapi.DomainHash
|
|
isCompletelyResolved := true
|
|
for _, tip := range tips {
|
|
log.Debugf("Resolving tip %s", tip)
|
|
resolveStagingArea := model.NewStagingArea()
|
|
unverifiedBlocks, err := csm.getUnverifiedChainBlocks(resolveStagingArea, tip)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
resolveTip := tip
|
|
hasMoreUnverifiedThanMax := maxBlocksToResolve != 0 && uint64(len(unverifiedBlocks)) > maxBlocksToResolve
|
|
if hasMoreUnverifiedThanMax {
|
|
resolveTip = unverifiedBlocks[uint64(len(unverifiedBlocks))-maxBlocksToResolve]
|
|
log.Debugf("Has more than %d blocks to resolve. Changing the resolve tip to %s", maxBlocksToResolve, resolveTip)
|
|
}
|
|
|
|
blockStatus, reversalData, err := csm.resolveBlockStatus(resolveStagingArea, resolveTip, true)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if blockStatus == externalapi.StatusUTXOValid {
|
|
selectedTip = resolveTip
|
|
isCompletelyResolved = !hasMoreUnverifiedThanMax
|
|
|
|
err = staging.CommitAllChanges(csm.databaseContext, resolveStagingArea)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if reversalData != nil {
|
|
err = csm.ReverseUTXODiffs(resolveTip, reversalData)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
if selectedTip == nil {
|
|
log.Warnf("Non of the DAG tips are valid")
|
|
return true, nil
|
|
}
|
|
|
|
updateVirtualStagingArea := model.NewStagingArea()
|
|
_, err = csm.updateVirtualWithParents(updateVirtualStagingArea, []*externalapi.DomainHash{selectedTip})
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
err = staging.CommitAllChanges(csm.databaseContext, updateVirtualStagingArea)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return isCompletelyResolved, nil
|
|
}
|