github.com/adoriasoft/tendermint@v0.34.0-dev1.0.20200722151356-96d84601a75a/light/errors.go (about)

     1  package light
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/tendermint/tendermint/light/provider"
     8  	"github.com/tendermint/tendermint/types"
     9  )
    10  
    11  // ErrOldHeaderExpired means the old (trusted) header has expired according to
    12  // the given trustingPeriod and current time. If so, the light client must be
    13  // reset subjectively.
    14  type ErrOldHeaderExpired struct {
    15  	At  time.Time
    16  	Now time.Time
    17  }
    18  
    19  func (e ErrOldHeaderExpired) Error() string {
    20  	return fmt.Sprintf("old header has expired at %v (now: %v)", e.At, e.Now)
    21  }
    22  
    23  // ErrNewValSetCantBeTrusted means the new validator set cannot be trusted
    24  // because < 1/3rd (+trustLevel+) of the old validator set has signed.
    25  type ErrNewValSetCantBeTrusted struct {
    26  	Reason types.ErrNotEnoughVotingPowerSigned
    27  }
    28  
    29  func (e ErrNewValSetCantBeTrusted) Error() string {
    30  	return fmt.Sprintf("cant trust new val set: %v", e.Reason)
    31  }
    32  
    33  // ErrInvalidHeader means the header either failed the basic validation or
    34  // commit is not signed by 2/3+.
    35  type ErrInvalidHeader struct {
    36  	Reason error
    37  }
    38  
    39  func (e ErrInvalidHeader) Error() string {
    40  	return fmt.Sprintf("invalid header: %v", e.Reason)
    41  }
    42  
    43  // ErrConflictingHeaders is thrown when two conflicting headers are discovered.
    44  type ErrConflictingHeaders struct {
    45  	H1      *types.SignedHeader
    46  	Primary provider.Provider
    47  
    48  	H2      *types.SignedHeader
    49  	Witness provider.Provider
    50  }
    51  
    52  func (e ErrConflictingHeaders) Error() string {
    53  	return fmt.Sprintf(
    54  		"header hash %X from primary %v does not match one %X from witness %v",
    55  		e.H1.Hash(), e.Primary,
    56  		e.H2.Hash(), e.Witness)
    57  }
    58  
    59  // ErrVerificationFailed means either sequential or skipping verification has
    60  // failed to verify from header #1 to header #2 due to some reason.
    61  type ErrVerificationFailed struct {
    62  	From   int64
    63  	To     int64
    64  	Reason error
    65  }
    66  
    67  // Unwrap returns underlying reason.
    68  func (e ErrVerificationFailed) Unwrap() error {
    69  	return e.Reason
    70  }
    71  
    72  func (e ErrVerificationFailed) Error() string {
    73  	return fmt.Sprintf(
    74  		"verify from #%d to #%d failed: %v",
    75  		e.From, e.To, e.Reason)
    76  }
    77  
    78  // errNoWitnesses means that there are not enough witnesses connected to
    79  // continue running the light client.
    80  type errNoWitnesses struct{}
    81  
    82  func (e errNoWitnesses) Error() string {
    83  	return "no witnesses connected. please reset light client"
    84  }
    85  
    86  type badWitnessCode int
    87  
    88  const (
    89  	noResponse badWitnessCode = iota + 1
    90  	invalidHeader
    91  	invalidValidatorSet
    92  )
    93  
    94  // errBadWitness is returned when the witness either does not respond or
    95  // responds with an invalid header.
    96  type errBadWitness struct {
    97  	Reason       error
    98  	Code         badWitnessCode
    99  	WitnessIndex int
   100  }
   101  
   102  func (e errBadWitness) Error() string {
   103  	switch e.Code {
   104  	case noResponse:
   105  		return fmt.Sprintf("failed to get a header/vals from witness: %v", e.Reason)
   106  	case invalidHeader:
   107  		return fmt.Sprintf("witness sent us invalid header: %v", e.Reason)
   108  	case invalidValidatorSet:
   109  		return fmt.Sprintf("witness sent us invalid validator set: %v", e.Reason)
   110  	default:
   111  		return fmt.Sprintf("unknown code: %d", e.Code)
   112  	}
   113  }