Skip to content

Commit

Permalink
Merge branch 'dev' into sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
hexfusion authored Jul 31, 2023
2 parents 8ef9f6c + c7ec186 commit 2d4e09d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
22 changes: 14 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func getGossipConfig(v *viper.Viper) subnets.GossipConfig {

func getNetworkConfig(
v *viper.Viper,
networkID uint32,
sybilProtectionEnabled bool,
halflife time.Duration,
) (network.Config, error) {
Expand All @@ -313,16 +314,16 @@ func getNetworkConfig(
upgradeCooldownInSeconds := upgradeCooldown.Seconds()
maxRecentConnsUpgraded := int(math.Ceil(maxInboundConnsPerSec * upgradeCooldownInSeconds))

var (
compressionType compression.Type
err error
)

compressionType, err = compression.TypeFromString(v.GetString(NetworkCompressionTypeKey))
compressionType, err := compression.TypeFromString(v.GetString(NetworkCompressionTypeKey))
if err != nil {
return network.Config{}, err
}

allowPrivateIPs := !constants.ProductionNetworkIDs.Contains(networkID)
if v.IsSet(NetworkAllowPrivateIPsKey) {
allowPrivateIPs = v.GetBool(NetworkAllowPrivateIPsKey)
}

config := network.Config{
ThrottlerConfig: network.ThrottlerConfig{
MaxInboundConnsPerSec: maxInboundConnsPerSec,
Expand Down Expand Up @@ -398,7 +399,7 @@ func getNetworkConfig(
MaxClockDifference: v.GetDuration(NetworkMaxClockDifferenceKey),
CompressionType: compressionType,
PingFrequency: v.GetDuration(NetworkPingFrequencyKey),
AllowPrivateIPs: v.GetBool(NetworkAllowPrivateIPsKey),
AllowPrivateIPs: allowPrivateIPs,
UptimeMetricFreq: v.GetDuration(UptimeMetricFreqKey),
MaximumInboundMessageTimeout: v.GetDuration(NetworkMaximumInboundTimeoutKey),

Expand Down Expand Up @@ -1371,7 +1372,12 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
}

// Network Config
nodeConfig.NetworkConfig, err = getNetworkConfig(v, nodeConfig.SybilProtectionEnabled, healthCheckAveragerHalflife)
nodeConfig.NetworkConfig, err = getNetworkConfig(
v,
nodeConfig.NetworkID,
nodeConfig.SybilProtectionEnabled,
healthCheckAveragerHalflife,
)
if err != nil {
return node.Config{}, err
}
Expand Down
5 changes: 4 additions & 1 deletion config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.String(NetworkCompressionTypeKey, constants.DefaultNetworkCompressionType.String(), fmt.Sprintf("Compression type for outbound messages. Must be one of [%s, %s, %s]", compression.TypeGzip, compression.TypeZstd, compression.TypeNone))

fs.Duration(NetworkMaxClockDifferenceKey, constants.DefaultNetworkMaxClockDifference, "Max allowed clock difference value between this node and peers")
fs.Bool(NetworkAllowPrivateIPsKey, constants.DefaultNetworkAllowPrivateIPs, "Allows the node to initiate outbound connection attempts to peers with private IPs")
// Note: The default value is set to false here because the default
// networkID is mainnet. The real default value of NetworkAllowPrivateIPs is
// based on the networkID.
fs.Bool(NetworkAllowPrivateIPsKey, false, fmt.Sprintf("Allows the node to initiate outbound connection attempts to peers with private IPs. If the provided --%s is one of [%s, %s] the default is false. Oterhwise, the default is true", NetworkNameKey, constants.MainnetName, constants.FujiName))
fs.Bool(NetworkRequireValidatorToConnectKey, constants.DefaultNetworkRequireValidatorToConnect, "If true, this node will only maintain a connection with another node if this node is a validator, the other node is a validator, or the other node is a beacon")
fs.Uint(NetworkPeerReadBufferSizeKey, constants.DefaultNetworkPeerReadBufferSize, "Size, in bytes, of the buffer that we read peer messages into (there is one buffer per peer)")
fs.Uint(NetworkPeerWriteBufferSizeKey, constants.DefaultNetworkPeerWriteBufferSize, "Size, in bytes, of the buffer that we write peer messages into (there is one buffer per peer)")
Expand Down
2 changes: 1 addition & 1 deletion network/test_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func NewTestNetwork(
MaxClockDifference: constants.DefaultNetworkMaxClockDifference,
CompressionType: constants.DefaultNetworkCompressionType,
PingFrequency: constants.DefaultPingFrequency,
AllowPrivateIPs: constants.DefaultNetworkAllowPrivateIPs,
AllowPrivateIPs: !constants.ProductionNetworkIDs.Contains(networkID),
UptimeMetricFreq: constants.DefaultUptimeMetricFreq,
MaximumInboundMessageTimeout: constants.DefaultNetworkMaximumInboundTimeout,

Expand Down
2 changes: 1 addition & 1 deletion snow/networking/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ func TestDynamicEngineTypeDispatch(t *testing.T) {
}

handler.Start(context.Background(), false)
handler.Push(context.TODO(), Message{
handler.Push(context.Background(), Message{
InboundMessage: message.InboundChits(
ids.Empty,
uint32(0),
Expand Down
5 changes: 5 additions & 0 deletions utils/constants/network_ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/set"
)

// Const variables to be exported
Expand Down Expand Up @@ -86,6 +87,10 @@ var (
UnitTestHRP: UnitTestID,
LocalHRP: LocalID,
}
ProductionNetworkIDs = set.Set[uint32]{
MainnetID: struct{}{},
FujiID: struct{}{},
}

ValidNetworkPrefix = "network-"

Expand Down
1 change: 0 additions & 1 deletion utils/constants/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const (

DefaultNetworkCompressionType = compression.TypeGzip
DefaultNetworkMaxClockDifference = time.Minute
DefaultNetworkAllowPrivateIPs = true
DefaultNetworkRequireValidatorToConnect = false
DefaultNetworkPeerReadBufferSize = 8 * units.KiB
DefaultNetworkPeerWriteBufferSize = 8 * units.KiB
Expand Down
2 changes: 1 addition & 1 deletion vms/proposervm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ func TestExpiredBuildBlock(t *testing.T) {
nil,
))
defer func() {
require.NoError(proVM.Shutdown(context.TODO()))
require.NoError(proVM.Shutdown(context.Background()))
}()

// Initialize shouldn't be called again
Expand Down

0 comments on commit 2d4e09d

Please sign in to comment.