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.

53 lines
1.6 KiB

  1. package lite
  2. import (
  3. "time"
  4. "github.com/pkg/errors"
  5. "github.com/tendermint/tendermint/crypto/tmhash"
  6. )
  7. // TrustOptions are the trust parameters needed when a new light client
  8. // connects to the network or when an existing light client that has been
  9. // offline for longer than the trusting period connects to the network.
  10. //
  11. // The expectation is the user will get this information from a trusted source
  12. // like a validator, a friend, or a secure website. A more user friendly
  13. // solution with trust tradeoffs is that we establish an https based protocol
  14. // with a default end point that populates this information. Also an on-chain
  15. // registry of roots-of-trust (e.g. on the Cosmos Hub) seems likely in the
  16. // future.
  17. type TrustOptions struct {
  18. // tp: trusting period.
  19. //
  20. // Should be significantly less than the unbonding period (e.g. unbonding
  21. // period = 3 weeks, trusting period = 2 weeks).
  22. //
  23. // More specifically, trusting period + time needed to check headers + time
  24. // needed to report and punish misbehavior should be less than the unbonding
  25. // period.
  26. Period time.Duration
  27. // Header's Height and Hash must both be provided to force the trusting of a
  28. // particular header.
  29. Height int64
  30. Hash []byte
  31. }
  32. // ValidateBasic performs basic validation.
  33. func (opts TrustOptions) ValidateBasic() error {
  34. if opts.Period <= 0 {
  35. return errors.New("negative or zero period")
  36. }
  37. if opts.Height <= 0 {
  38. return errors.New("negative or zero height")
  39. }
  40. if len(opts.Hash) != tmhash.Size {
  41. return errors.Errorf("expected hash size to be %d bytes, got %d bytes",
  42. tmhash.Size,
  43. len(opts.Hash),
  44. )
  45. }
  46. return nil
  47. }