diff --git a/state/validator.go b/state/validator.go index e16c6246a..20f12532e 100644 --- a/state/validator.go +++ b/state/validator.go @@ -56,6 +56,7 @@ type Validator struct { } // Creates a new copy of the validator so we can mutate accum. +// Panics if the validator is nil. func (v *Validator) Copy() *Validator { vCopy := *v return &vCopy @@ -83,6 +84,9 @@ func (v *Validator) CompareAccum(other *Validator) *Validator { } func (v *Validator) String() string { + if v == nil { + return "nil-Validator" + } return fmt.Sprintf("Validator{%X %v %v-%v-%v VP:%v A:%v}", v.Address, v.PubKey, diff --git a/state/validator_set.go b/state/validator_set.go index 27f1c29da..7f821d9c1 100644 --- a/state/validator_set.go +++ b/state/validator_set.go @@ -112,6 +112,9 @@ func (valSet *ValidatorSet) TotalVotingPower() int64 { } func (valSet *ValidatorSet) Proposer() (proposer *Validator) { + if len(valSet.Validators) == 0 { + return nil + } if valSet.proposer == nil { for _, val := range valSet.Validators { valSet.proposer = valSet.proposer.CompareAccum(val) @@ -255,6 +258,9 @@ func (valSet *ValidatorSet) String() string { } func (valSet *ValidatorSet) StringIndented(indent string) string { + if valSet == nil { + return "nil-ValidatorSet" + } valStrings := []string{} valSet.Iterate(func(index int, val *Validator) bool { valStrings = append(valStrings, val.String())