mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-25 14:12:03 +00:00
Compare commits
2 Commits
master
...
wb/chain-u
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31e61d937c | ||
|
|
f50721c36a |
@@ -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)
|
||||
@@ -299,25 +312,31 @@ func (params *ConsensusParams) ToProto() tmproto.ConsensusParams {
|
||||
}
|
||||
|
||||
func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams {
|
||||
return ConsensusParams{
|
||||
Block: BlockParams{
|
||||
c := ConsensusParams{}
|
||||
if pbParams.Block != nil {
|
||||
c.Block = BlockParams{
|
||||
MaxBytes: pbParams.Block.MaxBytes,
|
||||
MaxGas: pbParams.Block.MaxGas,
|
||||
},
|
||||
Evidence: EvidenceParams{
|
||||
MaxAgeNumBlocks: pbParams.Evidence.MaxAgeNumBlocks,
|
||||
MaxAgeDuration: pbParams.Evidence.MaxAgeDuration,
|
||||
MaxBytes: pbParams.Evidence.MaxBytes,
|
||||
},
|
||||
Validator: ValidatorParams{
|
||||
}
|
||||
}
|
||||
|
||||
if pbParams.Validator != nil {
|
||||
c.Validator = ValidatorParams{
|
||||
PubKeyTypes: pbParams.Validator.PubKeyTypes,
|
||||
},
|
||||
Version: VersionParams{
|
||||
}
|
||||
}
|
||||
|
||||
if pbParams.Validator != nil {
|
||||
c.Version = VersionParams{
|
||||
AppVersion: pbParams.Version.AppVersion,
|
||||
},
|
||||
Synchrony: SynchronyParams{
|
||||
}
|
||||
}
|
||||
|
||||
if pbParams.Synchrony != nil {
|
||||
c.Synchrony = SynchronyParams{
|
||||
MessageDelay: pbParams.Synchrony.MessageDelay,
|
||||
Precision: pbParams.Synchrony.Precision,
|
||||
},
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -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