diff --git a/types/block.go b/types/block.go index d881bd491..6eff57dd7 100644 --- a/types/block.go +++ b/types/block.go @@ -423,9 +423,6 @@ func (h Header) ValidateBasic() error { if len(h.ChainID) > MaxChainIDLen { return fmt.Errorf("chainID is too long; got: %d, max: %d", len(h.ChainID), MaxChainIDLen) } - if h.Round < 0 { - return errors.New("negative Round") - } if h.Height < 0 { return errors.New("negative Height") @@ -456,19 +453,11 @@ func (h Header) ValidateBasic() error { ) } - if err := ValidateProof(h.Proof); err != nil { - return fmt.Errorf("wrong Proof: %v", err) - } - // Basic validation of hashes related to application data. // Will validate fully against state in state#ValidateBlock. if err := ValidateHash(h.ValidatorsHash); err != nil { return fmt.Errorf("wrong ValidatorsHash: %v", err) } - if err := ValidateHash(h.VotersHash); err != nil { - return fmt.Errorf("wrong VotersHash: %v", err) - } - // TODO When we add `Header.ValidatorsHash` in a future commit, we have to add a similar check here. if err := ValidateHash(h.NextValidatorsHash); err != nil { return fmt.Errorf("wrong NextValidatorsHash: %v", err) } @@ -480,6 +469,18 @@ func (h Header) ValidateBasic() error { return fmt.Errorf("wrong LastResultsHash: %v", err) } + if err := ValidateHash(h.VotersHash); err != nil { + return fmt.Errorf("wrong VotersHash: %v", err) + } + + if h.Round < 0 { + return errors.New("negative Round") + } + + if err := ValidateProof(h.Proof); err != nil { + return fmt.Errorf("wrong Proof: %v", err) + } + return nil } diff --git a/types/block_test.go b/types/block_test.go index b743fde26..41e2305fe 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -495,8 +495,6 @@ func TestCommitHash(t *testing.T) { }) } -// The Proof defined here does not depend on the vrf ProofLength, -// but it is a fixed value for the purpose of calculating the Hash value. func TestHeaderHash(t *testing.T) { testCases := []struct { desc string @@ -520,7 +518,9 @@ func TestHeaderHash(t *testing.T) { EvidenceHash: tmhash.Sum([]byte("evidence_hash")), ProposerAddress: crypto.AddressHash([]byte("proposer_address")), Round: 1, - Proof: tmhash.Sum([]byte("proof")), + // The Proof defined here does not depend on the vrf ProofLength, + // but it is a fixed value for the purpose of calculating the Hash value. + Proof: tmhash.Sum([]byte("proof")), }, hexBytesFromString("0368E6F15B6B7BC9DC5B10F36F37D6F867E132A22333F083A11290324274E183")}, {"nil header yields nil", nil, nil}, {"nil VotersHash yields nil", &Header{ @@ -539,7 +539,9 @@ func TestHeaderHash(t *testing.T) { EvidenceHash: tmhash.Sum([]byte("evidence_hash")), ProposerAddress: crypto.AddressHash([]byte("proposer_address")), Round: 1, - Proof: tmhash.Sum([]byte("proof")), + // The Proof defined here does not depend on the vrf ProofLength, + // but it is a fixed value for the purpose of calculating the Hash value. + Proof: tmhash.Sum([]byte("proof")), }, nil}, } for _, tc := range testCases {