use NewValidator; fix setPrivValidatorIndex

This commit is contained in:
Ethan Buchman 2016-11-19 20:34:07 -05:00
parent e0db20c0cf
commit 6f8c91b651
3 changed files with 13 additions and 22 deletions

View File

@ -588,12 +588,14 @@ func (cs *ConsensusState) updateToState(state *sm.State) {
}
func (cs *ConsensusState) setPrivValidatorIndex() {
// TODO: just return -1 for not found
valIdx, val := cs.state.Validators.GetByAddress(cs.privValidator.GetAddress())
if val == nil {
cs.privValidatorIndex = -1
} else {
cs.privValidatorIndex = valIdx
if cs.privValidator != nil {
// TODO: just return -1 for not found
valIdx, val := cs.state.Validators.GetByAddress(cs.privValidator.GetAddress())
if val == nil {
cs.privValidatorIndex = -1
} else {
cs.privValidatorIndex = valIdx
}
}
}

View File

@ -102,11 +102,6 @@ func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidator)
if randPower {
votePower += int64(RandUint32())
}
val := &Validator{
Address: privVal.Address,
PubKey: privVal.PubKey,
VotingPower: votePower,
Accum: 0,
}
val := NewValidator(privVal.PubKey, votePower)
return val, privVal
}

View File

@ -16,12 +16,9 @@ func randPubKey() crypto.PubKeyEd25519 {
}
func randValidator_() *Validator {
return &Validator{
Address: RandBytes(20),
PubKey: randPubKey(),
VotingPower: RandInt64(),
Accum: RandInt64(),
}
val := NewValidator(randPubKey(), RandInt64())
val.Accum = RandInt64()
return val
}
func randValidatorSet(numValidators int) *ValidatorSet {
@ -147,10 +144,7 @@ func BenchmarkValidatorSetCopy(b *testing.B) {
for i := 0; i < 1000; i++ {
privKey := crypto.GenPrivKeyEd25519()
pubKey := privKey.PubKey().(crypto.PubKeyEd25519)
val := &Validator{
Address: pubKey.Address(),
PubKey: pubKey,
}
val := NewValidator(pubKey, 0)
if !vset.Add(val) {
panic("Failed to add validator")
}