-
Notifications
You must be signed in to change notification settings - Fork 198
/
spec.go
89 lines (71 loc) · 2.48 KB
/
spec.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
package types
import (
fmt "fmt"
"strconv"
epochstoragetypes "github.com/lavanet/lava/x/epochstorage/types"
)
const minCU = 1
func (spec Spec) ValidateSpec(maxCU uint64) (map[string]string, error) {
details := map[string]string{"spec": spec.Name, "status": strconv.FormatBool(spec.Enabled), "chainID": spec.Index}
functionTags := map[string]bool{}
availableAPIInterface := map[string]struct{}{
APIInterfaceJsonRPC: {},
APIInterfaceTendermintRPC: {},
APIInterfaceRest: {},
APIInterfaceGrpc: {},
}
if spec.ReliabilityThreshold == 0 {
return details, fmt.Errorf("ReliabilityThreshold can't be zero")
}
if spec.BlocksInFinalizationProof == 0 {
return details, fmt.Errorf("BlocksInFinalizationProof can't be zero")
}
if spec.AverageBlockTime <= 0 {
return details, fmt.Errorf("AverageBlockTime can't be zero")
}
if spec.AllowedBlockLagForQosSync <= 0 {
return details, fmt.Errorf("AllowedBlockLagForQosSync can't be zero")
}
if spec.MinStakeClient.Denom != epochstoragetypes.TokenDenom || spec.MinStakeClient.Amount.IsZero() {
return details, fmt.Errorf("MinStakeClient can't be zero andmust have denom of ulava")
}
if spec.MinStakeProvider.Denom != epochstoragetypes.TokenDenom || spec.MinStakeProvider.Amount.IsZero() {
return details, fmt.Errorf("MinStakeProvider can't be zero andmust have denom of ulava")
}
for _, api := range spec.Apis {
if api.ComputeUnits < minCU || api.ComputeUnits > maxCU {
details["api"] = api.Name
return details, fmt.Errorf("compute units out or range")
}
if len(api.ApiInterfaces) == 0 {
return details, fmt.Errorf("api interface list empty for %v", api.Name)
}
for _, apiInterface := range api.ApiInterfaces {
if _, ok := availableAPIInterface[apiInterface.Interface]; !ok {
return details, fmt.Errorf("unsupported api interface %v", apiInterface.Interface)
}
}
if api.Parsing.FunctionTag != "" {
// Validate tag name
result := false
for _, tag := range SupportedTags {
if tag == api.Parsing.FunctionTag {
result = true
functionTags[api.Parsing.FunctionTag] = true
}
}
if !result {
details["api"] = api.Name
return details, fmt.Errorf("unsupported function tag")
}
}
}
if spec.DataReliabilityEnabled && spec.Enabled {
for _, tag := range []string{GET_BLOCKNUM, GET_BLOCK_BY_NUM} {
if found := functionTags[tag]; !found {
return details, fmt.Errorf("missing tagged functions for hash comparison: %s", tag)
}
}
}
return details, nil
}