You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

  1. package proxy
  2. import (
  3. "bytes"
  4. "github.com/pkg/errors"
  5. "github.com/tendermint/tendermint/lite"
  6. certerr "github.com/tendermint/tendermint/lite/errors"
  7. "github.com/tendermint/tendermint/types"
  8. )
  9. func ValidateBlockMeta(meta *types.BlockMeta, check lite.Commit) error {
  10. // TODO: check the BlockID??
  11. return ValidateHeader(meta.Header, check)
  12. }
  13. func ValidateBlock(meta *types.Block, check lite.Commit) error {
  14. err := ValidateHeader(meta.Header, check)
  15. if err != nil {
  16. return err
  17. }
  18. if !bytes.Equal(meta.Data.Hash(), meta.Header.DataHash) {
  19. return errors.New("Data hash doesn't match header")
  20. }
  21. return nil
  22. }
  23. func ValidateHeader(head *types.Header, check lite.Commit) error {
  24. // make sure they are for the same height (obvious fail)
  25. if head.Height != check.Height() {
  26. return certerr.ErrHeightMismatch(head.Height, check.Height())
  27. }
  28. // check if they are equal by using hashes
  29. chead := check.Header
  30. if !bytes.Equal(head.Hash(), chead.Hash()) {
  31. return errors.New("Headers don't match")
  32. }
  33. return nil
  34. }