github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/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  	// ErrUnknownEpochBoundary is a sentinel returned when a query is made for an
    26  	// epoch boundary which is unknown to this node.
    27  	//
    28  	// There are 2 cases where an epoch boundary can be unknown.
    29  	// Consider an epoch boundary between epoch N and epoch M=N+1.
    30  	// Let:
    31  	//   - n be the final block in epoch N
    32  	//   - m be the first block in epoch M
    33  	//   - r be this node's lowest known block
    34  	//   - f be this node's latest finalized block
    35  	//
    36  	// CASE 1: `r.Height > n.Height`
    37  	// The boundary occurred before this node's lowest known block
    38  	// Note that this includes the case where `r == m` (we know the first block
    39  	// of epoch M but not the final block of epoch N).
    40  	//
    41  	// CASE 2: `f.Height < m.Height`
    42  	// The boundary has not been finalized yet. Note that we may have finalized
    43  	// n but not m.
    44  	ErrUnknownEpochBoundary = fmt.Errorf("unknown epoch boundary for current chain state")
    45  
    46  	// ErrSealingSegmentBelowRootBlock is a sentinel error returned for queries
    47  	// for a sealing segment below the root block (local history cutoff).
    48  	ErrSealingSegmentBelowRootBlock = fmt.Errorf("cannot construct sealing segment beyond locally known history")
    49  
    50  	// ErrClusterNotFound is a sentinel error returns for queries for a cluster
    51  	ErrClusterNotFound = fmt.Errorf("could not find cluster")
    52  
    53  	// ErrMultipleSealsForSameHeight indicates that an (unordered) slice of seals
    54  	// contains two or more seals for the same block height (possibilities include
    55  	// duplicated seals or seals for different blocks at the same height).
    56  	ErrMultipleSealsForSameHeight = fmt.Errorf("multiple seals for same block height")
    57  
    58  	// ErrDiscontinuousSeals indicates that an (unordered) slice of seals skips at least one block height.
    59  	ErrDiscontinuousSeals = fmt.Errorf("seals have discontinuity, i.e. they skip some block heights")
    60  )
    61  
    62  type IdentityNotFoundError struct {
    63  	NodeID flow.Identifier
    64  }
    65  
    66  func (e IdentityNotFoundError) Error() string {
    67  	return fmt.Sprintf("identity not found (%x)", e.NodeID)
    68  }
    69  
    70  func IsIdentityNotFound(err error) bool {
    71  	var errIdentityNotFound IdentityNotFoundError
    72  	return errors.As(err, &errIdentityNotFound)
    73  }
    74  
    75  type InvalidBlockTimestampError struct {
    76  	error
    77  }
    78  
    79  func (e InvalidBlockTimestampError) Unwrap() error {
    80  	return e.error
    81  }
    82  
    83  func (e InvalidBlockTimestampError) Error() string {
    84  	return e.error.Error()
    85  }
    86  
    87  func IsInvalidBlockTimestampError(err error) bool {
    88  	var errInvalidTimestampError InvalidBlockTimestampError
    89  	return errors.As(err, &errInvalidTimestampError)
    90  }
    91  
    92  func NewInvalidBlockTimestamp(msg string, args ...interface{}) error {
    93  	return InvalidBlockTimestampError{
    94  		error: fmt.Errorf(msg, args...),
    95  	}
    96  }
    97  
    98  // InvalidServiceEventError indicates an invalid service event was processed.
    99  type InvalidServiceEventError struct {
   100  	error
   101  }
   102  
   103  func (e InvalidServiceEventError) Unwrap() error {
   104  	return e.error
   105  }
   106  
   107  func IsInvalidServiceEventError(err error) bool {
   108  	var errInvalidServiceEventError InvalidServiceEventError
   109  	return errors.As(err, &errInvalidServiceEventError)
   110  }
   111  
   112  // NewInvalidServiceEventErrorf returns an invalid service event error. Since all invalid
   113  // service events indicate an invalid extension, the service event error is wrapped in
   114  // the invalid extension error at construction.
   115  func NewInvalidServiceEventErrorf(msg string, args ...interface{}) error {
   116  	return state.NewInvalidExtensionErrorf(
   117  		"cannot extend state with invalid service event: %w",
   118  		InvalidServiceEventError{
   119  			error: fmt.Errorf(msg, args...),
   120  		},
   121  	)
   122  }
   123  
   124  // UnfinalizedSealingSegmentError indicates that including unfinalized blocks
   125  // in the sealing segment is illegal.
   126  type UnfinalizedSealingSegmentError struct {
   127  	error
   128  }
   129  
   130  func NewUnfinalizedSealingSegmentErrorf(msg string, args ...interface{}) error {
   131  	return UnfinalizedSealingSegmentError{
   132  		error: fmt.Errorf(msg, args...),
   133  	}
   134  }
   135  
   136  func (e UnfinalizedSealingSegmentError) Unwrap() error {
   137  	return e.error
   138  }
   139  
   140  func (e UnfinalizedSealingSegmentError) Error() string {
   141  	return e.error.Error()
   142  }
   143  
   144  // IsUnfinalizedSealingSegmentError returns true if err is of type UnfinalizedSealingSegmentError
   145  func IsUnfinalizedSealingSegmentError(err error) bool {
   146  	var e UnfinalizedSealingSegmentError
   147  	return errors.As(err, &e)
   148  }