mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
[R4R] Pass nil to NewValidatorSet() when genesis file's Validators field is nil (#2617)
* Pass nil to NewValidatorSet() when genesis file's Validators field is nil Closes: #2616 * Update CHANGELOG_PENDING.md
This commit is contained in:
parent
7b48ea1788
commit
3744e8271d
@ -57,3 +57,4 @@ timeoutPrecommit before starting next round
|
|||||||
block
|
block
|
||||||
- [p2p] \#2555 fix p2p switch FlushThrottle value (@goolAdapter)
|
- [p2p] \#2555 fix p2p switch FlushThrottle value (@goolAdapter)
|
||||||
- [libs/event] \#2518 fix event concurrency flaw (@goolAdapter)
|
- [libs/event] \#2518 fix event concurrency flaw (@goolAdapter)
|
||||||
|
- [state] \#2616 Pass nil to NewValidatorSet() when genesis file's Validators field is nil
|
||||||
|
@ -198,6 +198,11 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make validators slice
|
// Make validators slice
|
||||||
|
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))
|
validators := make([]*types.Validator, len(genDoc.Validators))
|
||||||
for i, val := range genDoc.Validators {
|
for i, val := range genDoc.Validators {
|
||||||
pubKey := val.PubKey
|
pubKey := val.PubKey
|
||||||
@ -210,6 +215,9 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
|
|||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user