ValidateBasic checks that the data is correct and consistent This does no verification of the signatures
(chainID string)
| 19 | // |
| 20 | // This does no verification of the signatures |
| 21 | func (lb LightBlock) ValidateBasic(chainID string) error { |
| 22 | if lb.SignedHeader == nil { |
| 23 | return errors.New("missing signed header") |
| 24 | } |
| 25 | if lb.ValidatorSet == nil { |
| 26 | return errors.New("missing validator set") |
| 27 | } |
| 28 | |
| 29 | if err := lb.SignedHeader.ValidateBasic(chainID); err != nil { |
| 30 | return fmt.Errorf("invalid signed header: %w", err) |
| 31 | } |
| 32 | if err := lb.ValidatorSet.ValidateBasic(); err != nil { |
| 33 | return fmt.Errorf("invalid validator set: %w", err) |
| 34 | } |
| 35 | |
| 36 | // make sure the validator set is consistent with the header |
| 37 | if valSetHash := lb.ValidatorSet.Hash(); !bytes.Equal(lb.SignedHeader.ValidatorsHash, valSetHash) { |
| 38 | return fmt.Errorf("expected validator hash of header to match validator set hash (%X != %X)", |
| 39 | lb.SignedHeader.ValidatorsHash, valSetHash, |
| 40 | ) |
| 41 | } |
| 42 | |
| 43 | return nil |
| 44 | } |
| 45 | |
| 46 | // String returns a string representation of the LightBlock |
| 47 | func (lb LightBlock) String() string { |