mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
[NOD-1532] Invert condition in isViolatingFinality
This commit is contained in:
parent
66f5a5bd7d
commit
dbd15aecf5
@ -25,30 +25,36 @@ func (csm *consensusStateManager) checkFinalityViolation(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (csm *consensusStateManager) virtualFinalityPoint(virtualGHOSTDAGData *model.BlockGHOSTDAGData) (
|
||||
func (csm *consensusStateManager) virtualFinalityPoint() (
|
||||
*externalapi.DomainHash, error) {
|
||||
|
||||
blueScore := virtualGHOSTDAGData.BlueScore - csm.finalityDepth
|
||||
virtualGHOSTDAGData, err := csm.ghostdagDataStore.Get(csm.databaseContext, model.VirtualBlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
finalityPointBlueScore := virtualGHOSTDAGData.BlueScore - csm.finalityDepth
|
||||
if virtualGHOSTDAGData.BlueScore < csm.finalityDepth {
|
||||
blueScore = 0
|
||||
// if there's no `csm.finalityDepth` blocks in the DAG
|
||||
// practically - returns the genesis
|
||||
finalityPointBlueScore = 0
|
||||
}
|
||||
|
||||
return csm.dagTraversalManager.HighestChainBlockBelowBlueScore(
|
||||
model.VirtualBlockHash, blueScore)
|
||||
model.VirtualBlockHash, finalityPointBlueScore)
|
||||
}
|
||||
|
||||
func (csm *consensusStateManager) isViolatingFinality(
|
||||
blockHash *externalapi.DomainHash) (bool, error) {
|
||||
|
||||
virtualGHOSTDAGData, err := csm.ghostdagDataStore.Get(csm.databaseContext, model.VirtualBlockHash)
|
||||
virtualFinalityPoint, err := csm.virtualFinalityPoint()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
virtualFinalityPoint, err := csm.virtualFinalityPoint(virtualGHOSTDAGData)
|
||||
isInSelectedParentChain, err := csm.dagTopologyManager.IsInSelectedParentChainOf(virtualFinalityPoint, blockHash)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return csm.dagTopologyManager.IsInSelectedParentChainOf(virtualFinalityPoint, blockHash)
|
||||
return !isInSelectedParentChain, nil
|
||||
}
|
||||
|
@ -160,17 +160,17 @@ func (csm *consensusStateManager) boundedMergeBreakingParents(parents []*externa
|
||||
return nil, err
|
||||
}
|
||||
|
||||
virtualGHOSTDAGData, err := csm.ghostdagDataStore.Get(csm.databaseContext, model.VirtualBlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
virtualFinalityPoint, err := csm.virtualFinalityPoint(virtualGHOSTDAGData)
|
||||
virtualFinalityPoint, err := csm.virtualFinalityPoint()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
badReds := []*externalapi.DomainHash{}
|
||||
|
||||
virtualGHOSTDAGData, err := csm.ghostdagDataStore.Get(csm.databaseContext, model.VirtualBlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, redBlock := range virtualGHOSTDAGData.MergeSetReds {
|
||||
isFinalityPointInPast, err := csm.dagTopologyManager.IsAncestorOf(virtualFinalityPoint, redBlock)
|
||||
if err != nil {
|
||||
|
@ -2,6 +2,7 @@ package dagtraversalmanager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model"
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
)
|
||||
@ -65,27 +66,23 @@ func (dtm *dagTraversalManager) SelectedParentIterator(highHash *externalapi.Dom
|
||||
|
||||
// HighestChainBlockBelowBlueScore returns the hash of the
|
||||
// highest block with a blue score lower than the given
|
||||
// blueScore in the block with the given highHash's selected
|
||||
// parent chain
|
||||
func (dtm *dagTraversalManager) HighestChainBlockBelowBlueScore(highHash *externalapi.DomainHash, blueScore uint64) (*externalapi.DomainHash, error) {
|
||||
// blueScore in the selected-parent-chain of the block
|
||||
// with the given highHash's selected parent chain
|
||||
func (dtm *dagTraversalManager) HighestChainBlockBelowBlueScore(highHash *externalapi.DomainHash, requiredBlueScore uint64) (*externalapi.DomainHash, error) {
|
||||
currentBlockHash := highHash
|
||||
chainBlock, err := dtm.ghostdagDataStore.Get(dtm.databaseContext, highHash)
|
||||
highBlockGHOSTDAGData, err := dtm.ghostdagDataStore.Get(dtm.databaseContext, highHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if chainBlock.BlueScore < blueScore { // will practically return genesis.
|
||||
blueScore = chainBlock.BlueScore
|
||||
}
|
||||
|
||||
requiredBlueScore := chainBlock.BlueScore - blueScore
|
||||
|
||||
currentBlockGHOSTDAGData := highBlockGHOSTDAGData
|
||||
// If we used `BlockIterator` we'd need to do more calls to `ghostdagDataStore` so we can get the blueScore
|
||||
for chainBlock.BlueScore >= requiredBlueScore {
|
||||
if chainBlock.SelectedParent == nil { // genesis
|
||||
for currentBlockGHOSTDAGData.BlueScore >= requiredBlueScore {
|
||||
if currentBlockGHOSTDAGData.SelectedParent == nil { // genesis
|
||||
return currentBlockHash, nil
|
||||
}
|
||||
currentBlockHash = chainBlock.SelectedParent
|
||||
chainBlock, err = dtm.ghostdagDataStore.Get(dtm.databaseContext, currentBlockHash)
|
||||
currentBlockHash = currentBlockGHOSTDAGData.SelectedParent
|
||||
currentBlockGHOSTDAGData, err = dtm.ghostdagDataStore.Get(dtm.databaseContext, currentBlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user