github.com/onflow/flow-go@v0.33.17/state/protocol/errors.go (about)

     1  package protocol
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/onflow/flow-go/model/flow"
     8  	"github.com/onflow/flow-go/state"
     9  )
    10  
    11  var (
    12  	// ErrNoPreviousEpoch is a sentinel error returned when a previous epoch is
    13  	// queried from a snapshot within the first epoch after the root block.
    14  	ErrNoPreviousEpoch = fmt.Errorf("no previous epoch exists")
    15  
    16  	// ErrNextEpochNotSetup is a sentinel error returned when the next epoch
    17  	// has not been set up yet.
    18  	ErrNextEpochNotSetup = fmt.Errorf("next epoch has not yet been set up")
    19  
    20  	// ErrNextEpochNotCommitted is a sentinel error returned when the next epoch
    21  	// has not been committed and information is queried that is only accessible
    22  	// in the EpochCommitted phase.
    23  	ErrNextEpochNotCommitted = fmt.Errorf("queried info from EpochCommit event before it was emitted")
    24  
    25  	// ErrEpochTransitionNotFinalized is a sentinel returned when a query is made
    26  	// for a block at an epoch boundary which has not yet been finalized.
    27  	ErrEpochTransitionNotFinalized = fmt.Errorf("cannot query block at un-finalized epoch transition")
    28  
    29  	// ErrSealingSegmentBelowRootBlock is a sentinel error returned for queries
    30  	// for a sealing segment below the root block (local history cutoff).
    31  	ErrSealingSegmentBelowRootBlock = fmt.Errorf("cannot construct sealing segment beyond locally known history")
    32  
    33  	// ErrClusterNotFound is a sentinel error returns for queries for a cluster
    34  	ErrClusterNotFound = fmt.Errorf("could not find cluster")
    35  
    36  	// ErrMultipleSealsForSameHeight indicates that an (unordered) slice of seals
    37  	// contains two or more seals for the same block height (possibilities include
    38  	// duplicated seals or seals for different blocks at the same height).
    39  	ErrMultipleSealsForSameHeight = fmt.Errorf("multiple seals for same block height")
    40  
    41  	// ErrDiscontinuousSeals indicates that an (unordered) slice of seals skips at least one block height.
    42  	ErrDiscontinuousSeals = fmt.Errorf("seals have discontinuity, i.e. they skip some block heights")
    43  )
    44  
    45  type IdentityNotFoundError struct {
    46  	NodeID flow.Identifier
    47  }
    48  
    49  func (e IdentityNotFoundError) Error() string {
    50  	return fmt.Sprintf("identity not found (%x)", e.NodeID)
    51  }
    52  
    53  func IsIdentityNotFound(err error) bool {
    54  	var errIdentityNotFound IdentityNotFoundError
    55  	return errors.As(err, &errIdentityNotFound)
    56  }
    57  
    58  type InvalidBlockTimestampError struct {
    59  	error
    60  }
    61  
    62  func (e InvalidBlockTimestampError) Unwrap() error {
    63  	return e.error
    64  }
    65  
    66  func (e InvalidBlockTimestampError) Error() string {
    67  	return e.error.Error()
    68  }
    69  
    70  func IsInvalidBlockTimestampError(err error) bool {
    71  	var errInvalidTimestampError InvalidBlockTimestampError
    72  	return errors.As(err, &errInvalidTimestampError)
    73  }
    74  
    75  func NewInvalidBlockTimestamp(msg string, args ...interface{}) error {
    76  	return InvalidBlockTimestampError{
    77  		error: fmt.Errorf(msg, args...),
    78  	}
    79  }
    80  
    81  // InvalidServiceEventError indicates an invalid service event was processed.
    82  type InvalidServiceEventError struct {
    83  	error
    84  }
    85  
    86  func (e InvalidServiceEventError) Unwrap() error {
    87  	return e.error
    88  }
    89  
    90  func IsInvalidServiceEventError(err error) bool {
    91  	var errInvalidServiceEventError InvalidServiceEventError
    92  	return errors.As(err, &errInvalidServiceEventError)
    93  }
    94  
    95  // NewInvalidServiceEventErrorf returns an invalid service event error. Since all invalid
    96  // service events indicate an invalid extension, the service event error is wrapped in
    97  // the invalid extension error at construction.
    98  func NewInvalidServiceEventErrorf(msg string, args ...interface{}) error {
    99  	return state.NewInvalidExtensionErrorf(
   100  		"cannot extend state with invalid service event: %w",
   101  		InvalidServiceEventError{
   102  			error: fmt.Errorf(msg, args...),
   103  		},
   104  	)
   105  }
   106  
   107  // UnfinalizedSealingSegmentError indicates that including unfinalized blocks
   108  // in the sealing segment is illegal.
   109  type UnfinalizedSealingSegmentError struct {
   110  	error
   111  }
   112  
   113  func NewUnfinalizedSealingSegmentErrorf(msg string, args ...interface{}) error {
   114  	return UnfinalizedSealingSegmentError{
   115  		error: fmt.Errorf(msg, args...),
   116  	}
   117  }
   118  
   119  func (e UnfinalizedSealingSegmentError) Unwrap() error {
   120  	return e.error
   121  }
   122  
   123  func (e UnfinalizedSealingSegmentError) Error() string {
   124  	return e.error.Error()
   125  }
   126  
   127  // IsUnfinalizedSealingSegmentError returns true if err is of type UnfinalizedSealingSegmentError
   128  func IsUnfinalizedSealingSegmentError(err error) bool {
   129  	var e UnfinalizedSealingSegmentError
   130  	return errors.As(err, &e)
   131  }