From 0f7485690e51c81c9169a889c922913ab4e5c93b Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 30 Aug 2018 12:59:05 +0400 Subject: [PATCH] limit chain ID to 50 symbols max --- types/block.go | 3 --- types/genesis.go | 9 ++++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/types/block.go b/types/block.go index 1037caccc..7d4551e5b 100644 --- a/types/block.go +++ b/types/block.go @@ -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. diff --git a/types/genesis.go b/types/genesis.go index ccfd019c7..0594c0e3e 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -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()