mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-07-05 12:22:30 +00:00
Don't change the new reindex root if the blue score of the selected tip is lower than the current reindex root (#1501)
This commit is contained in:
parent
5b5a7e60af
commit
1a3b16aaa3
@ -337,6 +337,8 @@ func (rt *reachabilityManager) updateReindexRoot(selectedTip *externalapi.Domain
|
|||||||
|
|
||||||
rc := newReindexContext(rt)
|
rc := newReindexContext(rt)
|
||||||
|
|
||||||
|
if !newReindexRoot.Equal(reindexRootAncestor) {
|
||||||
|
log.Debugf("Concentrating the intervals towards the new reindex root")
|
||||||
// Iterate from reindexRootAncestor towards newReindexRoot
|
// Iterate from reindexRootAncestor towards newReindexRoot
|
||||||
for {
|
for {
|
||||||
chosenChild, err := rt.FindNextAncestor(selectedTip, reindexRootAncestor)
|
chosenChild, err := rt.FindNextAncestor(selectedTip, reindexRootAncestor)
|
||||||
@ -346,7 +348,7 @@ func (rt *reachabilityManager) updateReindexRoot(selectedTip *externalapi.Domain
|
|||||||
|
|
||||||
isFinalReindexRoot := chosenChild.Equal(newReindexRoot)
|
isFinalReindexRoot := chosenChild.Equal(newReindexRoot)
|
||||||
|
|
||||||
// Concentrate interval from current ancestor to it's chosen child
|
// Concentrate interval from current ancestor to its chosen child
|
||||||
err = rc.concentrateInterval(reindexRootAncestor, chosenChild, isFinalReindexRoot)
|
err = rc.concentrateInterval(reindexRootAncestor, chosenChild, isFinalReindexRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -358,9 +360,13 @@ func (rt *reachabilityManager) updateReindexRoot(selectedTip *externalapi.Domain
|
|||||||
|
|
||||||
reindexRootAncestor = chosenChild
|
reindexRootAncestor = chosenChild
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Debugf("newReindexRoot is the same as reindexRootAncestor. Skipping concentration...")
|
||||||
|
}
|
||||||
|
|
||||||
// Update reindex root data store
|
// Update reindex root data store
|
||||||
rt.stageReindexRoot(newReindexRoot)
|
rt.stageReindexRoot(newReindexRoot)
|
||||||
|
log.Debugf("Updated the reindex root to %s", newReindexRoot)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,8 +399,12 @@ func (rt *reachabilityManager) findNextReindexRoot(currentReindexRoot, selectedT
|
|||||||
// We have reindex root out of selected tip chain, however we switch chains only after a sufficient
|
// We have reindex root out of selected tip chain, however we switch chains only after a sufficient
|
||||||
// threshold of reindexSlack score in order to address possible alternating reorg attacks.
|
// threshold of reindexSlack score in order to address possible alternating reorg attacks.
|
||||||
// The reindexSlack constant is used as an heuristic for a large enough constant on the one hand, but
|
// The reindexSlack constant is used as an heuristic for a large enough constant on the one hand, but
|
||||||
// one which will not harm performance on the other hand - given the available slack at the chain split point
|
// one which will not harm performance on the other hand - given the available slack at the chain split point.
|
||||||
if selectedTipGHOSTDAGData.BlueScore()-currentRootGHOSTDAGData.BlueScore() < rt.reindexSlack {
|
//
|
||||||
|
// Note: In some cases the blue score selected tip can be lower than the current reindex root blue score.
|
||||||
|
// If that's the case we keep the reindex root unchanged.
|
||||||
|
if selectedTipGHOSTDAGData.BlueScore() < currentRootGHOSTDAGData.BlueScore() ||
|
||||||
|
selectedTipGHOSTDAGData.BlueScore()-currentRootGHOSTDAGData.BlueScore() < rt.reindexSlack {
|
||||||
// Return current - this indicates no change
|
// Return current - this indicates no change
|
||||||
return currentReindexRoot, currentReindexRoot, nil
|
return currentReindexRoot, currentReindexRoot, nil
|
||||||
}
|
}
|
||||||
@ -422,6 +432,11 @@ func (rt *reachabilityManager) findNextReindexRoot(currentReindexRoot, selectedT
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if selectedTipGHOSTDAGData.BlueScore() < chosenChildGHOSTDAGData.BlueScore() {
|
||||||
|
return nil, nil, errors.Errorf("chosen child %s has blue score greater "+
|
||||||
|
"than %s although it's in its selected parent chain", chosenChild, selectedTip)
|
||||||
|
}
|
||||||
|
|
||||||
if selectedTipGHOSTDAGData.BlueScore()-chosenChildGHOSTDAGData.BlueScore() < rt.reindexWindow {
|
if selectedTipGHOSTDAGData.BlueScore()-chosenChildGHOSTDAGData.BlueScore() < rt.reindexWindow {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user