From aba9ce38a8834e0f26bf3f3196703323a001c81e Mon Sep 17 00:00:00 2001 From: Woosang Son Date: Sat, 16 May 2020 15:49:20 +0900 Subject: [PATCH] fix: apply comments --- libs/rand/sampling.go | 1 - libs/rand/sampling_test.go | 5 ----- types/voter_set.go | 14 +++----------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/libs/rand/sampling.go b/libs/rand/sampling.go index 681452cd4..8aaf411c7 100644 --- a/libs/rand/sampling.go +++ b/libs/rand/sampling.go @@ -10,7 +10,6 @@ type Candidate interface { Priority() uint64 LessThan(other Candidate) bool IncreaseWin() - MultiplyWin(times float64) uint64 } const uint64Mask = uint64(0x7FFFFFFFFFFFFFFF) diff --git a/libs/rand/sampling_test.go b/libs/rand/sampling_test.go index c49d3d464..3ed78e0dc 100644 --- a/libs/rand/sampling_test.go +++ b/libs/rand/sampling_test.go @@ -29,11 +29,6 @@ func (e *Element) IncreaseWin() { e.Win++ } -func (e *Element) MultiplyWin(times float64) uint64 { - e.Win = uint64(float64(e.Win) * times) - return e.Win -} - func TestRandomSamplingWithPriority(t *testing.T) { candidates := newCandidates(100, func(i int) uint64 { return uint64(i) }) diff --git a/types/voter_set.go b/types/voter_set.go index d3001e11c..9898321be 100644 --- a/types/voter_set.go +++ b/types/voter_set.go @@ -27,6 +27,7 @@ type VoterSet struct { } func NewVoterSet(valz []*Validator) *VoterSet { + sort.Sort(ValidatorsByAddress(valz)) vals := &VoterSet{Voters: copyValidatorListShallow(valz), totalVotingPower: 0} vals.updateTotalVotingPower() return vals @@ -415,16 +416,12 @@ func SelectVoter(validators *ValidatorSet, proofHash []byte) *VoterSet { index++ } } - result := &VoterSet{Voters: vals, totalVotingPower: 0} - result.updateTotalVotingPower() - return result + return NewVoterSet(vals) } // This should be used in only test func ToVoterAll(validators *ValidatorSet) *VoterSet { - result := &VoterSet{Voters: copyValidatorListShallow(validators.Validators), totalVotingPower: 0} - result.updateTotalVotingPower() - return result + return NewVoterSet(validators.Validators) } // candidate save simple validator data for selecting proposer @@ -454,11 +451,6 @@ func (c *candidate) IncreaseWin() { c.win++ } -func (c *candidate) MultiplyWin(times float64) uint64 { - c.win = uint64(float64(c.win) * times) - return c.win -} - func hashToSeed(hash []byte) uint64 { for len(hash) < 8 { hash = append(hash, byte(0))