-
Notifications
You must be signed in to change notification settings - Fork 175
/
snapshot.go
81 lines (64 loc) · 2.13 KB
/
snapshot.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
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"
)
// Snapshot represents a snapshot that does not exist or could not be queried.
type Snapshot struct {
err error
}
// NewSnapshot returns a new invalid snapshot, containing an error describing why the
// snapshot could not be retrieved. The following are expected
// errors when constructing an invalid Snapshot:
// - state.ErrUnknownSnapshotReference if the reference point for the snapshot
// (height or block ID) does not resolve to a queriable block in the state.
// - generic error in case of unexpected critical internal corruption or bugs
func NewSnapshot(err error) *Snapshot {
if errors.Is(err, state.ErrUnknownSnapshotReference) {
return &Snapshot{err: err}
}
return &Snapshot{fmt.Errorf("critical unexpected error querying snapshot: %w", err)}
}
// NewSnapshotf is NewSnapshot with ergonomic error formatting.
func NewSnapshotf(msg string, args ...interface{}) *Snapshot {
return NewSnapshot(fmt.Errorf(msg, args...))
}
func (u *Snapshot) Head() (*flow.Header, error) {
return nil, u.err
}
func (u *Snapshot) QuorumCertificate() (*flow.QuorumCertificate, error) {
return nil, u.err
}
func (u *Snapshot) Phase() (flow.EpochPhase, error) {
return 0, u.err
}
func (u *Snapshot) Identities(_ flow.IdentityFilter) (flow.IdentityList, error) {
return nil, u.err
}
func (u *Snapshot) Identity(_ flow.Identifier) (*flow.Identity, error) {
return nil, u.err
}
func (u *Snapshot) Commit() (flow.StateCommitment, error) {
return flow.DummyStateCommitment, u.err
}
func (u *Snapshot) SealedResult() (*flow.ExecutionResult, *flow.Seal, error) {
return nil, nil, u.err
}
func (u *Snapshot) SealingSegment() (*flow.SealingSegment, error) {
return nil, u.err
}
func (u *Snapshot) Descendants() ([]flow.Identifier, error) {
return nil, u.err
}
func (u *Snapshot) ValidDescendants() ([]flow.Identifier, error) {
return nil, u.err
}
func (u *Snapshot) RandomSource() ([]byte, error) {
return nil, u.err
}
func (u *Snapshot) Params() protocol.GlobalParams {
return &Params{u.err}
}