ValidateBasic performs stateless validation on a Header returning an error if any validation fails. NOTE: Timestamp validation is subtle and handled elsewhere.
()
| 384 | // |
| 385 | // NOTE: Timestamp validation is subtle and handled elsewhere. |
| 386 | func (h Header) ValidateBasic() error { |
| 387 | if h.Version.Block != version.BlockProtocol { |
| 388 | return fmt.Errorf("block protocol is incorrect: got: %d, want: %d ", h.Version.Block, version.BlockProtocol) |
| 389 | } |
| 390 | if len(h.ChainID) > MaxChainIDLen { |
| 391 | return fmt.Errorf("chainID is too long; got: %d, max: %d", len(h.ChainID), MaxChainIDLen) |
| 392 | } |
| 393 | |
| 394 | if h.Height < 0 { |
| 395 | return errors.New("negative Height") |
| 396 | } else if h.Height == 0 { |
| 397 | return errors.New("zero Height") |
| 398 | } |
| 399 | |
| 400 | if err := h.LastBlockID.ValidateBasic(); err != nil { |
| 401 | return fmt.Errorf("wrong LastBlockID: %w", err) |
| 402 | } |
| 403 | |
| 404 | if err := ValidateHash(h.LastCommitHash); err != nil { |
| 405 | return fmt.Errorf("wrong LastCommitHash: %v", err) |
| 406 | } |
| 407 | |
| 408 | if err := ValidateHash(h.DataHash); err != nil { |
| 409 | return fmt.Errorf("wrong DataHash: %v", err) |
| 410 | } |
| 411 | |
| 412 | if err := ValidateHash(h.EvidenceHash); err != nil { |
| 413 | return fmt.Errorf("wrong EvidenceHash: %v", err) |
| 414 | } |
| 415 | |
| 416 | if len(h.ProposerAddress) != crypto.AddressSize { |
| 417 | return fmt.Errorf( |
| 418 | "invalid ProposerAddress length; got: %d, expected: %d", |
| 419 | len(h.ProposerAddress), crypto.AddressSize, |
| 420 | ) |
| 421 | } |
| 422 | |
| 423 | // Basic validation of hashes related to application data. |
| 424 | // Will validate fully against state in state#ValidateBlock. |
| 425 | if err := ValidateHash(h.ValidatorsHash); err != nil { |
| 426 | return fmt.Errorf("wrong ValidatorsHash: %v", err) |
| 427 | } |
| 428 | if err := ValidateHash(h.NextValidatorsHash); err != nil { |
| 429 | return fmt.Errorf("wrong NextValidatorsHash: %v", err) |
| 430 | } |
| 431 | if err := ValidateHash(h.ConsensusHash); err != nil { |
| 432 | return fmt.Errorf("wrong ConsensusHash: %v", err) |
| 433 | } |
| 434 | // NOTE: AppHash is arbitrary length |
| 435 | if err := ValidateHash(h.LastResultsHash); err != nil { |
| 436 | return fmt.Errorf("wrong LastResultsHash: %v", err) |
| 437 | } |
| 438 | |
| 439 | return nil |
| 440 | } |
| 441 | |
| 442 | // Hash returns the hash of the header. |
| 443 | // It computes a Merkle tree from the header fields |
nothing calls this directly
no test coverage detected