mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Check blue score before requesting a pruning proof (#1835)
* Check blue score before requesting a pruning proof * BuildPruningPointProof should return empty proof if the pruning point is genesis * Don't fail many-tips if kaspad exits ungracefully
This commit is contained in:
parent
77a344cc29
commit
99aaacd649
@ -43,12 +43,12 @@ func (flow *handleRelayInvsFlow) shouldSyncAndShouldDownloadHeadersProof(highBlo
|
||||
highestSharedBlockFound bool) (shouldDownload, shouldSync bool, err error) {
|
||||
|
||||
if !highestSharedBlockFound {
|
||||
hasMoreBlueWorkThanSelectedTip, err := flow.checkIfHighHashHasMoreBlueWorkThanSelectedTip(highBlock)
|
||||
hasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore, err := flow.checkIfHighHashHasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore(highBlock)
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
if hasMoreBlueWorkThanSelectedTip {
|
||||
if hasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore {
|
||||
return true, true, nil
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ func (flow *handleRelayInvsFlow) shouldSyncAndShouldDownloadHeadersProof(highBlo
|
||||
return false, true, nil
|
||||
}
|
||||
|
||||
func (flow *handleRelayInvsFlow) checkIfHighHashHasMoreBlueWorkThanSelectedTip(highBlock *externalapi.DomainBlock) (bool, error) {
|
||||
func (flow *handleRelayInvsFlow) checkIfHighHashHasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore(highBlock *externalapi.DomainBlock) (bool, error) {
|
||||
headersSelectedTip, err := flow.Domain().Consensus().GetHeadersSelectedTip()
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -69,6 +69,10 @@ func (flow *handleRelayInvsFlow) checkIfHighHashHasMoreBlueWorkThanSelectedTip(h
|
||||
return false, err
|
||||
}
|
||||
|
||||
if highBlock.Header.BlueScore() < headersSelectedTipInfo.BlueScore+flow.Config().NetParams().PruningDepth() {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return highBlock.Header.BlueWork().Cmp(headersSelectedTipInfo.BlueWork) > 0, nil
|
||||
}
|
||||
|
||||
|
@ -88,6 +88,10 @@ func (ppm *pruningProofManager) BuildPruningPointProof(stagingArea *model.Stagin
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if pruningPoint.Equal(ppm.genesisHash) {
|
||||
return &externalapi.PruningPointProof{}, nil
|
||||
}
|
||||
|
||||
pruningPointHeader, err := ppm.blockHeaderStore.BlockHeader(ppm.databaseContext, stagingArea, pruningPoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -245,13 +249,18 @@ func (ppm *pruningProofManager) blockAtDepth(stagingArea *model.StagingArea, gho
|
||||
|
||||
func (ppm *pruningProofManager) ValidatePruningPointProof(pruningPointProof *externalapi.PruningPointProof) error {
|
||||
stagingArea := model.NewStagingArea()
|
||||
|
||||
if len(pruningPointProof.Headers) == 0 {
|
||||
return errors.Wrap(ruleerrors.ErrPruningProofEmpty, "pruning proof is empty")
|
||||
}
|
||||
|
||||
level0Headers := pruningPointProof.Headers[0]
|
||||
pruningPointHeader := level0Headers[len(level0Headers)-1]
|
||||
pruningPoint := consensushashing.HeaderHash(pruningPointHeader)
|
||||
pruningPointBlockLevel := pow.BlockLevel(pruningPointHeader)
|
||||
maxLevel := len(pruningPointHeader.Parents()) - 1
|
||||
if maxLevel >= len(pruningPointProof.Headers) {
|
||||
return errors.Wrapf(ruleerrors.ErrPruningProofMissingBlockLevels, "proof has only %d levels while pruning point "+
|
||||
return errors.Wrapf(ruleerrors.ErrPruningProofEmpty, "proof has only %d levels while pruning point "+
|
||||
"has parents from %d levels", len(pruningPointProof.Headers), maxLevel+1)
|
||||
}
|
||||
|
||||
|
@ -238,6 +238,7 @@ var (
|
||||
ErrPruningProofInsufficientBlueWork = newRuleError("ErrPruningProofInsufficientBlueWork")
|
||||
ErrPruningProofMissingBlockAtDepthMFromNextLevel = newRuleError("ErrPruningProofMissingBlockAtDepthMFromNextLevel")
|
||||
ErrPruningProofMissesBlocksBelowPruningPoint = newRuleError("ErrPruningProofMissesBlocksBelowPruningPoint")
|
||||
ErrPruningProofEmpty = newRuleError("ErrPruningProofEmpty")
|
||||
ErrWrongCoinbaseSubsidy = newRuleError("ErrWrongCoinbaseSubsidy")
|
||||
)
|
||||
|
||||
|
@ -132,7 +132,8 @@ func startNode() (teardown func(), err error) {
|
||||
panics.Exit(log, fmt.Sprintf("kaspadCmd closed unexpectedly: %s. See logs at: %s", err, dataDir))
|
||||
}
|
||||
if !strings.Contains(err.Error(), "signal: killed") {
|
||||
panics.Exit(log, fmt.Sprintf("kaspadCmd closed with an error: %s. See logs at: %s", err, dataDir))
|
||||
// TODO: Panic here and check why sometimes kaspad closes ungracefully
|
||||
log.Errorf("kaspadCmd closed with an error: %s. See logs at: %s", err, dataDir)
|
||||
}
|
||||
}
|
||||
processesStoppedWg.Done()
|
||||
@ -246,7 +247,8 @@ func mineLoopUntilHavingOnlyOneTipInDAG(rpcClient *rpc.Client, miningAddress uti
|
||||
panics.Exit(log, fmt.Sprintf("minerCmd closed unexpectedly: %s.", err))
|
||||
}
|
||||
if !strings.Contains(err.Error(), "signal: killed") {
|
||||
panics.Exit(log, fmt.Sprintf("minerCmd closed with an error: %s.", err))
|
||||
// TODO: Panic here and check why sometimes miner closes ungracefully
|
||||
log.Errorf("minerCmd closed with an error: %s", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user