github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/state/errors.go (about) 1 package state 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 var ( 9 // ErrUnknownSnapshotReference indicates that the reference point for a queried 10 // snapshot cannot be resolved. The reference point is either a height above the 11 // finalized boundary, or a block ID that does not exist in the state. 12 ErrUnknownSnapshotReference = errors.New("reference block of the snapshot is not resolvable") 13 ) 14 15 // InvalidExtensionError is an error for invalid extension of the state. An invalid 16 // extension is distinct from outdated or unverifiable extensions, in that it indicates 17 // a malicious input. 18 type InvalidExtensionError struct { 19 error 20 } 21 22 func NewInvalidExtensionError(msg string) error { 23 return NewInvalidExtensionErrorf(msg) 24 } 25 26 func NewInvalidExtensionErrorf(msg string, args ...interface{}) error { 27 return InvalidExtensionError{ 28 error: fmt.Errorf(msg, args...), 29 } 30 } 31 32 func (e InvalidExtensionError) Unwrap() error { 33 return e.error 34 } 35 36 // IsInvalidExtensionError returns whether the given error is an InvalidExtensionError error 37 func IsInvalidExtensionError(err error) bool { 38 return errors.As(err, &InvalidExtensionError{}) 39 } 40 41 // OutdatedExtensionError is an error for the extension of the state being outdated. 42 // Being outdated doesn't mean it's invalid or not. 43 // Knowing whether an outdated extension is an invalid extension or not would 44 // take more state queries. 45 type OutdatedExtensionError struct { 46 error 47 } 48 49 func NewOutdatedExtensionError(msg string) error { 50 return NewOutdatedExtensionErrorf(msg) 51 } 52 53 func NewOutdatedExtensionErrorf(msg string, args ...interface{}) error { 54 return OutdatedExtensionError{ 55 error: fmt.Errorf(msg, args...), 56 } 57 } 58 59 func (e OutdatedExtensionError) Unwrap() error { 60 return e.error 61 } 62 63 func IsOutdatedExtensionError(err error) bool { 64 return errors.As(err, &OutdatedExtensionError{}) 65 } 66 67 // UnverifiableExtensionError represents a state extension (block) which cannot be 68 // verified at the moment. For example, it does not connect to the finalized state, 69 // or an entity referenced within the payload is unknown. 70 // Unlike InvalidExtensionError, this error is only used when the failure CANNOT be 71 // attributed to a malicious input, therefore this error can be treated as a benign failure. 72 type UnverifiableExtensionError struct { 73 error 74 } 75 76 func NewUnverifiableExtensionError(msg string, args ...interface{}) error { 77 return UnverifiableExtensionError{ 78 error: fmt.Errorf(msg, args...), 79 } 80 } 81 82 func (e UnverifiableExtensionError) Unwrap() error { 83 return e.error 84 } 85 86 func IsUnverifiableExtensionError(err error) bool { 87 var errUnverifiableExtensionError UnverifiableExtensionError 88 return errors.As(err, &errUnverifiableExtensionError) 89 }