aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-07-24 18:46:37 +0800
committerGitHub <noreply@github.com>2018-07-24 18:46:37 +0800
commit62467e440582db5cc806584c196aaa53d1154425 (patch)
tree723d428de73b67650d84a2cb1e5e1d5cd2061455
parentd0082bb7ec04b4fe3fc9e269fe2673c9cbd094e2 (diff)
parent49f63deb24beed8adc03a6fdf5d68ab793cc275f (diff)
downloadgo-tangerine-62467e440582db5cc806584c196aaa53d1154425.tar
go-tangerine-62467e440582db5cc806584c196aaa53d1154425.tar.gz
go-tangerine-62467e440582db5cc806584c196aaa53d1154425.tar.bz2
go-tangerine-62467e440582db5cc806584c196aaa53d1154425.tar.lz
go-tangerine-62467e440582db5cc806584c196aaa53d1154425.tar.xz
go-tangerine-62467e440582db5cc806584c196aaa53d1154425.tar.zst
go-tangerine-62467e440582db5cc806584c196aaa53d1154425.zip
Merge pull request #17206 from hadv/master
consensus/clique: replace bubble sort by golang stable sort
-rw-r--r--consensus/clique/snapshot.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/consensus/clique/snapshot.go b/consensus/clique/snapshot.go
index 9ebdb8df1..2333d6924 100644
--- a/consensus/clique/snapshot.go
+++ b/consensus/clique/snapshot.go
@@ -19,6 +19,7 @@ package clique
import (
"bytes"
"encoding/json"
+ "sort"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
@@ -56,6 +57,13 @@ type Snapshot struct {
Tally map[common.Address]Tally `json:"tally"` // Current vote tally to avoid recalculating
}
+// signers implements the sort interface to allow sorting a list of addresses
+type signers []common.Address
+
+func (s signers) Len() int { return len(s) }
+func (s signers) Less(i, j int) bool { return bytes.Compare(s[i][:], s[j][:]) < 0 }
+func (s signers) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
+
// newSnapshot creates a new snapshot with the specified startup parameters. This
// method does not initialize the set of recent signers, so only ever use if for
// the genesis block.
@@ -286,18 +294,12 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
// signers retrieves the list of authorized signers in ascending order.
func (s *Snapshot) signers() []common.Address {
- signers := make([]common.Address, 0, len(s.Signers))
- for signer := range s.Signers {
- signers = append(signers, signer)
- }
- for i := 0; i < len(signers); i++ {
- for j := i + 1; j < len(signers); j++ {
- if bytes.Compare(signers[i][:], signers[j][:]) > 0 {
- signers[i], signers[j] = signers[j], signers[i]
- }
- }
+ sigs := make([]common.Address, 0, len(s.Signers))
+ for sig := range s.Signers {
+ sigs = append(sigs, sig)
}
- return signers
+ sort.Sort(signers(sigs))
+ return sigs
}
// inturn returns if a signer at a given block height is in-turn or not.