diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1361,6 +1361,11 @@ ArgsManager::ALLOW_ANY, OptionsCategory::AVALANCHE); argsman.AddArg("-avasessionkey", "Avalanche session key (default: random)", ArgsManager::ALLOW_ANY, OptionsCategory::AVALANCHE); + argsman.AddArg( + "-maxavalancheoutbound", + "Set the maximum number of avalanche outbound peers to connect to. " + "Note that the -maxconnections option takes precedence.", + ArgsManager::ALLOW_INT, OptionsCategory::AVALANCHE); // Add the hidden options argsman.AddHiddenArgs(hidden_args); @@ -3048,11 +3053,12 @@ CConnman::Options connOptions; connOptions.nLocalServices = nLocalServices; connOptions.nMaxConnections = nMaxConnections; - connOptions.m_max_avalanche_outbound = - std::min(g_avalanche && isAvalancheEnabled(args) - ? MAX_AVALANCHE_OUTBOUND_CONNECTIONS - : 0, - connOptions.nMaxConnections); + connOptions.m_max_avalanche_outbound = std::min( + g_avalanche && isAvalancheEnabled(args) + ? args.GetArg("-maxavalancheoutbound", + DEFAULT_MAX_AVALANCHE_OUTBOUND_CONNECTIONS) + : 0, + connOptions.nMaxConnections); connOptions.m_max_outbound_full_relay = std::min( MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, connOptions.nMaxConnections - connOptions.m_max_avalanche_outbound); diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -69,8 +69,11 @@ static const int MAX_ADDNODE_CONNECTIONS = 8; /** Maximum number of block-relay-only outgoing connections */ static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2; -/** Maximum number of avalanche enabled outgoing connections */ -static const int MAX_AVALANCHE_OUTBOUND_CONNECTIONS = 16; +/** + * Maximum number of avalanche enabled outgoing connections by default. + * Can be overridden with the -maxavalancheoutbound option. + */ +static const int DEFAULT_MAX_AVALANCHE_OUTBOUND_CONNECTIONS = 16; /** Maximum number of feeler connections */ static const int MAX_FEELER_CONNECTIONS = 1; /** -listen default */ diff --git a/test/functional/p2p_add_connections.py b/test/functional/p2p_add_connections.py --- a/test/functional/p2p_add_connections.py +++ b/test/functional/p2p_add_connections.py @@ -13,9 +13,12 @@ # From net.h MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 16 -MAX_AVALANCHE_OUTBOUND_CONNECTIONS = 16 MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2 +# Override DEFAULT_MAX_AVALANCHE_OUTBOUND_CONNECTIONS with +# -maxavalancheoutbound +MAX_AVALANCHE_OUTBOUND_CONNECTIONS = 12 + class P2PFeelerReceiver(P2PInterface): def on_version(self, message): @@ -29,7 +32,13 @@ class P2PAddConnections(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 - self.extra_args = [["-enableavalanche=1"], []] + self.extra_args = [ + [ + "-enableavalanche=1", + f"-maxavalancheoutbound={MAX_AVALANCHE_OUTBOUND_CONNECTIONS}" + ], + [] + ] def setup_network(self): self.setup_nodes()