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

Add ValidatorPubkeyTypes as a consensus param #2636

Merged
merged 10 commits into from
Oct 30, 2018
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ BREAKING CHANGES:
`PrecommitType`.

* Blockchain Protocol
* [abci] [\#2636](https://github.com/tendermint/tendermint/issues/2636) Add ValidatorParams field to ConsensusParams.
(Used to control which pubkey types validators can use, by amino route)
* [types] Update SignBytes for `Vote`/`Proposal`/`Heartbeat`:
* [\#2459](https://github.com/tendermint/tendermint/issues/2459) Use amino encoding instead of JSON in `SignBytes`.
* [\#2598](https://github.com/tendermint/tendermint/issues/2598) Reorder fields and use fixed sized encoding.
Expand Down
992 changes: 734 additions & 258 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions abci/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ message ResponseCommit {
message ConsensusParams {
BlockSize block_size = 1;
EvidenceParams evidence_params = 2;
ValidatorParams validator_params = 3;
}

// BlockSize contains limits on the block size.
Expand All @@ -226,6 +227,11 @@ message EvidenceParams {
int64 max_age = 1;
}

// ValidatorParams contains limits on validators.
message ValidatorParams {
repeated string validator_pubkey_types = 3;
}

message LastCommitInfo {
int32 round = 1;
repeated VoteInfo votes = 2 [(gogoproto.nullable)=false];
Expand Down
124 changes: 124 additions & 0 deletions abci/types/typespb_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/spec/abci/abci.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ Commit are included in the header of the next block.
- `BlockSize (BlockSize)`: Parameters limiting the size of a block.
- `EvidenceParams (EvidenceParams)`: Parameters limiting the validity of
evidence of byzantine behaviour.
- `ValidatorPubkeyTypes ([]string)`: List of amino routes for the pubkeys
which validators may use.

### BlockSize

Expand Down
2 changes: 1 addition & 1 deletion state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func LoadConsensusParams(db dbm.DB, height int64) (types.ConsensusParams, error)
return empty, ErrNoConsensusParamsForHeight{height}
}

if paramsInfo.ConsensusParams == empty {
if paramsInfo.ConsensusParams.Equals(&empty) {
paramsInfo2 := loadConsensusParamsInfo(db, paramsInfo.LastHeightChanged)
if paramsInfo2 == nil {
panic(
Expand Down
41 changes: 41 additions & 0 deletions types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"
)
Expand All @@ -19,6 +20,7 @@ const (
type ConsensusParams struct {
BlockSize `json:"block_size_params"`
EvidenceParams `json:"evidence_params"`
Validator ValidatorParams `json:"validator_params"`
}

// BlockSize contain limits on the block size.
Expand All @@ -32,11 +34,16 @@ type EvidenceParams struct {
MaxAge int64 `json:"max_age"` // only accept new evidence more recent than this
}

type ValidatorParams struct {
ValidatorPubkeyTypes []string `json:"validator_pubkey_types"` // amino routes accepted for validator pubkeys
}

// DefaultConsensusParams returns a default ConsensusParams.
func DefaultConsensusParams() *ConsensusParams {
return &ConsensusParams{
DefaultBlockSize(),
DefaultEvidenceParams(),
DefaultValidatorParams(),
}
}

Expand All @@ -55,6 +62,12 @@ func DefaultEvidenceParams() EvidenceParams {
}
}

// DefaultValidatorParams returns a default ValidatorParams, which allows
// only ed25519 pubkeys.
func DefaultValidatorParams() ValidatorParams {
return ValidatorParams{[]string{ed25519.PubKeyAminoRoute}}
}

// Validate validates the ConsensusParams to ensure all values are within their
// allowed limits, and returns an error if they are not.
func (params *ConsensusParams) Validate() error {
Expand All @@ -77,6 +90,10 @@ func (params *ConsensusParams) Validate() error {
params.EvidenceParams.MaxAge)
}

if len(params.Validator.ValidatorPubkeyTypes) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also validate that the types given are known?

return cmn.NewError("len(ValidatorParams.ValidatorPubkeyTypes) must be greater than 0")
}

return nil
}

Expand All @@ -94,6 +111,27 @@ func (params *ConsensusParams) Hash() []byte {
return hasher.Sum(nil)
}

func (params *ConsensusParams) Equals(params2 *ConsensusParams) bool {
if params.BlockSize == params2.BlockSize &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just return this conjunction instead of using the conditional

params.EvidenceParams == params2.EvidenceParams &&
stringSliceEqual(params.Validator.ValidatorPubkeyTypes, params2.Validator.ValidatorPubkeyTypes) {
return true
}
return false
}

func stringSliceEqual(a, b []string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to cmn#string.go?

if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
return false
}
}
return true
}

// Update returns a copy of the params with updates from the non-zero fields of p2.
// NOTE: note: must not modify the original
func (params ConsensusParams) Update(params2 *abci.ConsensusParams) ConsensusParams {
Expand All @@ -111,5 +149,8 @@ func (params ConsensusParams) Update(params2 *abci.ConsensusParams) ConsensusPar
if params2.EvidenceParams != nil {
res.EvidenceParams.MaxAge = params2.EvidenceParams.MaxAge
}
if params2.ValidatorParams != nil {
res.Validator.ValidatorPubkeyTypes = params2.ValidatorParams.ValidatorPubkeyTypes
}
return res
}
Loading