From 291806c05652d89c761a4fc53a53b60f4d5412e8 Mon Sep 17 00:00:00 2001
From: gitglorythegreat <t4juu3@proton.me>
Date: Thu, 26 Dec 2024 13:09:45 +0800
Subject: [PATCH 1/2] all: use cmp.Compare

---
 cmd/devp2p/dns_route53.go            | 9 ++-------
 cmd/devp2p/nodeset.go                | 9 ++-------
 core/state/snapshot/iterator_fast.go | 9 ++-------
 p2p/protocol.go                      | 9 ++-------
 triedb/pathdb/iterator_fast.go       | 9 ++-------
 5 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/cmd/devp2p/dns_route53.go b/cmd/devp2p/dns_route53.go
index a6125b8263a8..86907688f3b5 100644
--- a/cmd/devp2p/dns_route53.go
+++ b/cmd/devp2p/dns_route53.go
@@ -17,6 +17,7 @@
 package main
 
 import (
+	"cmp"
 	"context"
 	"errors"
 	"fmt"
@@ -292,13 +293,7 @@ func sortChanges(changes []types.Change) {
 		if a.Action == b.Action {
 			return strings.Compare(*a.ResourceRecordSet.Name, *b.ResourceRecordSet.Name)
 		}
-		if score[string(a.Action)] < score[string(b.Action)] {
-			return -1
-		}
-		if score[string(a.Action)] > score[string(b.Action)] {
-			return 1
-		}
-		return 0
+		return cmp.Compare(score[string(a.Action)], score[string(b.Action)])
 	})
 }
 
diff --git a/cmd/devp2p/nodeset.go b/cmd/devp2p/nodeset.go
index 4fa862de14cb..0eb31be0038f 100644
--- a/cmd/devp2p/nodeset.go
+++ b/cmd/devp2p/nodeset.go
@@ -17,6 +17,7 @@
 package main
 
 import (
+	"cmp"
 	"bytes"
 	"encoding/json"
 	"fmt"
@@ -104,13 +105,7 @@ func (ns nodeSet) topN(n int) nodeSet {
 		byscore = append(byscore, v)
 	}
 	slices.SortFunc(byscore, func(a, b nodeJSON) int {
-		if a.Score > b.Score {
-			return -1
-		}
-		if a.Score < b.Score {
-			return 1
-		}
-		return 0
+		return cmp.Compare(b.Score, a.Score)
 	})
 	result := make(nodeSet, n)
 	for _, v := range byscore[:n] {
diff --git a/core/state/snapshot/iterator_fast.go b/core/state/snapshot/iterator_fast.go
index 7f7ba876ffbd..3ef2cece6126 100644
--- a/core/state/snapshot/iterator_fast.go
+++ b/core/state/snapshot/iterator_fast.go
@@ -17,6 +17,7 @@
 package snapshot
 
 import (
+	"cmp"
 	"bytes"
 	"fmt"
 	"slices"
@@ -45,13 +46,7 @@ func (it *weightedIterator) Cmp(other *weightedIterator) int {
 		return 1
 	}
 	// Same account/storage-slot in multiple layers, split by priority
-	if it.priority < other.priority {
-		return -1
-	}
-	if it.priority > other.priority {
-		return 1
-	}
-	return 0
+	return cmp.Compare(it.priority, other.priority)
 }
 
 // fastIterator is a more optimized multi-layer iterator which maintains a
diff --git a/p2p/protocol.go b/p2p/protocol.go
index 9bb6785a2250..de3127e23365 100644
--- a/p2p/protocol.go
+++ b/p2p/protocol.go
@@ -17,6 +17,7 @@
 package p2p
 
 import (
+	"cmp"
 	"fmt"
 	"strings"
 
@@ -81,13 +82,7 @@ func (cap Cap) String() string {
 // Cmp defines the canonical sorting order of capabilities.
 func (cap Cap) Cmp(other Cap) int {
 	if cap.Name == other.Name {
-		if cap.Version < other.Version {
-			return -1
-		}
-		if cap.Version > other.Version {
-			return 1
-		}
-		return 0
+		return cmp.Compare(cap.Version, other.Version)
 	}
 	return strings.Compare(cap.Name, other.Name)
 }
diff --git a/triedb/pathdb/iterator_fast.go b/triedb/pathdb/iterator_fast.go
index 217b211fccb1..24cd1635eb6f 100644
--- a/triedb/pathdb/iterator_fast.go
+++ b/triedb/pathdb/iterator_fast.go
@@ -17,6 +17,7 @@
 package pathdb
 
 import (
+	"cmp"
 	"bytes"
 	"fmt"
 	"slices"
@@ -45,13 +46,7 @@ func (it *weightedIterator) Cmp(other *weightedIterator) int {
 		return 1
 	}
 	// Same account/storage-slot in multiple layers, split by priority
-	if it.priority < other.priority {
-		return -1
-	}
-	if it.priority > other.priority {
-		return 1
-	}
-	return 0
+	return cmp.Compare(it.priority, other.priority)
 }
 
 // fastIterator is a more optimized multi-layer iterator which maintains a

From e740417f52dc0b266eb406424283ff7471878512 Mon Sep 17 00:00:00 2001
From: gitglorythegreat <t4juu3@proton.me>
Date: Thu, 26 Dec 2024 14:23:13 +0800
Subject: [PATCH 2/2] fix import order

---
 cmd/devp2p/nodeset.go                | 2 +-
 core/state/snapshot/iterator_fast.go | 2 +-
 triedb/pathdb/iterator_fast.go       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmd/devp2p/nodeset.go b/cmd/devp2p/nodeset.go
index 0eb31be0038f..4a6df6cdfe8b 100644
--- a/cmd/devp2p/nodeset.go
+++ b/cmd/devp2p/nodeset.go
@@ -17,8 +17,8 @@
 package main
 
 import (
-	"cmp"
 	"bytes"
+	"cmp"
 	"encoding/json"
 	"fmt"
 	"os"
diff --git a/core/state/snapshot/iterator_fast.go b/core/state/snapshot/iterator_fast.go
index 3ef2cece6126..61fc43417822 100644
--- a/core/state/snapshot/iterator_fast.go
+++ b/core/state/snapshot/iterator_fast.go
@@ -17,8 +17,8 @@
 package snapshot
 
 import (
-	"cmp"
 	"bytes"
+	"cmp"
 	"fmt"
 	"slices"
 	"sort"
diff --git a/triedb/pathdb/iterator_fast.go b/triedb/pathdb/iterator_fast.go
index 24cd1635eb6f..966e37a7cb4e 100644
--- a/triedb/pathdb/iterator_fast.go
+++ b/triedb/pathdb/iterator_fast.go
@@ -17,8 +17,8 @@
 package pathdb
 
 import (
-	"cmp"
 	"bytes"
+	"cmp"
 	"fmt"
 	"slices"
 	"sort"