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