-
Notifications
You must be signed in to change notification settings - Fork 178
/
epoch.go
111 lines (89 loc) · 2.78 KB
/
epoch.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
package invalid
import (
"errors"
"fmt"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state"
"github.com/onflow/flow-go/state/protocol"
)
// Epoch represents an epoch that does not exist or could not be retrieved.
type Epoch struct {
err error
}
// NewEpoch returns a new invalid epoch, containing an error describing why the
// epoch could not be retrieved. The following are expected errors when constructing
// an invalid Epoch:
// - protocol.ErrNoPreviousEpoch - if the epoch represents a previous epoch which does not exist.
// This happens when the previous epoch is queried within the first epoch of a spork.
// - protocol.ErrNextEpochNotSetup - if the epoch represents a next epoch which has not been set up.
// This happens when the next epoch is queried within the EpochStaking phase of any epoch.
// - state.ErrUnknownSnapshotReference - if the epoch is queried from an unresolvable snapshot.
// - generic error in case of unexpected critical internal corruption or bugs
func NewEpoch(err error) *Epoch {
if errors.Is(err, protocol.ErrNoPreviousEpoch) {
return &Epoch{err: err}
}
if errors.Is(err, protocol.ErrNextEpochNotSetup) {
return &Epoch{err: err}
}
if errors.Is(err, state.ErrUnknownSnapshotReference) {
return &Epoch{err: err}
}
return &Epoch{err: fmt.Errorf("critical unexpected error querying epoch: %w", err)}
}
// NewEpochf is NewEpoch with ergonomic error formatting.
func NewEpochf(msg string, args ...interface{}) *Epoch {
return NewEpoch(fmt.Errorf(msg, args...))
}
func (u *Epoch) Counter() (uint64, error) {
return 0, u.err
}
func (u *Epoch) FirstView() (uint64, error) {
return 0, u.err
}
func (u *Epoch) FinalView() (uint64, error) {
return 0, u.err
}
func (u *Epoch) DKGPhase1FinalView() (uint64, error) {
return 0, u.err
}
func (u *Epoch) DKGPhase2FinalView() (uint64, error) {
return 0, u.err
}
func (u *Epoch) DKGPhase3FinalView() (uint64, error) {
return 0, u.err
}
func (u *Epoch) InitialIdentities() (flow.IdentityList, error) {
return nil, u.err
}
func (u *Epoch) Clustering() (flow.ClusterList, error) {
return nil, u.err
}
func (u *Epoch) Cluster(uint) (protocol.Cluster, error) {
return nil, u.err
}
func (u *Epoch) ClusterByChainID(chainID flow.ChainID) (protocol.Cluster, error) {
return nil, u.err
}
func (u *Epoch) DKG() (protocol.DKG, error) {
return nil, u.err
}
func (u *Epoch) RandomSource() ([]byte, error) {
return nil, u.err
}
// Epochs is an epoch query for an invalid snapshot.
type Epochs struct {
err error
}
func (u *Snapshot) Epochs() protocol.EpochQuery {
return &Epochs{err: u.err}
}
func (u *Epochs) Current() protocol.Epoch {
return NewEpoch(u.err)
}
func (u *Epochs) Next() protocol.Epoch {
return NewEpoch(u.err)
}
func (u *Epochs) Previous() protocol.Epoch {
return NewEpoch(u.err)
}