forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
185 lines (145 loc) · 7.54 KB
/
config.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package network
import (
"crypto"
"crypto/tls"
"time"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/dialer"
"github.com/ava-labs/avalanchego/network/peer"
"github.com/ava-labs/avalanchego/network/throttling"
"github.com/ava-labs/avalanchego/snow/networking/tracker"
"github.com/ava-labs/avalanchego/snow/uptime"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/compression"
"github.com/ava-labs/avalanchego/utils/ips"
"github.com/ava-labs/avalanchego/utils/set"
)
// HealthConfig describes parameters for network layer health checks.
type HealthConfig struct {
// Marks if the health check should be enabled
Enabled bool `json:"-"`
// MinConnectedPeers is the minimum number of peers that the network should
// be connected to to be considered healthy.
MinConnectedPeers uint `json:"minConnectedPeers"`
// MaxTimeSinceMsgReceived is the maximum amount of time since the network
// last received a message to be considered healthy.
MaxTimeSinceMsgReceived time.Duration `json:"maxTimeSinceMsgReceived"`
// MaxTimeSinceMsgSent is the maximum amount of time since the network last
// sent a message to be considered healthy.
MaxTimeSinceMsgSent time.Duration `json:"maxTimeSinceMsgSent"`
// MaxPortionSendQueueBytesFull is the maximum percentage of the pending
// send byte queue that should be used for the network to be considered
// healthy. Should be in (0,1].
MaxPortionSendQueueBytesFull float64 `json:"maxPortionSendQueueBytesFull"`
// MaxSendFailRate is the maximum percentage of send attempts that should be
// failing for the network to be considered healthy. This does not include
// send attempts that were not made due to benching. Should be in [0,1].
MaxSendFailRate float64 `json:"maxSendFailRate"`
// SendFailRateHalflife is the halflife of the averager used to calculate
// the send fail rate percentage. Should be > 0. Larger values mean that the
// fail rate is affected less by recently dropped messages.
SendFailRateHalflife time.Duration `json:"sendFailRateHalflife"`
}
type PeerListGossipConfig struct {
// PeerListNumValidatorIPs is the number of validator IPs to gossip in every
// gossip event.
PeerListNumValidatorIPs uint32 `json:"peerListNumValidatorIPs"`
// PeerListValidatorGossipSize is the number of validators to gossip the IPs
// to in every IP gossip event.
PeerListValidatorGossipSize uint32 `json:"peerListValidatorGossipSize"`
// PeerListNonValidatorGossipSize is the number of non-validators to gossip
// the IPs to in every IP gossip event.
PeerListNonValidatorGossipSize uint32 `json:"peerListNonValidatorGossipSize"`
// PeerListPeersGossipSize is the number of peers to gossip
// the IPs to in every IP gossip event.
PeerListPeersGossipSize uint32 `json:"peerListPeersGossipSize"`
// PeerListGossipFreq is the frequency that this node will attempt to gossip
// signed IPs to its peers.
PeerListGossipFreq time.Duration `json:"peerListGossipFreq"`
}
type TimeoutConfig struct {
// PingPongTimeout is the maximum amount of time to wait for a Pong response
// from a peer we sent a Ping to.
PingPongTimeout time.Duration `json:"pingPongTimeout"`
// ReadHandshakeTimeout is the maximum amount of time to wait for the peer's
// connection upgrade to finish before starting the p2p handshake.
ReadHandshakeTimeout time.Duration `json:"readHandshakeTimeout"`
}
type DelayConfig struct {
// InitialReconnectDelay is the minimum amount of time the node will delay a
// reconnection to a peer. This value is used to start the exponential
// backoff.
InitialReconnectDelay time.Duration `json:"initialReconnectDelay"`
// MaxReconnectDelay is the maximum amount of time the node will delay a
// reconnection to a peer.
MaxReconnectDelay time.Duration `json:"maxReconnectDelay"`
}
type ThrottlerConfig struct {
InboundConnUpgradeThrottlerConfig throttling.InboundConnUpgradeThrottlerConfig `json:"inboundConnUpgradeThrottlerConfig"`
InboundMsgThrottlerConfig throttling.InboundMsgThrottlerConfig `json:"inboundMsgThrottlerConfig"`
OutboundMsgThrottlerConfig throttling.MsgByteThrottlerConfig `json:"outboundMsgThrottlerConfig"`
MaxInboundConnsPerSec float64 `json:"maxInboundConnsPerSec"`
}
type Config struct {
HealthConfig `json:"healthConfig"`
PeerListGossipConfig `json:"peerListGossipConfig"`
TimeoutConfig `json:"timeoutConfigs"`
DelayConfig `json:"delayConfig"`
ThrottlerConfig ThrottlerConfig `json:"throttlerConfig"`
ProxyEnabled bool `json:"proxyEnabled"`
ProxyReadHeaderTimeout time.Duration `json:"proxyReadHeaderTimeout"`
DialerConfig dialer.Config `json:"dialerConfig"`
TLSConfig *tls.Config `json:"-"`
TLSKeyLogFile string `json:"tlsKeyLogFile"`
Namespace string `json:"namespace"`
MyNodeID ids.NodeID `json:"myNodeID"`
MyIPPort ips.DynamicIPPort `json:"myIP"`
NetworkID uint32 `json:"networkID"`
MaxClockDifference time.Duration `json:"maxClockDifference"`
PingFrequency time.Duration `json:"pingFrequency"`
AllowPrivateIPs bool `json:"allowPrivateIPs"`
// The compression type to use when compressing outbound messages.
// Assumes all peers support this compression type.
CompressionType compression.Type `json:"compressionType"`
// TLSKey is this node's TLS key that is used to sign IPs.
TLSKey crypto.Signer `json:"-"`
// TrackedSubnets of the node.
TrackedSubnets set.Set[ids.ID] `json:"-"`
Beacons validators.Set `json:"-"`
// Validators are the current validators in the Avalanche network
Validators validators.Manager `json:"-"`
UptimeCalculator uptime.Calculator `json:"-"`
// UptimeMetricFreq marks how frequently this node will recalculate the
// observed average uptime metrics.
UptimeMetricFreq time.Duration `json:"uptimeMetricFreq"`
// UptimeRequirement is the fraction of time a validator must be online and
// responsive for us to vote that they should receive a staking reward.
UptimeRequirement float64 `json:"-"`
// RequireValidatorToConnect require that all connections must have at least
// one validator between the 2 peers. This can be useful to enable if the
// node wants to connect to the minimum number of nodes without impacting
// the network negatively.
RequireValidatorToConnect bool `json:"requireValidatorToConnect"`
// MaximumInboundMessageTimeout is the maximum deadline duration in a
// message. Messages sent by clients setting values higher than this value
// will be reset to this value.
MaximumInboundMessageTimeout time.Duration `json:"maximumInboundMessageTimeout"`
// Size, in bytes, of the buffer that we read peer messages into
// (there is one buffer per peer)
PeerReadBufferSize int `json:"peerReadBufferSize"`
// Size, in bytes, of the buffer that we write peer messages into
// (there is one buffer per peer)
PeerWriteBufferSize int `json:"peerWriteBufferSize"`
// Tracks the CPU/disk usage caused by processing messages of each peer.
ResourceTracker tracker.ResourceTracker `json:"-"`
// Specifies how much CPU usage each peer can cause before
// we rate-limit them.
CPUTargeter tracker.Targeter `json:"-"`
// Specifies how much disk usage each peer can cause before
// we rate-limit them.
DiskTargeter tracker.Targeter `json:"-"`
// Tracks which validators have been sent to which peers
GossipTracker peer.GossipTracker `json:"-"`
}