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.

92 lines
2.6 KiB

  1. package errors
  2. import (
  3. "fmt"
  4. "github.com/pkg/errors"
  5. )
  6. var (
  7. errValidatorsChanged = fmt.Errorf("Validators differ between header and certifier")
  8. errCommitNotFound = fmt.Errorf("Commit not found by provider")
  9. errTooMuchChange = fmt.Errorf("Validators change too much to safely update")
  10. errPastTime = fmt.Errorf("Update older than certifier height")
  11. errNoPathFound = fmt.Errorf("Cannot find a path of validators")
  12. )
  13. // IsCommitNotFoundErr checks whether an error is due to missing data
  14. func IsCommitNotFoundErr(err error) bool {
  15. return err != nil && (errors.Cause(err) == errCommitNotFound)
  16. }
  17. // ErrCommitNotFound indicates that a the requested commit was not found.
  18. func ErrCommitNotFound() error {
  19. return errors.WithStack(errCommitNotFound)
  20. }
  21. // IsValidatorsChangedErr checks whether an error is due
  22. // to a differing validator set.
  23. func IsValidatorsChangedErr(err error) bool {
  24. return err != nil && (errors.Cause(err) == errValidatorsChanged)
  25. }
  26. // ErrValidatorsChanged indicates that the validator set was changed between two commits.
  27. func ErrValidatorsChanged() error {
  28. return errors.WithStack(errValidatorsChanged)
  29. }
  30. // IsTooMuchChangeErr checks whether an error is due to too much change
  31. // between these validators sets.
  32. func IsTooMuchChangeErr(err error) bool {
  33. return err != nil && (errors.Cause(err) == errTooMuchChange)
  34. }
  35. // ErrTooMuchChange indicates that the underlying validator set was changed by >1/3.
  36. func ErrTooMuchChange() error {
  37. return errors.WithStack(errTooMuchChange)
  38. }
  39. // IsPastTimeErr ...
  40. func IsPastTimeErr(err error) bool {
  41. return err != nil && (errors.Cause(err) == errPastTime)
  42. }
  43. // ErrPastTime ...
  44. func ErrPastTime() error {
  45. return errors.WithStack(errPastTime)
  46. }
  47. // IsNoPathFoundErr checks whether an error is due to no path of
  48. // validators in provider from where we are to where we want to be
  49. func IsNoPathFoundErr(err error) bool {
  50. return err != nil && (errors.Cause(err) == errNoPathFound)
  51. }
  52. // ErrNoPathFound ...
  53. func ErrNoPathFound() error {
  54. return errors.WithStack(errNoPathFound)
  55. }
  56. //--------------------------------------------
  57. type errHeightMismatch struct {
  58. h1, h2 int
  59. }
  60. func (e errHeightMismatch) Error() string {
  61. return fmt.Sprintf("Blocks don't match - %d vs %d", e.h1, e.h2)
  62. }
  63. // IsHeightMismatchErr checks whether an error is due to data from different blocks
  64. func IsHeightMismatchErr(err error) bool {
  65. if err == nil {
  66. return false
  67. }
  68. _, ok := errors.Cause(err).(errHeightMismatch)
  69. return ok
  70. }
  71. // ErrHeightMismatch returns an mismatch error with stack-trace
  72. func ErrHeightMismatch(h1, h2 int) error {
  73. return errors.WithStack(errHeightMismatch{h1, h2})
  74. }