Skip to content

Commit

Permalink
Merge pull request dominant-strategies#332 from spruce-solutions/hc-hlcr
Browse files Browse the repository at this point in the history
headerchain.go: fixed HLCR
  • Loading branch information
0xalank authored Jul 1, 2022
2 parents 766e718 + 9870b10 commit 89b3a5c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,15 +673,23 @@ func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, d

// HLCR does hierarchical comparison of two difficulty tuples and returns true if second tuple is greater than the first
func (hc *HeaderChain) HLCR(localDifficulties []*big.Int, externDifficulties []*big.Int) bool {
log.Info("HLCR", "localDiff", localDifficulties, "externDiff", externDifficulties)
if localDifficulties[0].Cmp(externDifficulties[0]) < 0 {
return true
} else if localDifficulties[1].Cmp(externDifficulties[1]) < 0 {
} else if localDifficulties[0].Cmp(externDifficulties[0]) > 0 {
return false
}
if localDifficulties[1].Cmp(externDifficulties[1]) < 0 {
return true
} else if localDifficulties[2].Cmp(externDifficulties[2]) < 0 {
} else if localDifficulties[1].Cmp(externDifficulties[1]) > 0 {
return false
}
if localDifficulties[2].Cmp(externDifficulties[2]) < 0 {
return true
} else {
} else if localDifficulties[2].Cmp(externDifficulties[2]) > 0 {
return false
}
return false
}

// CalcTd calculates the TD of the given header using PCRC and CalcHLCRNetDifficulty.
Expand Down

0 comments on commit 89b3a5c

Please sign in to comment.