-
Notifications
You must be signed in to change notification settings - Fork 106
/
sanity_check.go
62 lines (52 loc) · 1.55 KB
/
sanity_check.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
package api
import (
"fmt"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
)
// SanityCheck does basic sanity checking on the genesis state.
func (g *Genesis) SanityCheck() error {
if err := g.Parameters.SanityCheck(); err != nil {
return fmt.Errorf("beacon: sanity check failed: %w", err)
}
if g.Base == EpochInvalid {
return fmt.Errorf("beacon: sanity check failed: starting epoch is invalid")
}
return nil
}
// SanityCheck performs a sanity check on the consensus parameters.
func (p *ConsensusParameters) SanityCheck() error {
switch p.Backend {
case BackendInsecure:
params := p.InsecureParameters
if params == nil {
return fmt.Errorf("insecure backend not configured")
}
if params.Interval <= 0 && !p.DebugMockBackend {
return fmt.Errorf("epoch interval must be > 0")
}
case BackendVRF:
params := p.VRFParameters
if params == nil {
return fmt.Errorf("VRF backend not configured")
}
if params.AlphaHighQualityThreshold == 0 {
return fmt.Errorf("alpha threshold must be > 0")
}
if params.Interval <= 0 {
return fmt.Errorf("epoch interval must be > 0")
}
if params.ProofSubmissionDelay <= 0 {
return fmt.Errorf("submission delay must be > 0")
}
if params.ProofSubmissionDelay >= params.Interval {
return fmt.Errorf("submission delay must be < epoch interval")
}
default:
return fmt.Errorf("unknown backend: '%s'", p.Backend)
}
unsafeFlags := p.DebugMockBackend
if unsafeFlags && !flags.DebugDontBlameOasis() {
return fmt.Errorf("one or more unsafe debug flags set")
}
return nil
}