github.com/koko1123/flow-go-1@v0.29.6/state/errors.go (about) 1 package state 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/koko1123/flow-go-1/model/flow" 8 ) 9 10 var ( 11 // ErrUnknownSnapshotReference indicates that the reference point for a queried 12 // snapshot cannot be resolved. The reference point is either a height above the 13 // finalized boundary, or a block ID that does not exist in the state. 14 ErrUnknownSnapshotReference = errors.New("reference block of the snapshot is not resolvable") 15 ) 16 17 // InvalidExtensionError is an error for invalid extension of the state. An invalid 18 // extension is distinct from outdated or unverifiable extensions, in that it indicates 19 // a malicious input. 20 type InvalidExtensionError struct { 21 error 22 } 23 24 func NewInvalidExtensionError(msg string) error { 25 return NewInvalidExtensionErrorf(msg) 26 } 27 28 func NewInvalidExtensionErrorf(msg string, args ...interface{}) error { 29 return InvalidExtensionError{ 30 error: fmt.Errorf(msg, args...), 31 } 32 } 33 34 func (e InvalidExtensionError) Unwrap() error { 35 return e.error 36 } 37 38 // IsInvalidExtensionError returns whether the given error is an InvalidExtensionError error 39 func IsInvalidExtensionError(err error) bool { 40 return errors.As(err, &InvalidExtensionError{}) 41 } 42 43 // OutdatedExtensionError is an error for the extension of the state being outdated. 44 // Being outdated doesn't mean it's invalid or not. 45 // Knowing whether an outdated extension is an invalid extension or not would 46 // take more state queries. 47 type OutdatedExtensionError struct { 48 error 49 } 50 51 func NewOutdatedExtensionError(msg string) error { 52 return NewOutdatedExtensionErrorf(msg) 53 } 54 55 func NewOutdatedExtensionErrorf(msg string, args ...interface{}) error { 56 return OutdatedExtensionError{ 57 error: fmt.Errorf(msg, args...), 58 } 59 } 60 61 func (e OutdatedExtensionError) Unwrap() error { 62 return e.error 63 } 64 65 func IsOutdatedExtensionError(err error) bool { 66 return errors.As(err, &OutdatedExtensionError{}) 67 } 68 69 // UnverifiableExtensionError represents a state extension (block) which cannot be 70 // verified at the moment. For example, it does not connect to the finalized state, 71 // or an entity referenced within the payload is unknown. 72 // Unlike InvalidExtensionError, this error is only used when the failure CANNOT be 73 // attributed to a malicious input, therefore this error can be treated as a benign failure. 74 type UnverifiableExtensionError struct { 75 error 76 } 77 78 func NewUnverifiableExtensionError(msg string, args ...interface{}) error { 79 return UnverifiableExtensionError{ 80 error: fmt.Errorf(msg, args...), 81 } 82 } 83 84 func (e UnverifiableExtensionError) Unwrap() error { 85 return e.error 86 } 87 88 func IsUnverifiableExtensionError(err error) bool { 89 var errUnverifiableExtensionError UnverifiableExtensionError 90 return errors.As(err, &errUnverifiableExtensionError) 91 } 92 93 // NoValidChildBlockError is a sentinel error when the case where a certain block has 94 // no valid child. 95 type NoValidChildBlockError struct { 96 error 97 } 98 99 func NewNoValidChildBlockError(msg string) error { 100 return NoValidChildBlockError{ 101 error: fmt.Errorf(msg), 102 } 103 } 104 105 func NewNoValidChildBlockErrorf(msg string, args ...interface{}) error { 106 return NewNoValidChildBlockError(fmt.Sprintf(msg, args...)) 107 } 108 109 func (e NoValidChildBlockError) Unwrap() error { 110 return e.error 111 } 112 113 func IsNoValidChildBlockError(err error) bool { 114 return errors.As(err, &NoValidChildBlockError{}) 115 } 116 117 // UnknownBlockError is a sentinel error indicating that a certain block 118 // has not been ingested yet. 119 type UnknownBlockError struct { 120 blockID flow.Identifier 121 error 122 } 123 124 // WrapAsUnknownBlockError wraps a given error as UnknownBlockError 125 func WrapAsUnknownBlockError(blockID flow.Identifier, err error) error { 126 return UnknownBlockError{ 127 blockID: blockID, 128 error: fmt.Errorf("block %v has not been processed yet: %w", blockID, err), 129 } 130 } 131 132 func NewUnknownBlockError(blockID flow.Identifier) error { 133 return UnknownBlockError{ 134 blockID: blockID, 135 error: fmt.Errorf("block %v has not been processed yet", blockID), 136 } 137 } 138 139 func (e UnknownBlockError) Unwrap() error { return e.error } 140 141 func IsUnknownBlockError(err error) bool { 142 var e UnknownBlockError 143 return errors.As(err, &e) 144 }