-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
50 lines (42 loc) · 1.29 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
package light
import (
"fmt"
)
// SampleAmount specifies the minimum required amount of samples a light node must perform
// before declaring that a block is available
var (
DefaultSampleAmount uint = 16
)
// Parameters is the set of Parameters that must be configured for the light
// availability implementation
type Parameters struct {
SampleAmount uint // The minimum required amount of samples to perform
}
// Option is a function that configures light availability Parameters
type Option func(*Parameters)
// DefaultParameters returns the default Parameters' configuration values
// for the light availability implementation
func DefaultParameters() Parameters {
return Parameters{
SampleAmount: DefaultSampleAmount,
}
}
// Validate validates the values in Parameters
func (p *Parameters) Validate() error {
if p.SampleAmount <= 0 {
return fmt.Errorf(
"light availability: invalid option: value %s was %s, where it should be %s",
"SampleAmount",
"<= 0", // current value
">= 0", // what the value should be
)
}
return nil
}
// WithSampleAmount is a functional option that the Availability interface
// implementers use to set the SampleAmount configuration param
func WithSampleAmount(sampleAmount uint) Option {
return func(p *Parameters) {
p.SampleAmount = sampleAmount
}
}