-
Notifications
You must be signed in to change notification settings - Fork 179
/
params.go
131 lines (101 loc) · 3.18 KB
/
params.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
package badger
import (
"fmt"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/storage/badger/operation"
)
type Params struct {
state *State
}
var _ protocol.Params = (*Params)(nil)
func (p Params) ChainID() (flow.ChainID, error) {
// retrieve root header
root, err := p.FinalizedRoot()
if err != nil {
return "", fmt.Errorf("could not get root: %w", err)
}
return root.ChainID, nil
}
func (p Params) SporkID() (flow.Identifier, error) {
var sporkID flow.Identifier
err := p.state.db.View(operation.RetrieveSporkID(&sporkID))
if err != nil {
return flow.ZeroID, fmt.Errorf("could not get spork id: %w", err)
}
return sporkID, nil
}
func (p Params) SporkRootBlockHeight() (uint64, error) {
var sporkRootBlockHeight uint64
err := p.state.db.View(operation.RetrieveSporkRootBlockHeight(&sporkRootBlockHeight))
if err != nil {
return 0, fmt.Errorf("could not get spork root block height: %w", err)
}
return sporkRootBlockHeight, nil
}
func (p Params) ProtocolVersion() (uint, error) {
var version uint
err := p.state.db.View(operation.RetrieveProtocolVersion(&version))
if err != nil {
return 0, fmt.Errorf("could not get protocol version: %w", err)
}
return version, nil
}
func (p Params) EpochCommitSafetyThreshold() (uint64, error) {
var threshold uint64
err := p.state.db.View(operation.RetrieveEpochCommitSafetyThreshold(&threshold))
if err != nil {
return 0, fmt.Errorf("could not get epoch commit safety threshold")
}
return threshold, nil
}
func (p Params) EpochFallbackTriggered() (bool, error) {
var triggered bool
err := p.state.db.View(operation.CheckEpochEmergencyFallbackTriggered(&triggered))
if err != nil {
return false, fmt.Errorf("could not check epoch fallback triggered: %w", err)
}
return triggered, nil
}
func (p Params) FinalizedRoot() (*flow.Header, error) {
// look up root block ID
var rootID flow.Identifier
err := p.state.db.View(operation.LookupBlockHeight(p.state.finalizedRootHeight, &rootID))
if err != nil {
return nil, fmt.Errorf("could not look up root header: %w", err)
}
// retrieve root header
header, err := p.state.headers.ByBlockID(rootID)
if err != nil {
return nil, fmt.Errorf("could not retrieve root header: %w", err)
}
return header, nil
}
func (p Params) SealedRoot() (*flow.Header, error) {
// look up root block ID
var rootID flow.Identifier
err := p.state.db.View(operation.LookupBlockHeight(p.state.sealedRootHeight, &rootID))
if err != nil {
return nil, fmt.Errorf("could not look up root header: %w", err)
}
// retrieve root header
header, err := p.state.headers.ByBlockID(rootID)
if err != nil {
return nil, fmt.Errorf("could not retrieve root header: %w", err)
}
return header, nil
}
func (p Params) Seal() (*flow.Seal, error) {
// look up root header
var rootID flow.Identifier
err := p.state.db.View(operation.LookupBlockHeight(p.state.finalizedRootHeight, &rootID))
if err != nil {
return nil, fmt.Errorf("could not look up root header: %w", err)
}
// retrieve the root seal
seal, err := p.state.seals.HighestInFork(rootID)
if err != nil {
return nil, fmt.Errorf("could not retrieve root seal: %w", err)
}
return seal, nil
}