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