mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 14:21:14 +00:00
types: update synchrony params to match checked in proto (#8142)
The `.proto` file do not have the `nullable = false` annotation present on the `SynchronyParams` durations. This pull request updates the `SynchronyParams` to match the checked in proto files. Note, this does not make the code buildable against the latest protos. This pull request was achieved by checking out all files _not relevant_ to the `SynchronyParams` and removing the new `TimeoutParams` from the the `params.proto` file. Future updates will add these back. This pull request also adds a `nil` check to the `pbParams.Synchrony` field in `ConsensusParamsFromProto`. Old versions of Tendermint will not have the `Synchrony` parameters filled in so this code would panic on startup. We will fill in the empty fields with defaults, but per https://github.com/tendermint/tendermint/blob/master/docs/rfc/rfc-009-consensus-parameter-upgrades.md#only-update-hashedparams-on-hash-breaking-releases we will keep out of the hash during this release.
This commit is contained in:
@@ -275,8 +275,12 @@ func (params ConsensusParams) UpdateConsensusParams(params2 *tmproto.ConsensusPa
|
||||
res.Version.AppVersion = params2.Version.AppVersion
|
||||
}
|
||||
if params2.Synchrony != nil {
|
||||
res.Synchrony.Precision = params2.Synchrony.Precision
|
||||
res.Synchrony.MessageDelay = params2.Synchrony.MessageDelay
|
||||
if params2.Synchrony.MessageDelay != nil {
|
||||
res.Synchrony.MessageDelay = *params2.Synchrony.GetMessageDelay()
|
||||
}
|
||||
if params2.Synchrony.Precision != nil {
|
||||
res.Synchrony.Precision = *params2.Synchrony.GetPrecision()
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -299,14 +303,14 @@ func (params *ConsensusParams) ToProto() tmproto.ConsensusParams {
|
||||
AppVersion: params.Version.AppVersion,
|
||||
},
|
||||
Synchrony: &tmproto.SynchronyParams{
|
||||
MessageDelay: params.Synchrony.MessageDelay,
|
||||
Precision: params.Synchrony.Precision,
|
||||
MessageDelay: ¶ms.Synchrony.MessageDelay,
|
||||
Precision: ¶ms.Synchrony.Precision,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams {
|
||||
return ConsensusParams{
|
||||
c := ConsensusParams{
|
||||
Block: BlockParams{
|
||||
MaxBytes: pbParams.Block.MaxBytes,
|
||||
MaxGas: pbParams.Block.MaxGas,
|
||||
@@ -322,9 +326,14 @@ func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams
|
||||
Version: VersionParams{
|
||||
AppVersion: pbParams.Version.AppVersion,
|
||||
},
|
||||
Synchrony: SynchronyParams{
|
||||
MessageDelay: pbParams.Synchrony.MessageDelay,
|
||||
Precision: pbParams.Synchrony.Precision,
|
||||
},
|
||||
}
|
||||
if pbParams.Synchrony != nil {
|
||||
if pbParams.Synchrony.MessageDelay != nil {
|
||||
c.Synchrony.MessageDelay = *pbParams.Synchrony.GetMessageDelay()
|
||||
}
|
||||
if pbParams.Synchrony.Precision != nil {
|
||||
c.Synchrony.Precision = *pbParams.Synchrony.GetPrecision()
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -246,8 +246,8 @@ func TestConsensusParamsUpdate(t *testing.T) {
|
||||
intialParams: makeParams(makeParamsArgs{evidenceAge: 3, precision: time.Second, messageDelay: 3 * time.Second}),
|
||||
updates: &tmproto.ConsensusParams{
|
||||
Synchrony: &tmproto.SynchronyParams{
|
||||
Precision: time.Second * 2,
|
||||
MessageDelay: time.Second * 4,
|
||||
Precision: durationPtr(time.Second * 2),
|
||||
MessageDelay: durationPtr(time.Second * 4),
|
||||
},
|
||||
},
|
||||
updatedParams: makeParams(makeParamsArgs{evidenceAge: 3, precision: 2 * time.Second, messageDelay: 4 * time.Second}),
|
||||
@@ -339,3 +339,7 @@ func TestProto(t *testing.T) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func durationPtr(t time.Duration) *time.Duration {
|
||||
return &t
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user