Browse Source

types: NewValidatorSet doesn't panic on empty valz list (#2938)

* types: NewValidatorSet doesn't panic on empty valz list

* changelog
pull/2940/head
Ethan Buchman 6 years ago
committed by GitHub
parent
commit
b11788d36d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +3
    -3
      types/validator_set.go
  3. +5
    -2
      types/validator_set_test.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -30,3 +30,5 @@ program](https://hackerone.com/tendermint).
- [consensus] [\#2871](https://github.com/tendermint/tendermint/issues/2871) Remove *ProposalHeartbeat* infrastructure as it serves no real purpose
### BUG FIXES:
- [types] \#2938 Fix regression in v0.26.4 where we panic on empty
genDoc.Validators

+ 3
- 3
types/validator_set.go View File

@ -29,10 +29,10 @@ type ValidatorSet struct {
totalVotingPower int64
}
// NewValidatorSet initializes a ValidatorSet by copying over the
// values from `valz`, a list of Validators. If valz is nil or empty,
// the new ValidatorSet will have an empty list of Validators.
func NewValidatorSet(valz []*Validator) *ValidatorSet {
if valz != nil && len(valz) == 0 {
panic("validator set initialization slice cannot be an empty slice (but it can be nil)")
}
validators := make([]*Validator, len(valz))
for i, val := range valz {
validators[i] = val.Copy()


+ 5
- 2
types/validator_set_test.go View File

@ -17,9 +17,12 @@ import (
)
func TestValidatorSetBasic(t *testing.T) {
assert.Panics(t, func() { NewValidatorSet([]*Validator{}) })
// empty or nil validator lists are allowed,
// but attempting to IncrementAccum on them will panic.
vset := NewValidatorSet([]*Validator{})
assert.Panics(t, func() { vset.IncrementAccum(1) })
vset := NewValidatorSet(nil)
vset = NewValidatorSet(nil)
assert.Panics(t, func() { vset.IncrementAccum(1) })
assert.EqualValues(t, vset, vset.Copy())


Loading…
Cancel
Save