|
@ -1,23 +1,23 @@ |
|
|
package types |
|
|
package types |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
. "github.com/tendermint/go-common" |
|
|
|
|
|
"github.com/tendermint/go-crypto" |
|
|
|
|
|
|
|
|
|
|
|
"bytes" |
|
|
"bytes" |
|
|
"strings" |
|
|
"strings" |
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
cmn "github.com/tendermint/go-common" |
|
|
|
|
|
"github.com/tendermint/go-crypto" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func randPubKey() crypto.PubKeyEd25519 { |
|
|
func randPubKey() crypto.PubKeyEd25519 { |
|
|
var pubKey [32]byte |
|
|
var pubKey [32]byte |
|
|
copy(pubKey[:], RandBytes(32)) |
|
|
|
|
|
|
|
|
copy(pubKey[:], cmn.RandBytes(32)) |
|
|
return crypto.PubKeyEd25519(pubKey) |
|
|
return crypto.PubKeyEd25519(pubKey) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func randValidator_() *Validator { |
|
|
func randValidator_() *Validator { |
|
|
val := NewValidator(randPubKey(), RandInt64()) |
|
|
|
|
|
val.Accum = RandInt64() |
|
|
|
|
|
|
|
|
val := NewValidator(randPubKey(), cmn.RandInt64()) |
|
|
|
|
|
val.Accum = cmn.RandInt64() |
|
|
return val |
|
|
return val |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -138,6 +138,43 @@ func TestProposerSelection2(t *testing.T) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestProposerSelection3(t *testing.T) { |
|
|
|
|
|
vset := NewValidatorSet([]*Validator{ |
|
|
|
|
|
newValidator([]byte("a"), 1), |
|
|
|
|
|
newValidator([]byte("b"), 1), |
|
|
|
|
|
newValidator([]byte("c"), 1), |
|
|
|
|
|
newValidator([]byte("d"), 1), |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
proposerOrder := make([]*Validator, 4) |
|
|
|
|
|
for i := 0; i < 4; i++ { |
|
|
|
|
|
proposerOrder[i] = vset.Proposer() |
|
|
|
|
|
vset.IncrementAccum(1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// i for the loop
|
|
|
|
|
|
// j for the times
|
|
|
|
|
|
// we should go in order for ever, despite occasional IncrementAccums with times > 1
|
|
|
|
|
|
var i, j int |
|
|
|
|
|
for ; i < 1000; i++ { |
|
|
|
|
|
got := vset.Proposer().Address |
|
|
|
|
|
expected := proposerOrder[j%4].Address |
|
|
|
|
|
if !bytes.Equal(got, expected) { |
|
|
|
|
|
t.Fatalf(cmn.Fmt("vset.Proposer (%X) does not match expected proposer (%X) for (%d, %d)", got, expected, i, j)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// times is usually 1
|
|
|
|
|
|
times := 1 |
|
|
|
|
|
if cmn.RandInt()%2 > 0 { |
|
|
|
|
|
// sometimes its up to 5
|
|
|
|
|
|
times = cmn.RandInt() % 5 |
|
|
|
|
|
} |
|
|
|
|
|
vset.IncrementAccum(times) |
|
|
|
|
|
|
|
|
|
|
|
j += times |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func BenchmarkValidatorSetCopy(b *testing.B) { |
|
|
func BenchmarkValidatorSetCopy(b *testing.B) { |
|
|
b.StopTimer() |
|
|
b.StopTimer() |
|
|
vset := NewValidatorSet([]*Validator{}) |
|
|
vset := NewValidatorSet([]*Validator{}) |
|
|