abci++: add proto fields for enabling vote extensions (#8587)

This pull requests adds the protocol buffer field for the `ABCI.VoteExtensionsEnableHeight` parameter. This proto field is threaded throughout all of the relevant places where consensus params are used and referenced.

This PR also adds validation of the consensus param updates. Previous consensus param changes didn't depend on _previous_ versions of the params, so this change adds a method for validating against the old params as well.

closes: #8453
This commit is contained in:
William Banfield
2022-05-23 18:23:23 +00:00
committed by GitHub
parent 6ff77eece3
commit 43313e9b85
14 changed files with 553 additions and 129 deletions
+37
View File
@@ -330,6 +330,9 @@ func (params ConsensusParams) ValidateConsensusParams() error {
if params.Timeout.Commit <= 0 {
return fmt.Errorf("timeout.Commit must be greater than 0. Got: %d", params.Timeout.Commit)
}
if params.ABCI.VoteExtensionsEnableHeight < 0 {
return fmt.Errorf("ABCI.VoteExtensionsEnableHeight cannot be negative. Got: %d", params.ABCI.VoteExtensionsEnableHeight)
}
if len(params.Validator.PubKeyTypes) == 0 {
return errors.New("len(Validator.PubKeyTypes) must be greater than 0")
@@ -347,6 +350,30 @@ func (params ConsensusParams) ValidateConsensusParams() error {
return nil
}
func (params ConsensusParams) ValidateUpdate(updated *tmproto.ConsensusParams, h int64) error {
if updated.Abci == nil {
return nil
}
if params.ABCI.VoteExtensionsEnableHeight == updated.Abci.VoteExtensionsEnableHeight {
return nil
}
if params.ABCI.VoteExtensionsEnableHeight != 0 && updated.Abci.VoteExtensionsEnableHeight == 0 {
return errors.New("vote extensions cannot be disabled once enabled")
}
if updated.Abci.VoteExtensionsEnableHeight <= h {
return fmt.Errorf("VoteExtensionsEnableHeight cannot be updated to a past height, "+
"initial height: %d, current height %d",
params.ABCI.VoteExtensionsEnableHeight, h)
}
if params.ABCI.VoteExtensionsEnableHeight <= h {
return fmt.Errorf("VoteExtensionsEnableHeight cannot be updated modified once"+
"the initial height has occurred, "+
"initial height: %d, current height %d",
params.ABCI.VoteExtensionsEnableHeight, h)
}
return nil
}
// Hash returns a hash of a subset of the parameters to store in the block header.
// Only the Block.MaxBytes and Block.MaxGas are included in the hash.
// This allows the ConsensusParams to evolve more without breaking the block
@@ -373,6 +400,7 @@ func (params *ConsensusParams) Equals(params2 *ConsensusParams) bool {
params.Version == params2.Version &&
params.Synchrony == params2.Synchrony &&
params.Timeout == params2.Timeout &&
params.ABCI == params2.ABCI &&
tmstrings.StringSliceEqual(params.Validator.PubKeyTypes, params2.Validator.PubKeyTypes)
}
@@ -429,6 +457,9 @@ func (params ConsensusParams) UpdateConsensusParams(params2 *tmproto.ConsensusPa
}
res.Timeout.BypassCommitTimeout = params2.Timeout.GetBypassCommitTimeout()
}
if params2.Abci != nil {
res.ABCI.VoteExtensionsEnableHeight = params2.Abci.GetVoteExtensionsEnableHeight()
}
return res
}
@@ -461,6 +492,9 @@ func (params *ConsensusParams) ToProto() tmproto.ConsensusParams {
Commit: &params.Timeout.Commit,
BypassCommitTimeout: params.Timeout.BypassCommitTimeout,
},
Abci: &tmproto.ABCIParams{
VoteExtensionsEnableHeight: params.ABCI.VoteExtensionsEnableHeight,
},
}
}
@@ -508,5 +542,8 @@ func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams
}
c.Timeout.BypassCommitTimeout = pbParams.Timeout.BypassCommitTimeout
}
if pbParams.Abci != nil {
c.ABCI.VoteExtensionsEnableHeight = pbParams.Abci.GetVoteExtensionsEnableHeight()
}
return c
}