-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Changes from 6 commits
5e68d1c
49cfa31
cdeb0d0
ba52834
d883524
a5cc8ac
241bf3d
e85a96c
d3381af
27cd7c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
|
@@ -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. | ||
|
@@ -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(), | ||
} | ||
} | ||
|
||
|
@@ -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 { | ||
|
@@ -77,6 +90,10 @@ func (params *ConsensusParams) Validate() error { | |
params.EvidenceParams.MaxAge) | ||
} | ||
|
||
if len(params.Validator.ValidatorPubkeyTypes) == 0 { | ||
return cmn.NewError("len(ValidatorParams.ValidatorPubkeyTypes) must be greater than 0") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -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 && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -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 | ||
} |
There was a problem hiding this comment.
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?