/
options.go
123 lines (100 loc) · 3.22 KB
/
options.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
package beacon
import (
"time"
"github.com/ethpandaops/beacon/pkg/human"
)
// Options holds the options for a beacon node.
type Options struct {
BeaconSubscription BeaconSubscriptionOptions
HealthCheck HealthCheckOptions
PrometheusMetrics bool
DetectEmptySlots bool
}
// EnablePrometheusMetrics enables Prometheus metrics.
func (o *Options) EnablePrometheusMetrics() *Options {
o.PrometheusMetrics = true
return o
}
// DisablePrometheusMetrics disables Prometheus metrics.
func (o *Options) DisablePrometheusMetrics() *Options {
o.PrometheusMetrics = false
return o
}
// EnableEmptySlotDetection enables empty slot detection.
func (o *Options) EnableEmptySlotDetection() *Options {
o.DetectEmptySlots = true
return o
}
// DisableEmptySlotDetection disables empty slot detection.
func (o *Options) DisableEmptySlotDetection() *Options {
o.DetectEmptySlots = false
return o
}
// DefaultOptions returns the default options.
func DefaultOptions() *Options {
return &Options{
BeaconSubscription: DefaultDisabledBeaconSubscriptionOptions(),
HealthCheck: DefaultHealthCheckOptions(),
PrometheusMetrics: true,
DetectEmptySlots: false,
}
}
// BeaconSubscriptionOptions holds the options for beacon subscription.
type BeaconSubscriptionOptions struct {
Enabled bool
Topics EventTopics
}
// Disable disables the beacon subscription.
func (b *BeaconSubscriptionOptions) Disable() *BeaconSubscriptionOptions {
b.Enabled = false
return b
}
// Enable enables the beacon subscription.
func (b *BeaconSubscriptionOptions) Enable() *BeaconSubscriptionOptions {
b.Enabled = true
return b
}
// DefaultDisabledBeaconSubscriptionOptions returns the default options for a disabled beacon subscription.
func DefaultDisabledBeaconSubscriptionOptions() BeaconSubscriptionOptions {
return BeaconSubscriptionOptions{
Enabled: false,
Topics: []string{},
}
}
// DefaultEnabledBeaconSubscriptionOptions returns the default options for an enabled beacon subscription.
func DefaultEnabledBeaconSubscriptionOptions() BeaconSubscriptionOptions {
return BeaconSubscriptionOptions{
Enabled: true,
Topics: []string{
topicAttestation,
topicBlock,
topicChainReorg,
topicFinalizedCheckpoint,
topicHead,
topicVoluntaryExit,
topicContributionAndProof,
},
}
}
// EnableDefaultBeaconSubscription enables the default beacon subscription.
func (o *Options) EnableDefaultBeaconSubscription() *Options {
o.BeaconSubscription = DefaultEnabledBeaconSubscriptionOptions()
return o
}
// HealthCheckOptions holds the options for the health check.
type HealthCheckOptions struct {
// Interval is the interval at which the health check will be run.
Interval human.Duration
// SuccessThreshold is the number of consecutive successful health checks required before the node is considered healthy.
SuccessfulResponses int
// FailureThreshold is the number of consecutive failed health checks required before the node is considered unhealthy.
FailedResponses int
}
// DefaultHealthCheckOptions returns the default health check options.
func DefaultHealthCheckOptions() HealthCheckOptions {
return HealthCheckOptions{
Interval: human.Duration{Duration: 15 * time.Second},
SuccessfulResponses: 3,
FailedResponses: 3,
}
}