Skip to content

MakeGenesisState() populates State's ValidatorSets with empty slices unconditionally #2616

@alessio

Description

@alessio

When genesis's Validators is a nil slice, State's Validators and NextValidators fields should be populated accordingly.
A patch follows:

--- vendor/github.com/tendermint/tendermint/state/state.go.orig	2018-10-11 15:22:42.556215269 -0700
+++ vendor/github.com/tendermint/tendermint/state/state.go	2018-10-11 15:34:07.668015560 -0700
@@ -198,17 +198,25 @@ func MakeGenesisState(genDoc *types.Gene
 	}
 
 	// Make validators slice
-	validators := make([]*types.Validator, len(genDoc.Validators))
-	for i, val := range genDoc.Validators {
-		pubKey := val.PubKey
-		address := pubKey.Address()
-
-		// Make validator
-		validators[i] = &types.Validator{
-			Address:     address,
-			PubKey:      pubKey,
-			VotingPower: val.Power,
+	var validatorSet, nextValidatorSet *types.ValidatorSet
+	if genDoc.Validators == nil {
+		validatorSet = types.NewValidatorSet(nil)
+		nextValidatorSet = types.NewValidatorSet(nil)
+	} else {
+		validators := make([]*types.Validator, len(genDoc.Validators))
+		for i, val := range genDoc.Validators {
+			pubKey := val.PubKey
+			address := pubKey.Address()
+
+			// Make validator
+			validators[i] = &types.Validator{
+				Address:     address,
+				PubKey:      pubKey,
+				VotingPower: val.Power,
+			}
 		}
+		validatorSet = types.NewValidatorSet(validators)
+		nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementAccum(1)
 	}
 
 	return State{
@@ -219,8 +227,8 @@ func MakeGenesisState(genDoc *types.Gene
 		LastBlockID:     types.BlockID{},
 		LastBlockTime:   genDoc.GenesisTime,
 
-		NextValidators:              types.NewValidatorSet(validators).CopyIncrementAccum(1),
-		Validators:                  types.NewValidatorSet(validators),
+		NextValidators:              nextValidatorSet,
+		Validators:                  validatorSet,
 		LastValidators:              types.NewValidatorSet(nil),
 		LastHeightValidatorsChanged: 1,
 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions