-
Notifications
You must be signed in to change notification settings - Fork 179
/
snapshot.go
85 lines (68 loc) · 2.17 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
82
83
84
85
package inmem
import (
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/state/protocol/seed"
)
var (
_ protocol.Snapshot = new(Snapshot)
_ protocol.EpochQuery = new(Epochs)
_ protocol.Epoch = new(Epoch)
_ protocol.Cluster = new(Cluster)
)
// Snapshot is a memory-backed implementation of protocol.Snapshot. The snapshot
// data is stored in the embedded encodable snapshot model, which defines the
// canonical structure of an encoded snapshot for the purposes of serialization.
type Snapshot struct {
enc EncodableSnapshot
}
func (s Snapshot) Head() (*flow.Header, error) {
return s.enc.Head, nil
}
func (s Snapshot) QuorumCertificate() (*flow.QuorumCertificate, error) {
return s.enc.QuorumCertificate, nil
}
func (s Snapshot) Identities(selector flow.IdentityFilter) (flow.IdentityList, error) {
return s.enc.Identities.Filter(selector), nil
}
func (s Snapshot) Identity(nodeID flow.Identifier) (*flow.Identity, error) {
identity, ok := s.enc.Identities.ByNodeID(nodeID)
if !ok {
return nil, protocol.IdentityNotFoundError{NodeID: nodeID}
}
return identity, nil
}
func (s Snapshot) Commit() (flow.StateCommitment, error) {
return s.enc.LatestSeal.FinalState, nil
}
func (s Snapshot) SealedResult() (*flow.ExecutionResult, *flow.Seal, error) {
return s.enc.LatestResult, s.enc.LatestSeal, nil
}
func (s Snapshot) SealingSegment() ([]*flow.Block, error) {
return s.enc.SealingSegment, nil
}
func (s Snapshot) Descendants() ([]flow.Identifier, error) {
// canonical snapshots don't have any descendants
return nil, nil
}
func (s Snapshot) ValidDescendants() ([]flow.Identifier, error) {
// canonical snapshots don't have any descendants
return nil, nil
}
func (s Snapshot) Phase() (flow.EpochPhase, error) {
return s.enc.Phase, nil
}
func (s Snapshot) Seed(indices ...uint32) ([]byte, error) {
return seed.FromParentSignature(indices, s.enc.QuorumCertificate.SigData)
}
func (s Snapshot) Epochs() protocol.EpochQuery {
return Epochs{s.enc.Epochs}
}
func (s Snapshot) Encodable() EncodableSnapshot {
return s.enc
}
func SnapshotFromEncodable(enc EncodableSnapshot) *Snapshot {
return &Snapshot{
enc: enc,
}
}