Skip to content

Commit

Permalink
Separate the diff with tendermint down into the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mdaiki0730 committed Nov 28, 2022
1 parent 07dec16 commit 1f82b3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
23 changes: 12 additions & 11 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}

Expand Down
10 changes: 6 additions & 4 deletions types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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 {
Expand Down

0 comments on commit 1f82b3a

Please sign in to comment.