Browse Source

proposer selection fix

pull/102/head
Jae Kwon 9 years ago
parent
commit
bc71e38bad
2 changed files with 31 additions and 4 deletions
  1. +1
    -1
      state/validator_set.go
  2. +30
    -3
      state/validator_set_test.go

+ 1
- 1
state/validator_set.go View File

@ -298,5 +298,5 @@ type accumComparable int64
// We want to find the validator with the greatest accum. // We want to find the validator with the greatest accum.
func (ac accumComparable) Less(o interface{}) bool { func (ac accumComparable) Less(o interface{}) bool {
return int64(ac) < int64(o.(accumComparable))
return int64(ac) > int64(o.(accumComparable))
} }

+ 30
- 3
state/validator_set_test.go View File

@ -5,7 +5,7 @@ import (
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
"bytes" "bytes"
"fmt"
"strings"
"testing" "testing"
) )
@ -43,12 +43,39 @@ func TestCopy(t *testing.T) {
} }
func TestProposerSelection(t *testing.T) { func TestProposerSelection(t *testing.T) {
vset := randValidatorSet(10)
vset := NewValidatorSet([]*Validator{
&Validator{
Address: []byte("foo"),
PubKey: account.PubKeyEd25519(RandBytes(64)),
BondHeight: RandInt(),
VotingPower: 1000,
Accum: 0,
},
&Validator{
Address: []byte("bar"),
PubKey: account.PubKeyEd25519(RandBytes(64)),
BondHeight: RandInt(),
VotingPower: 300,
Accum: 0,
},
&Validator{
Address: []byte("baz"),
PubKey: account.PubKeyEd25519(RandBytes(64)),
BondHeight: RandInt(),
VotingPower: 330,
Accum: 0,
},
})
proposers := []string{}
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
val := vset.Proposer() val := vset.Proposer()
fmt.Printf("Proposer: %v\n", val)
proposers = append(proposers, string(val.Address))
vset.IncrementAccum(1) vset.IncrementAccum(1)
} }
expected := `bar foo baz foo bar foo foo baz foo bar foo foo baz foo foo bar foo baz foo foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo foo baz bar foo foo foo baz foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo`
if expected != strings.Join(proposers, " ") {
t.Errorf("Expected sequence of proposers was\n%v\nbut got \n%v", expected, strings.Join(proposers, " "))
}
} }
func BenchmarkValidatorSetCopy(b *testing.B) { func BenchmarkValidatorSetCopy(b *testing.B) {


Loading…
Cancel
Save