mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-24 22:32:15 +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
|
||||
- [p2p] \#2555 fix p2p switch FlushThrottle value (@goolAdapter)
|
||||
- [libs/event] \#2518 fix event concurrency flaw (@goolAdapter)
|
||||
- [state] \#2616 Pass nil to NewValidatorSet() when genesis file's Validators field is nil
|
||||
|
@ -198,17 +198,25 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
|
||||
}
|
||||
|
||||
// Make validators slice
|
||||
validators := make([]*types.Validator, len(genDoc.Validators))
|
||||
for i, val := range genDoc.Validators {
|
||||
pubKey := val.PubKey
|
||||
address := pubKey.Address()
|
||||
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,
|
||||
// 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.GenesisDoc) (State, error) {
|
||||
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,
|
||||
|
||||
|
@ -48,6 +48,19 @@ func TestStateCopy(t *testing.T) {
|
||||
%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.
|
||||
func TestStateSaveLoad(t *testing.T) {
|
||||
tearDown, stateDB, state := setupTestCase(t)
|
||||
|
Loading…
x
Reference in New Issue
Block a user