mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 22:26:47 +00:00
a temp patch for fixing IBD issues for all side-chains
This commit is contained in:
parent
685c049a12
commit
c903a65def
@ -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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,25 +87,25 @@ 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)
|
||||||
|
|
||||||
if highestSharedBlockFound {
|
if highestSharedBlockFound {
|
||||||
checkpoint, err := externalapi.NewDomainHashFromString("f4a415f28990806a899a208b77930fa5a58f3a94876c3cbe814e60a7ed22824f")
|
virtualSelectedParent, err := flow.Domain().Consensus().GetVirtualSelectedParent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
virtualSelectedParentHeader, err := flow.Domain().Consensus().GetBlockHeader(virtualSelectedParent)
|
||||||
info, err := flow.Domain().Consensus().GetBlockInfo(checkpoint)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if virtualSelectedParentHeader.DAAScore() > block.Header.DAAScore()+2641*3 {
|
||||||
if info.Exists {
|
virtualDifficulty := difficulty.CalcWork(virtualSelectedParentHeader.Bits())
|
||||||
isInSelectedParentChainOf, err := flow.Domain().Consensus().IsInSelectedParentChainOf(checkpoint, highestSharedBlockHash)
|
var virtualSub, difficultyMul big.Int
|
||||||
if err != nil {
|
if difficultyMul.Mul(virtualDifficulty, big.NewInt(180)).
|
||||||
return err
|
Cmp(virtualSub.Sub(virtualSelectedParentHeader.BlueWork(), block.Header.BlueWork())) < 0 {
|
||||||
}
|
log.Criticalf("Stopped IBD because it is coming from a deep (%d DAA score depth) "+
|
||||||
|
"side-chain which split at %s and has lower blue work (%d, %d)",
|
||||||
if !isInSelectedParentChainOf {
|
virtualSelectedParentHeader.DAAScore()-block.Header.DAAScore(),
|
||||||
log.Criticalf("Stopped IBD because the checkpoint %s is not in the selected chain of %s", checkpoint, highestSharedBlockHash)
|
highestSharedBlockHash, virtualSelectedParentHeader.BlueWork(), block.Header.BlueWork())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user