-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.go
371 lines (327 loc) · 7.94 KB
/
types.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package main
import (
"fmt"
"io/ioutil"
"math/big"
"os"
"strconv"
"strings"
"sync"
"github.com/ethereum/go-ethereum/common/hexutil"
"gopkg.in/yaml.v2"
)
type VerificationOutcome struct {
Success bool
Message string
}
type Verification struct {
VerificationName string `yaml:"VerificationName"`
ClientLayer ClientLayer `yaml:"ClientLayer"`
PostMerge bool `yaml:"PostMerge"`
MetricName MetricName `yaml:"MetricName"`
AggregateFunction AggregateFunction `yaml:"AggregateFunction"`
AggregateFunctionValue InputValue `yaml:"AggregateFunctionValue"`
PassCriteria PassCriteria `yaml:"PassCriteria"`
PassValue InputValue `yaml:"PassValue"`
}
type Verifications []Verification
type VerificationProbe struct {
Verification *Verification
AllProbesClient *VerificationProbes
Client Client
IsSyncing bool
CurrentOutcome VerificationOutcome
CurrentOutcomeLock sync.Mutex
PreviousDataPointSlotBlock uint64
DataPointsPerSlotBlock DataPoints
}
type VerificationProbes []*VerificationProbe
func (vs *Verifications) Set(filePath string) error {
yamlFile, err := os.Open(filePath)
if err != nil {
return err
}
bVal, _ := ioutil.ReadAll(yamlFile)
var newVerifications Verifications
if err := yaml.Unmarshal(bVal, &newVerifications); err != nil {
return err
}
*vs = append(*vs, newVerifications...)
return nil
}
func (vs *Verifications) String() string {
names := make([]string, 0)
for _, v := range *vs {
names = append(names, v.VerificationName)
}
return strings.Join(names, ",")
}
type ClientType uint64
const (
Geth ClientType = iota
Nethermind
Besu
Erigon
GenericExecutionClient
Lodestar
Nimbus
Teku
Prysm
Lighthouse
GenericBeaconClient
)
var ClientTypeNames = map[string]ClientType{
// Execution Types
"Geth": Geth,
"Nethermind": Nethermind,
"Besu": Besu,
"Erigon": Erigon,
"Execution": GenericExecutionClient,
"Lodestar": Lodestar,
"Nimbus": Nimbus,
"Teku": Teku,
"Prysm": Prysm,
"Lighthouse": Lighthouse,
"Beacon": GenericBeaconClient,
}
func (c ClientType) String() string {
for k, v := range ClientTypeNames {
if v == c {
return k
}
}
return ""
}
func ParseClientTypeString(str string) (ClientType, bool) {
strLower := strings.ToLower(str)
for k, v := range ClientTypeNames {
if strings.ToLower(k) == strLower {
return v, true
}
}
return Geth, false
}
type ClientLayer uint64
const (
Execution ClientLayer = iota
Beacon
)
func (l *ClientLayer) UnmarshalText(input []byte) error {
s := string(input)
if s == "Execution" {
*l = Execution
return nil
} else if s == "Beacon" {
*l = Beacon
return nil
}
return fmt.Errorf("invalid layer type: %s", s)
}
var ClientTypeToLayer = map[ClientType]ClientLayer{
Geth: Execution,
Nethermind: Execution,
Besu: Execution,
Erigon: Execution,
GenericExecutionClient: Execution,
Lodestar: Beacon,
Nimbus: Beacon,
Teku: Beacon,
Prysm: Beacon,
Lighthouse: Beacon,
GenericBeaconClient: Beacon,
}
type MetricName uint64
const (
// Execution Types
ExecutionBlockCount MetricName = iota
ExecutionBaseFee
ExecutionGasUsed
ExecutionDifficulty
ExecutionMixHash
ExecutionUnclesHash
ExecutionNonce
// Beacon Types
BeaconBlockCount
FinalizedEpoch
JustifiedEpoch
SlotAttestations
SlotAttestationsPercentage
EpochAttestationPerformance
EpochTargetAttestationPerformance
SyncParticipationCount
SyncParticipationPercentage
)
var MetricClientTypeRequirements = map[MetricName][]ClientType{
EpochAttestationPerformance: {
// This metric requires validator_inclusion API from lighthouse
Lighthouse,
},
EpochTargetAttestationPerformance: {
// This metric requires validator_inclusion API from lighthouse
Lighthouse,
},
}
var MetricNames = map[string]MetricName{
// Execution Types
"ExecutionBlockCount": ExecutionBlockCount,
"ExecutionBaseFee": ExecutionBaseFee,
"ExecutionGasUsed": ExecutionGasUsed,
"ExecutionDifficulty": ExecutionDifficulty,
"ExecutionMixHash": ExecutionMixHash,
"ExecutionUnclesHash": ExecutionUnclesHash,
"ExecutionNonce": ExecutionNonce,
// Beacon Types
"BeaconBlockCount": BeaconBlockCount,
"FinalizedEpoch": FinalizedEpoch,
"JustifiedEpoch": JustifiedEpoch,
"SlotAttestations": SlotAttestations,
"SlotAttestationsPercentage": SlotAttestationsPercentage,
"EpochAttestationPerformance": EpochAttestationPerformance,
"EpochTargetAttestationPerformance": EpochTargetAttestationPerformance,
"SyncParticipationCount": SyncParticipationCount,
"SyncParticipationPercentage": SyncParticipationPercentage,
}
func (dn *MetricName) UnmarshalText(input []byte) error {
s := string(input)
v, ok := MetricNames[s]
if !ok {
return fmt.Errorf("invalid data type: %s", s)
}
*dn = v
return nil
}
func (dn MetricName) String() string {
for k, v := range MetricNames {
if dn == v {
return k
}
}
return ""
}
type DataType uint64
const (
Uint64 DataType = iota
BigInt
)
var DataTypesPerLayer = map[ClientLayer]map[MetricName]DataType{
Execution: {
ExecutionBlockCount: Uint64,
ExecutionBaseFee: BigInt,
ExecutionGasUsed: Uint64,
ExecutionDifficulty: BigInt,
ExecutionMixHash: BigInt,
ExecutionUnclesHash: BigInt,
ExecutionNonce: Uint64,
},
Beacon: {
BeaconBlockCount: Uint64,
FinalizedEpoch: Uint64,
JustifiedEpoch: Uint64,
SlotAttestations: Uint64,
SlotAttestationsPercentage: Uint64,
EpochAttestationPerformance: Uint64,
EpochTargetAttestationPerformance: Uint64,
SyncParticipationCount: Uint64,
SyncParticipationPercentage: Uint64,
},
}
type AggregateFunction uint64
const (
Count AggregateFunction = iota
CountUnequal
CountEqual
Average
Sum
Percentage
Min
Max
)
var AggregateFunctions = map[string]AggregateFunction{
"Count": Count,
"CountUnequal": CountUnequal,
"CountEqual": CountEqual,
"Average": Average,
"Sum": Sum,
"Percentage": Percentage,
"Min": Min,
"Max": Max,
}
func (af *AggregateFunction) UnmarshalText(input []byte) error {
s := string(input)
v, ok := AggregateFunctions[s]
if !ok {
return fmt.Errorf("invalid aggregate function: %s", s)
}
*af = v
return nil
}
func (af AggregateFunction) String() string {
for k, v := range AggregateFunctions {
if af == v {
return k
}
}
return ""
}
type PassCriteria uint64
const (
MinimumValue PassCriteria = iota
MaximumValue
)
var PassCriterias = map[string]PassCriteria{
"MinimumValue": MinimumValue,
"MaximumValue": MaximumValue,
}
func (pc *PassCriteria) UnmarshalText(input []byte) error {
s := string(input)
v, ok := PassCriterias[s]
if !ok {
return fmt.Errorf("invalid aggregate function: %s", s)
}
*pc = v
return nil
}
func (pc PassCriteria) String() string {
for k, v := range PassCriterias {
if pc == v {
return k
}
}
return ""
}
type InputValue string
func (v InputValue) ToBigInt() (*big.Int, error) {
var err error
n := new(big.Int)
vs := string(v)
if len(vs) >= 2 && vs[0:2] == "0x" {
n, err = hexutil.DecodeBig(vs)
if err != nil {
return nil, err
}
} else {
var ok bool
n, ok = n.SetString(vs, 10)
if !ok {
return nil, fmt.Errorf("invalid value for bigInt: %s", vs)
}
}
return n, nil
}
func (v InputValue) ToUint64() (uint64, error) {
var err error
var n uint64
vs := string(v)
if len(vs) >= 2 && vs[0:2] == "0x" {
n, err = hexutil.DecodeUint64(vs)
if err != nil {
return 0, err
}
} else {
n, err = strconv.ParseUint(vs, 10, 64)
if err != nil {
return 0, fmt.Errorf("invalid value for Uint64: %s", vs)
}
}
return n, nil
}