-
Notifications
You must be signed in to change notification settings - Fork 893
/
options.go
84 lines (69 loc) · 2.67 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
package peers
import (
"fmt"
"time"
libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/share/p2p/shrexsub"
)
type Parameters struct {
// PoolValidationTimeout is the timeout used for validating incoming datahashes. Pools that have
// been created for datahashes from shrexsub that do not see this hash from headersub after this
// timeout will be garbage collected.
PoolValidationTimeout time.Duration
// PeerCooldown is the time a peer is put on cooldown after a ResultCooldownPeer.
PeerCooldown time.Duration
// GcInterval is the interval at which the manager will garbage collect unvalidated pools.
GcInterval time.Duration
// EnableBlackListing turns on blacklisting for misbehaved peers
EnableBlackListing bool
}
type Option func(*Manager) error
// Validate validates the values in Parameters
func (p *Parameters) Validate() error {
if p.PoolValidationTimeout <= 0 {
return fmt.Errorf("peer-manager: validation timeout must be positive")
}
if p.PeerCooldown <= 0 {
return fmt.Errorf("peer-manager: peer cooldown must be positive")
}
if p.GcInterval <= 0 {
return fmt.Errorf("peer-manager: garbage collection interval must be positive")
}
return nil
}
// DefaultParameters returns the default configuration values for the peer manager parameters
func DefaultParameters() Parameters {
return Parameters{
// PoolValidationTimeout's default value is based on the default daser sampling timeout of 1 minute.
// If a received datahash has not tried to be sampled within these two minutes, the pool will be
// removed.
PoolValidationTimeout: 2 * time.Minute,
// PeerCooldown's default value is based on initial network tests that showed a ~3.5 second
// sync time for large blocks. This value gives our (discovery) peers enough time to sync
// the new block before we ask them again.
PeerCooldown: 3 * time.Second,
GcInterval: time.Second * 30,
// blacklisting is off by default //TODO(@walldiss): enable blacklisting once all related issues
// are resolved
EnableBlackListing: false,
}
}
// WithShrexSubPools passes a shrexsub and headersub instance to be used to populate and validate
// pools from shrexsub notifications.
func WithShrexSubPools(shrexSub *shrexsub.PubSub, headerSub libhead.Subscriber[*header.ExtendedHeader]) Option {
return func(m *Manager) error {
m.shrexSub = shrexSub
m.headerSub = headerSub
return nil
}
}
// WithMetrics turns on metric collection in peer manager.
func (m *Manager) WithMetrics() error {
metrics, err := initMetrics(m)
if err != nil {
return fmt.Errorf("peer-manager: init metrics: %w", err)
}
m.metrics = metrics
return nil
}