From f79a037fd7171a91447f48ecd6d83c561b9ea785 Mon Sep 17 00:00:00 2001 From: yingshanghuangqiao Date: Thu, 6 Nov 2025 16:12:39 +0800 Subject: [PATCH] refactor: replace sort.Slice with slices.Sort for natural ordering Signed-off-by: yingshanghuangqiao --- pkg/consensus/consensus.go | 6 ++---- pkg/wal/util.go | 7 ++----- test/network.go | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 56191e5d..9f25a2db 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -8,7 +8,7 @@ package consensus import ( "errors" "fmt" - "sort" + "slices" "strings" "sync" "sync/atomic" @@ -378,9 +378,7 @@ func (c *Consensus) setNodes(nodes []uint64) { func sortNodes(nodes []uint64) []uint64 { sorted := make([]uint64, len(nodes)) copy(sorted, nodes) - sort.Slice(sorted, func(i, j int) bool { - return sorted[i] < sorted[j] - }) + slices.Sort(sorted) return sorted } diff --git a/pkg/wal/util.go b/pkg/wal/util.go index b7b66dfc..eaadd1b5 100644 --- a/pkg/wal/util.go +++ b/pkg/wal/util.go @@ -11,6 +11,7 @@ import ( "io" "os" "path/filepath" + "slices" "sort" "strings" @@ -132,11 +133,7 @@ func checkWalFiles(logger api.Logger, dirName string, walNames []string) ([]uint } } - sort.Slice(indexes, - func(i, j int) bool { - return indexes[i] < indexes[j] - }, - ) + slices.Sort(indexes) return indexes, nil } diff --git a/test/network.go b/test/network.go index 48cc76ee..42ff37f0 100644 --- a/test/network.go +++ b/test/network.go @@ -8,7 +8,7 @@ package test import ( "fmt" "math/rand" - "sort" + "slices" "sync" "github.com/hyperledger-labs/SmartBFT/smartbftprotos" @@ -213,7 +213,7 @@ func (node *Node) SendTransaction(targetID uint64, request []byte) { // Nodes returns the ids of all nodes in the network func (node *Node) Nodes() []uint64 { res := node.n.getAll() - sort.Slice(res, func(i, j int) bool { return res[i] < res[j] }) + slices.Sort(res) return res }