mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-29 03:05:49 +00:00
Pass nil to NewValidatorSet() when genesis file's Validators field is nil (#2617)
Closes: #2616
This commit is contained in:
@@ -15,3 +15,4 @@ FEATURES:
|
|||||||
IMPROVEMENTS:
|
IMPROVEMENTS:
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
- [state] \#2616 Pass nil to NewValidatorSet() when genesis file's Validators field is nil
|
||||||
|
|||||||
+19
-11
@@ -198,17 +198,25 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make validators slice
|
// Make validators slice
|
||||||
validators := make([]*types.Validator, len(genDoc.Validators))
|
var validatorSet, nextValidatorSet *types.ValidatorSet
|
||||||
for i, val := range genDoc.Validators {
|
if genDoc.Validators == nil {
|
||||||
pubKey := val.PubKey
|
validatorSet = types.NewValidatorSet(nil)
|
||||||
address := pubKey.Address()
|
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
|
// Make validator
|
||||||
validators[i] = &types.Validator{
|
validators[i] = &types.Validator{
|
||||||
Address: address,
|
Address: address,
|
||||||
PubKey: pubKey,
|
PubKey: pubKey,
|
||||||
VotingPower: val.Power,
|
VotingPower: val.Power,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
validatorSet = types.NewValidatorSet(validators)
|
||||||
|
nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementAccum(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return State{
|
return State{
|
||||||
@@ -219,8 +227,8 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
|
|||||||
LastBlockID: types.BlockID{},
|
LastBlockID: types.BlockID{},
|
||||||
LastBlockTime: genDoc.GenesisTime,
|
LastBlockTime: genDoc.GenesisTime,
|
||||||
|
|
||||||
NextValidators: types.NewValidatorSet(validators).CopyIncrementAccum(1),
|
NextValidators: nextValidatorSet,
|
||||||
Validators: types.NewValidatorSet(validators),
|
Validators: validatorSet,
|
||||||
LastValidators: types.NewValidatorSet(nil),
|
LastValidators: types.NewValidatorSet(nil),
|
||||||
LastHeightValidatorsChanged: 1,
|
LastHeightValidatorsChanged: 1,
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,19 @@ func TestStateCopy(t *testing.T) {
|
|||||||
%v`, state))
|
%v`, state))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TestMakeGenesisStateNilValidators tests state's consistency when genesis file's validators field is nil.
|
||||||
|
func TestMakeGenesisStateNilValidators(t *testing.T) {
|
||||||
|
doc := types.GenesisDoc{
|
||||||
|
ChainID: "dummy",
|
||||||
|
Validators: nil,
|
||||||
|
}
|
||||||
|
require.Nil(t, doc.ValidateAndComplete())
|
||||||
|
state, err := MakeGenesisState(&doc)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Equal(t, 0, len(state.Validators.Validators))
|
||||||
|
require.Equal(t, 0, len(state.NextValidators.Validators))
|
||||||
|
}
|
||||||
|
|
||||||
// TestStateSaveLoad tests saving and loading State from a db.
|
// TestStateSaveLoad tests saving and loading State from a db.
|
||||||
func TestStateSaveLoad(t *testing.T) {
|
func TestStateSaveLoad(t *testing.T) {
|
||||||
tearDown, stateDB, state := setupTestCase(t)
|
tearDown, stateDB, state := setupTestCase(t)
|
||||||
|
|||||||
Reference in New Issue
Block a user