mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
[DEV-189] invert arguments order of daghash.Less (#83)
* [DEV-189] invert arguments order or daghash.Less * [DEV-189] invert arguments order of daghash.Less in blockset.highest * [DEV-189] change to equivalent condition in Hash.Less to make it prettier
This commit is contained in:
parent
3c88184b38
commit
0643b0d920
@ -38,7 +38,7 @@ func (bs blockSet) maxHeight() int32 {
|
||||
func (bs blockSet) highest() *blockNode {
|
||||
var highest *blockNode
|
||||
for _, node := range bs {
|
||||
if highest.height < node.height || daghash.Less(&highest.hash, &node.hash) {
|
||||
if highest.height < node.height || daghash.Less(&node.hash, &highest.hash) {
|
||||
highest = node
|
||||
}
|
||||
}
|
||||
@ -130,7 +130,7 @@ func (bs blockSet) hashes() []daghash.Hash {
|
||||
hashes = append(hashes, hash)
|
||||
}
|
||||
sort.Slice(hashes, func(i, j int) bool {
|
||||
return daghash.Less(&hashes[i], &hashes[j])
|
||||
return daghash.Less(&hashes[j], &hashes[i])
|
||||
})
|
||||
return hashes
|
||||
}
|
||||
@ -160,7 +160,7 @@ func (bs blockSet) bluest() *blockNode {
|
||||
for _, node := range bs {
|
||||
if bluestNode == nil ||
|
||||
node.blueScore > maxScore ||
|
||||
(node.blueScore == maxScore && daghash.Less(&bluestNode.hash, &node.hash)) {
|
||||
(node.blueScore == maxScore && daghash.Less(&node.hash, &bluestNode.hash)) {
|
||||
bluestNode = node
|
||||
maxScore = node.blueScore
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func phantom(block *blockNode, k uint32) (blues []*blockNode, selectedParent *bl
|
||||
blues := traverseCandidates(block, candidates, parent)
|
||||
score := uint64(len(blues)) + parent.blueScore
|
||||
|
||||
if score > bestScore || (score == bestScore && (bestHash == nil || daghash.Less(bestHash, &parent.hash))) {
|
||||
if score > bestScore || (score == bestScore && (bestHash == nil || daghash.Less(&parent.hash, bestHash))) {
|
||||
bestScore = score
|
||||
bestBlues = blues
|
||||
bestParent = parent
|
||||
|
@ -435,7 +435,7 @@ func checkBlockParentsOrder(header *wire.BlockHeader) error {
|
||||
sortedHashes = append(sortedHashes, hash)
|
||||
}
|
||||
sort.Slice(sortedHashes, func(i, j int) bool {
|
||||
return daghash.Less(&sortedHashes[i], &sortedHashes[j])
|
||||
return daghash.Less(&sortedHashes[j], &sortedHashes[i])
|
||||
})
|
||||
if !daghash.AreEqual(header.PrevBlocks, sortedHashes) {
|
||||
return ruleError(ErrWrongParentsOrder, "block parents are not ordered by hash")
|
||||
|
@ -178,9 +178,9 @@ func (hash *Hash) Cmp(target *Hash) int {
|
||||
return HashToBig(hash).Cmp(HashToBig(target))
|
||||
}
|
||||
|
||||
//Less returns true iff hash b is less than hash a
|
||||
//Less returns true iff hash a is less than hash b
|
||||
func Less(a *Hash, b *Hash) bool {
|
||||
return a.Cmp(b) > 0
|
||||
return a.Cmp(b) < 0
|
||||
}
|
||||
|
||||
//JoinHashesStrings joins all the stringified hashes separated by a separator
|
||||
|
Loading…
x
Reference in New Issue
Block a user