Browse Source

use NewValidator; fix setPrivValidatorIndex

pull/319/head
Ethan Buchman 8 years ago
parent
commit
6f8c91b651
3 changed files with 13 additions and 22 deletions
  1. +8
    -6
      consensus/state.go
  2. +1
    -6
      types/validator.go
  3. +4
    -10
      types/validator_set_test.go

+ 8
- 6
consensus/state.go View File

@ -588,12 +588,14 @@ func (cs *ConsensusState) updateToState(state *sm.State) {
} }
func (cs *ConsensusState) setPrivValidatorIndex() { 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
}
} }
} }


+ 1
- 6
types/validator.go View File

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

+ 4
- 10
types/validator_set_test.go View File

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


Loading…
Cancel
Save