mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-02-22 19:45:36 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca32eb6bbf | ||
|
|
061e65be93 | ||
|
|
9df231f810 | ||
|
|
09cebe6960 | ||
|
|
7c327683d3 | ||
|
|
c903a65def | ||
|
|
685c049a12 | ||
|
|
9b45e803d0 | ||
|
|
cb5e9b55b7 | ||
|
|
190e725dd0 | ||
|
|
20f16cf729 | ||
|
|
4d3f504b73 | ||
|
|
b5eda33488 |
@@ -13,7 +13,9 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/infrastructure/config"
|
"github.com/kaspanet/kaspad/infrastructure/config"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/logger"
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
||||||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
||||||
|
"github.com/kaspanet/kaspad/util/difficulty"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -64,6 +66,29 @@ func (flow *handleIBDFlow) start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleIBDFlow) runIBDIfNotRunning(block *externalapi.DomainBlock) error {
|
func (flow *handleIBDFlow) runIBDIfNotRunning(block *externalapi.DomainBlock) error {
|
||||||
|
highHash := consensushashing.BlockHash(block)
|
||||||
|
|
||||||
|
// Temp code to avoid IBD from lagging nodes publishing their side-chain
|
||||||
|
virtualSelectedParent, err := flow.Domain().Consensus().GetVirtualSelectedParent()
|
||||||
|
if err == nil {
|
||||||
|
virtualSelectedParentHeader, err := flow.Domain().Consensus().GetBlockHeader(virtualSelectedParent)
|
||||||
|
if err == nil {
|
||||||
|
if virtualSelectedParentHeader.DAAScore() > block.Header.DAAScore()+2641 {
|
||||||
|
virtualDifficulty := difficulty.CalcWork(virtualSelectedParentHeader.Bits())
|
||||||
|
var virtualSub, difficultyMul big.Int
|
||||||
|
if difficultyMul.Mul(virtualDifficulty, big.NewInt(180)).
|
||||||
|
Cmp(virtualSub.Sub(virtualSelectedParentHeader.BlueWork(), block.Header.BlueWork())) < 0 {
|
||||||
|
log.Criticalf("Avoiding IBD triggered by relay %s because it is coming from " +
|
||||||
|
"a deep (%d DAA score depth) side-chain which has much lower blue work (%d, %d)",
|
||||||
|
highHash,
|
||||||
|
virtualSelectedParentHeader.DAAScore()-block.Header.DAAScore(),
|
||||||
|
virtualSelectedParentHeader.BlueWork(), block.Header.BlueWork())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wasIBDNotRunning := flow.TrySetIBDRunning(flow.peer)
|
wasIBDNotRunning := flow.TrySetIBDRunning(flow.peer)
|
||||||
if !wasIBDNotRunning {
|
if !wasIBDNotRunning {
|
||||||
log.Debugf("IBD is already running")
|
log.Debugf("IBD is already running")
|
||||||
@@ -76,7 +101,6 @@ func (flow *handleIBDFlow) runIBDIfNotRunning(block *externalapi.DomainBlock) er
|
|||||||
flow.logIBDFinished(isFinishedSuccessfully)
|
flow.logIBDFinished(isFinishedSuccessfully)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
highHash := consensushashing.BlockHash(block)
|
|
||||||
log.Criticalf("IBD started with peer %s and highHash %s", flow.peer, highHash)
|
log.Criticalf("IBD started with peer %s and highHash %s", flow.peer, highHash)
|
||||||
log.Criticalf("Syncing blocks up to %s", highHash)
|
log.Criticalf("Syncing blocks up to %s", highHash)
|
||||||
log.Criticalf("Trying to find highest shared chain block with peer %s with high hash %s", flow.peer, highHash)
|
log.Criticalf("Trying to find highest shared chain block with peer %s with high hash %s", flow.peer, highHash)
|
||||||
@@ -85,27 +109,6 @@ func (flow *handleIBDFlow) runIBDIfNotRunning(block *externalapi.DomainBlock) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Criticalf("Found highest shared chain block %s with peer %s", highestSharedBlockHash, flow.peer)
|
log.Criticalf("Found highest shared chain block %s with peer %s", highestSharedBlockHash, flow.peer)
|
||||||
checkpoint, err := externalapi.NewDomainHashFromString("05ff0f2e1d201dcaee7c5e567cc2c1d42ca3cce9fefbd3b519dc68b5bb89d0b9")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := flow.Domain().Consensus().GetBlockInfo(checkpoint)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if info.Exists {
|
|
||||||
isInSelectedParentChainOf, err := flow.Domain().Consensus().IsInSelectedParentChainOf(checkpoint, highestSharedBlockHash)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isInSelectedParentChainOf {
|
|
||||||
log.Criticalf("Stopped IBD because the checkpoint %s is not in the selected chain of %s", checkpoint, highestSharedBlockHash)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldDownloadHeadersProof, shouldSync, err := flow.shouldSyncAndShouldDownloadHeadersProof(block, highestSharedBlockFound)
|
shouldDownloadHeadersProof, shouldSync, err := flow.shouldSyncAndShouldDownloadHeadersProof(block, highestSharedBlockFound)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -329,7 +332,6 @@ func (flow *handleIBDFlow) syncPruningPointFutureHeaders(consensus externalapi.C
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
count := 0
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case ibdBlocksMessage, ok := <-blockHeadersMessageChan:
|
case ibdBlocksMessage, ok := <-blockHeadersMessageChan:
|
||||||
|
|||||||
@@ -336,12 +336,12 @@ func (csm *consensusStateManager) boundedMergeBreakingParents(stagingArea *model
|
|||||||
log.Debugf("Checking whether parent %s breaks the bounded merge set", parent)
|
log.Debugf("Checking whether parent %s breaks the bounded merge set", parent)
|
||||||
isBadRedInPast := false
|
isBadRedInPast := false
|
||||||
for _, badRedBlock := range badReds {
|
for _, badRedBlock := range badReds {
|
||||||
isBadRedInPast, err = csm.dagTopologyManager.IsAncestorOf(stagingArea, parent, badRedBlock)
|
isBadRedInPast, err = csm.dagTopologyManager.IsAncestorOf(stagingArea, badRedBlock, parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if isBadRedInPast {
|
if isBadRedInPast {
|
||||||
log.Debugf("Parent %s is an ancestor of bad red %s", parent, badRedBlock)
|
log.Debugf("Parent %s is a descendant of bad red %s", parent, badRedBlock)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -995,7 +995,13 @@ func (pm *pruningManager) ExpectedHeaderPruningPoint(stagingArea *model.StagingA
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasPruningPointInItsSelectedChain && pm.finalityScore(ghostdagData.BlueScore()) > pm.finalityScore(selectedParentPruningPointHeader.BlueScore()+pm.pruningDepth) {
|
// Note: the pruning point from the POV of the current block is the first block in its chain that is in depth of pm.pruningDepth and
|
||||||
|
// its finality score is greater than the previous pruning point. This is why the diff between finalityScore(selectedParent.blueScore + 1) * finalityInterval
|
||||||
|
// and the current block blue score is less than pm.pruningDepth we can know for sure that this block didn't trigger a pruning point change.
|
||||||
|
minRequiredBlueScoreForNextPruningPoint := (pm.finalityScore(selectedParentPruningPointHeader.BlueScore()) + 1) * pm.finalityInterval
|
||||||
|
|
||||||
|
if hasPruningPointInItsSelectedChain &&
|
||||||
|
minRequiredBlueScoreForNextPruningPoint+pm.pruningDepth <= ghostdagData.BlueScore() {
|
||||||
var suggestedLowHash *externalapi.DomainHash
|
var suggestedLowHash *externalapi.DomainHash
|
||||||
hasReachabilityData, err := pm.reachabilityDataStore.HasReachabilityData(pm.databaseContext, stagingArea, selectedParentHeader.PruningPoint())
|
hasReachabilityData, err := pm.reachabilityDataStore.HasReachabilityData(pm.databaseContext, stagingArea, selectedParentHeader.PruningPoint())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// DefaultMaxMessages is the default capacity for a route with a capacity defined
|
// DefaultMaxMessages is the default capacity for a route with a capacity defined
|
||||||
DefaultMaxMessages = 100
|
DefaultMaxMessages = 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
Reference in New Issue
Block a user