limit chain ID to 50 symbols max

This commit is contained in:
Anton Kaliaev 2018-08-30 12:59:05 +04:00
parent d73c5cbdb1
commit 0f7485690e
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
2 changed files with 8 additions and 4 deletions

View File

@ -19,9 +19,6 @@ const (
// MaxAminoOverheadForBlock - amino overhead to encode the block.
MaxAminoOverheadForBlock = 4
// MaxChainIDLen is a maximum length of the chain ID.
MaxChainIDLen = 50
)
// Block defines the atomic unit of a Tendermint blockchain.

View File

@ -10,6 +10,11 @@ import (
cmn "github.com/tendermint/tendermint/libs/common"
)
const (
// MaxChainIDLen is a maximum length of the chain ID.
MaxChainIDLen = 50
)
//------------------------------------------------------------
// core types for a genesis definition
@ -52,10 +57,12 @@ func (genDoc *GenesisDoc) ValidatorHash() []byte {
// ValidateAndComplete checks that all necessary fields are present
// and fills in defaults for optional fields left empty
func (genDoc *GenesisDoc) ValidateAndComplete() error {
if genDoc.ChainID == "" {
return cmn.NewError("Genesis doc must include non-empty chain_id")
}
if len(genDoc.ChainID) > MaxChainIDLen {
return cmn.NewError(fmt.Sprintf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen))
}
if genDoc.ConsensusParams == nil {
genDoc.ConsensusParams = DefaultConsensusParams()