Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initializing LastValidatorSet as well on InitChain #390

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func NewManager(
return nil, err
}
validators = append(validators, tmtypes.NewValidator(tmPubKey, 1))

}

res, err := exec.InitChain(genesis, validators)
Expand Down Expand Up @@ -817,6 +816,11 @@ func updateInitChainState(s *types.State, res *abci.ResponseInitChain, validator
copy(s.AppHash[:], res.AppHash)
}

//The validators after initChain must be greater than zero, otherwise this state is not loadable
if len(validators) <= 0 {
panic("Validators must be greater than zero")
}

if res.ConsensusParams != nil {
params := res.ConsensusParams
if params.Block != nil {
Expand All @@ -841,8 +845,8 @@ func updateInitChainState(s *types.State, res *abci.ResponseInitChain, validator
// We update the last results hash with the empty hash, to conform with RFC-6962.
copy(s.LastResultsHash[:], merkle.HashFromByteSlices(nil))

if len(validators) > 0 {
s.Validators = tmtypes.NewValidatorSet(validators)
s.NextValidators = tmtypes.NewValidatorSet(validators).CopyIncrementProposerPriority(1)
}
// Set the validators in the state
s.Validators = tmtypes.NewValidatorSet(validators).CopyIncrementProposerPriority(1)
s.NextValidators = s.Validators.Copy()
s.LastValidators = s.Validators.Copy()
}