mirror of
https://github.com/tendermint/tendermint.git
synced 2026-05-22 07:01:29 +00:00
update validate/complete logic for consensus params
This commit is contained in:
@@ -455,7 +455,7 @@ func updateState(
|
||||
if abciResponses.EndBlock.ConsensusParamUpdates != nil {
|
||||
// NOTE: must not mutate s.ConsensusParams
|
||||
nextParams = state.ConsensusParams.UpdateConsensusParams(abciResponses.EndBlock.ConsensusParamUpdates)
|
||||
err := nextParams.ValidateConsensusParams()
|
||||
err := nextParams.Validate()
|
||||
if err != nil {
|
||||
return state, fmt.Errorf("error updating consensus params: %w", err)
|
||||
}
|
||||
|
||||
@@ -239,7 +239,9 @@ func FromProto(pb *tmstate.State) (*State, error) {
|
||||
}
|
||||
|
||||
state.LastHeightValidatorsChanged = pb.LastHeightValidatorsChanged
|
||||
state.ConsensusParams = types.ConsensusParamsFromProto(pb.ConsensusParams)
|
||||
c := types.ConsensusParamsFromProto(pb.ConsensusParams)
|
||||
(&c).Complete()
|
||||
state.ConsensusParams = c
|
||||
state.LastHeightConsensusParamsChanged = pb.LastHeightConsensusParamsChanged
|
||||
state.LastResultsHash = pb.LastResultsHash
|
||||
state.AppHash = pb.AppHash
|
||||
|
||||
@@ -269,7 +269,7 @@ func (c *Client) ConsensusParams(ctx context.Context, height *int64) (*coretypes
|
||||
}
|
||||
|
||||
// Validate res.
|
||||
if err := res.ConsensusParams.ValidateConsensusParams(); err != nil {
|
||||
if err := res.ConsensusParams.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.BlockHeight <= 0 {
|
||||
|
||||
@@ -113,7 +113,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
||||
|
||||
if genDoc.ConsensusParams == nil {
|
||||
genDoc.ConsensusParams = DefaultConsensusParams()
|
||||
} else if err := genDoc.ConsensusParams.ValidateConsensusParams(); err != nil {
|
||||
} else if err := genDoc.ConsensusParams.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -145,9 +145,22 @@ func (val *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (params *ConsensusParams) Complete() {
|
||||
if params.Synchrony.MessageDelay == 0 && params.Synchrony.Precision == 0 {
|
||||
params.Synchrony = DefaultSynchronyParams()
|
||||
}
|
||||
}
|
||||
func (params *ConsensusParams) ValidateAndComplete() error {
|
||||
if params == nil {
|
||||
params = DefaultConsensusParams()
|
||||
}
|
||||
params.Complete()
|
||||
return params.Validate()
|
||||
}
|
||||
|
||||
// Validate validates the ConsensusParams to ensure all values are within their
|
||||
// allowed limits, and returns an error if they are not.
|
||||
func (params ConsensusParams) ValidateConsensusParams() error {
|
||||
func (params *ConsensusParams) Validate() error {
|
||||
if params.Block.MaxBytes <= 0 {
|
||||
return fmt.Errorf("block.MaxBytes must be greater than 0. Got %d",
|
||||
params.Block.MaxBytes)
|
||||
|
||||
@@ -160,9 +160,9 @@ func TestConsensusParamsValidation(t *testing.T) {
|
||||
}
|
||||
for i, tc := range testCases {
|
||||
if tc.valid {
|
||||
assert.NoErrorf(t, tc.params.ValidateConsensusParams(), "expected no error for valid params (#%d)", i)
|
||||
assert.NoErrorf(t, tc.params.Validate(), "expected no error for valid params (#%d)", i)
|
||||
} else {
|
||||
assert.Errorf(t, tc.params.ValidateConsensusParams(), "expected error for non valid params (#%d)", i)
|
||||
assert.Errorf(t, tc.params.Validate(), "expected error for non valid params (#%d)", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user