github.com/DFWallet/tendermint-cosmos@v0.0.2/light/errors.go (about)

     1  package light
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"time"
     7  
     8  	"github.com/DFWallet/tendermint-cosmos/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  // ErrFailedHeaderCrossReferencing is returned when the detector was not able to cross reference the header
    44  // with any of the connected witnesses.
    45  var ErrFailedHeaderCrossReferencing = errors.New("all witnesses have either not responded, don't have the " +
    46  	" blocks or sent invalid blocks. You should look to change your witnesses" +
    47  	"  or review the light client's logs for more information")
    48  
    49  // ErrVerificationFailed means either sequential or skipping verification has
    50  // failed to verify from header #1 to header #2 due to some reason.
    51  type ErrVerificationFailed struct {
    52  	From   int64
    53  	To     int64
    54  	Reason error
    55  }
    56  
    57  // Unwrap returns underlying reason.
    58  func (e ErrVerificationFailed) Unwrap() error {
    59  	return e.Reason
    60  }
    61  
    62  func (e ErrVerificationFailed) Error() string {
    63  	return fmt.Sprintf("verify from #%d to #%d failed: %v", e.From, e.To, e.Reason)
    64  }
    65  
    66  // ErrLightClientAttack is returned when the light client has detected an attempt
    67  // to verify a false header and has sent the evidence to either a witness or primary.
    68  var ErrLightClientAttack = errors.New(`attempted attack detected.
    69  	Light client received valid conflicting header from witness.
    70  	Unable to verify header. Evidence has been sent to both providers.
    71  	Check logs for full evidence and trace`,
    72  )
    73  
    74  // ErrNoWitnesses means that there are not enough witnesses connected to
    75  // continue running the light client.
    76  var ErrNoWitnesses = errors.New("no witnesses connected. please reset light client")
    77  
    78  // ----------------------------- INTERNAL ERRORS ---------------------------------
    79  
    80  // ErrConflictingHeaders is thrown when two conflicting headers are discovered.
    81  type errConflictingHeaders struct {
    82  	Block        *types.LightBlock
    83  	WitnessIndex int
    84  }
    85  
    86  func (e errConflictingHeaders) Error() string {
    87  	return fmt.Sprintf(
    88  		"header hash (%X) from witness (%d) does not match primary",
    89  		e.Block.Hash(), e.WitnessIndex)
    90  }
    91  
    92  // errBadWitness is returned when the witness either does not respond or
    93  // responds with an invalid header.
    94  type errBadWitness struct {
    95  	Reason       error
    96  	WitnessIndex int
    97  }
    98  
    99  func (e errBadWitness) Error() string {
   100  	return fmt.Sprintf("Witness %d returned error: %s", e.WitnessIndex, e.Reason.Error())
   101  }
   102  
   103  var errNoDivergence = errors.New(
   104  	"sanity check failed: no divergence between the original trace and the provider's new trace",
   105  )