github.com/MetalBlockchain/metalgo@v1.11.9/network/config.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package network 5 6 import ( 7 "crypto" 8 "crypto/tls" 9 "net/netip" 10 "time" 11 12 "github.com/MetalBlockchain/metalgo/ids" 13 "github.com/MetalBlockchain/metalgo/network/dialer" 14 "github.com/MetalBlockchain/metalgo/network/throttling" 15 "github.com/MetalBlockchain/metalgo/snow/networking/tracker" 16 "github.com/MetalBlockchain/metalgo/snow/uptime" 17 "github.com/MetalBlockchain/metalgo/snow/validators" 18 "github.com/MetalBlockchain/metalgo/utils" 19 "github.com/MetalBlockchain/metalgo/utils/compression" 20 "github.com/MetalBlockchain/metalgo/utils/crypto/bls" 21 "github.com/MetalBlockchain/metalgo/utils/set" 22 ) 23 24 // HealthConfig describes parameters for network layer health checks. 25 type HealthConfig struct { 26 // Marks if the health check should be enabled 27 Enabled bool `json:"-"` 28 29 // MinConnectedPeers is the minimum number of peers that the network should 30 // be connected to be considered healthy. 31 MinConnectedPeers uint `json:"minConnectedPeers"` 32 33 // MaxTimeSinceMsgReceived is the maximum amount of time since the network 34 // last received a message to be considered healthy. 35 MaxTimeSinceMsgReceived time.Duration `json:"maxTimeSinceMsgReceived"` 36 37 // MaxTimeSinceMsgSent is the maximum amount of time since the network last 38 // sent a message to be considered healthy. 39 MaxTimeSinceMsgSent time.Duration `json:"maxTimeSinceMsgSent"` 40 41 // MaxPortionSendQueueBytesFull is the maximum percentage of the pending 42 // send byte queue that should be used for the network to be considered 43 // healthy. Should be in (0,1]. 44 MaxPortionSendQueueBytesFull float64 `json:"maxPortionSendQueueBytesFull"` 45 46 // MaxSendFailRate is the maximum percentage of send attempts that should be 47 // failing for the network to be considered healthy. This does not include 48 // send attempts that were not made due to benching. Should be in [0,1]. 49 MaxSendFailRate float64 `json:"maxSendFailRate"` 50 51 // SendFailRateHalflife is the halflife of the averager used to calculate 52 // the send fail rate percentage. Should be > 0. Larger values mean that the 53 // fail rate is affected less by recently dropped messages. 54 SendFailRateHalflife time.Duration `json:"sendFailRateHalflife"` 55 } 56 57 type PeerListGossipConfig struct { 58 // PeerListNumValidatorIPs is the number of validator IPs to gossip in every 59 // gossip event. 60 PeerListNumValidatorIPs uint32 `json:"peerListNumValidatorIPs"` 61 62 // PeerListPullGossipFreq is the frequency that this node will attempt to 63 // request signed IPs from its peers. 64 PeerListPullGossipFreq time.Duration `json:"peerListPullGossipFreq"` 65 66 // PeerListBloomResetFreq is how frequently this node will recalculate the 67 // IP tracker's bloom filter. 68 PeerListBloomResetFreq time.Duration `json:"peerListBloomResetFreq"` 69 } 70 71 type TimeoutConfig struct { 72 // PingPongTimeout is the maximum amount of time to wait for a Pong response 73 // from a peer we sent a Ping to. 74 PingPongTimeout time.Duration `json:"pingPongTimeout"` 75 76 // ReadHandshakeTimeout is the maximum amount of time to wait for the peer's 77 // connection upgrade to finish before starting the p2p handshake. 78 ReadHandshakeTimeout time.Duration `json:"readHandshakeTimeout"` 79 } 80 81 type DelayConfig struct { 82 // InitialReconnectDelay is the minimum amount of time the node will delay a 83 // reconnection to a peer. This value is used to start the exponential 84 // backoff. 85 InitialReconnectDelay time.Duration `json:"initialReconnectDelay"` 86 87 // MaxReconnectDelay is the maximum amount of time the node will delay a 88 // reconnection to a peer. 89 MaxReconnectDelay time.Duration `json:"maxReconnectDelay"` 90 } 91 92 type ThrottlerConfig struct { 93 InboundConnUpgradeThrottlerConfig throttling.InboundConnUpgradeThrottlerConfig `json:"inboundConnUpgradeThrottlerConfig"` 94 InboundMsgThrottlerConfig throttling.InboundMsgThrottlerConfig `json:"inboundMsgThrottlerConfig"` 95 OutboundMsgThrottlerConfig throttling.MsgByteThrottlerConfig `json:"outboundMsgThrottlerConfig"` 96 MaxInboundConnsPerSec float64 `json:"maxInboundConnsPerSec"` 97 } 98 99 type Config struct { 100 HealthConfig `json:"healthConfig"` 101 PeerListGossipConfig `json:"peerListGossipConfig"` 102 TimeoutConfig `json:"timeoutConfigs"` 103 DelayConfig `json:"delayConfig"` 104 ThrottlerConfig ThrottlerConfig `json:"throttlerConfig"` 105 106 ProxyEnabled bool `json:"proxyEnabled"` 107 ProxyReadHeaderTimeout time.Duration `json:"proxyReadHeaderTimeout"` 108 109 DialerConfig dialer.Config `json:"dialerConfig"` 110 TLSConfig *tls.Config `json:"-"` 111 112 TLSKeyLogFile string `json:"tlsKeyLogFile"` 113 114 MyNodeID ids.NodeID `json:"myNodeID"` 115 MyIPPort *utils.Atomic[netip.AddrPort] `json:"myIP"` 116 NetworkID uint32 `json:"networkID"` 117 MaxClockDifference time.Duration `json:"maxClockDifference"` 118 PingFrequency time.Duration `json:"pingFrequency"` 119 AllowPrivateIPs bool `json:"allowPrivateIPs"` 120 121 SupportedACPs set.Set[uint32] `json:"supportedACPs"` 122 ObjectedACPs set.Set[uint32] `json:"objectedACPs"` 123 124 // The compression type to use when compressing outbound messages. 125 // Assumes all peers support this compression type. 126 CompressionType compression.Type `json:"compressionType"` 127 128 // TLSKey is this node's TLS key that is used to sign IPs. 129 TLSKey crypto.Signer `json:"-"` 130 // BLSKey is this node's BLS key that is used to sign IPs. 131 BLSKey *bls.SecretKey `json:"-"` 132 133 // TrackedSubnets of the node. 134 TrackedSubnets set.Set[ids.ID] `json:"-"` 135 Beacons validators.Manager `json:"-"` 136 137 // Validators are the current validators in the Avalanche network 138 Validators validators.Manager `json:"-"` 139 140 UptimeCalculator uptime.Calculator `json:"-"` 141 142 // UptimeMetricFreq marks how frequently this node will recalculate the 143 // observed average uptime metrics. 144 UptimeMetricFreq time.Duration `json:"uptimeMetricFreq"` 145 146 // UptimeRequirement is the fraction of time a validator must be online and 147 // responsive for us to vote that they should receive a staking reward. 148 UptimeRequirement float64 `json:"-"` 149 150 // RequireValidatorToConnect require that all connections must have at least 151 // one validator between the 2 peers. This can be useful to enable if the 152 // node wants to connect to the minimum number of nodes without impacting 153 // the network negatively. 154 RequireValidatorToConnect bool `json:"requireValidatorToConnect"` 155 156 // MaximumInboundMessageTimeout is the maximum deadline duration in a 157 // message. Messages sent by clients setting values higher than this value 158 // will be reset to this value. 159 MaximumInboundMessageTimeout time.Duration `json:"maximumInboundMessageTimeout"` 160 161 // Size, in bytes, of the buffer that we read peer messages into 162 // (there is one buffer per peer) 163 PeerReadBufferSize int `json:"peerReadBufferSize"` 164 165 // Size, in bytes, of the buffer that we write peer messages into 166 // (there is one buffer per peer) 167 PeerWriteBufferSize int `json:"peerWriteBufferSize"` 168 169 // Tracks the CPU/disk usage caused by processing messages of each peer. 170 ResourceTracker tracker.ResourceTracker `json:"-"` 171 172 // Specifies how much CPU usage each peer can cause before 173 // we rate-limit them. 174 CPUTargeter tracker.Targeter `json:"-"` 175 176 // Specifies how much disk usage each peer can cause before 177 // we rate-limit them. 178 DiskTargeter tracker.Targeter `json:"-"` 179 }