Skip to content

Commit

Permalink
Merge pull request #2259 from subspace/tweak-connection-limits
Browse files Browse the repository at this point in the history
Tweak connections targets and limits
  • Loading branch information
nazar-pc authored Nov 21, 2023
2 parents ec2cb16 + b26daf6 commit f2fc438
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ struct DsnArgs {
#[arg(long)]
reserved_peers: Vec<Multiaddr>,
/// Defines max established incoming connection limit.
#[arg(long, default_value_t = 50)]
#[arg(long, default_value_t = 300)]
in_connections: u32,
/// Defines max established outgoing swarm connection limit.
#[arg(long, default_value_t = 100)]
Expand All @@ -192,9 +192,6 @@ struct DsnArgs {
/// Defines max pending outgoing swarm connection limit.
#[arg(long, default_value_t = 100)]
pending_out_connections: u32,
/// Defines target total (in and out) connection number that should be maintained.
#[arg(long, default_value_t = 15)]
target_connections: u32,
/// Known external addresses
#[arg(long, alias = "external-address")]
external_addresses: Vec<Multiaddr>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use tracing::{debug, error, info, Instrument};
///
/// Must be the same as RPC limit since all requests go to the node anyway.
const SEGMENT_HEADER_NUMBER_LIMIT: u64 = MAX_SEGMENT_HEADERS_PER_REQUEST as u64;
/// Should be sufficient number of target connections for everyone, limits are higher
const TARGET_CONNECTIONS: u32 = 15;

#[allow(clippy::type_complexity, clippy::too_many_arguments)]
pub(super) fn configure_dsn(
Expand All @@ -40,7 +42,6 @@ pub(super) fn configure_dsn(
out_connections,
pending_in_connections,
pending_out_connections,
target_connections,
external_addresses,
disable_bootstrap_on_start,
}: DsnArgs,
Expand Down Expand Up @@ -190,11 +191,11 @@ pub(super) fn configure_dsn(
special_connected_peers_handler: Some(Arc::new(PeerInfo::is_farmer)),
// Do not have any target for general peers
general_connected_peers_target: 0,
special_connected_peers_target: target_connections,
special_connected_peers_target: TARGET_CONNECTIONS,
// Allow up to quarter of incoming connections to be maintained
general_connected_peers_limit: in_connections / 4,
// Allow to maintain some extra farmer connections beyond direct interest too
special_connected_peers_limit: target_connections + in_connections / 4,
special_connected_peers_limit: TARGET_CONNECTIONS + in_connections / 4,
bootstrap_addresses: bootstrap_nodes,
kademlia_mode: KademliaMode::Dynamic,
external_addresses,
Expand Down
1 change: 0 additions & 1 deletion crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ fn main() -> Result<(), Error> {
max_out_connections: cli.dsn_out_connections,
max_pending_in_connections: cli.dsn_pending_in_connections,
max_pending_out_connections: cli.dsn_pending_out_connections,
target_connections: cli.dsn_target_connections,
external_addresses: cli.dsn_external_addresses,
// Override initial Kademlia bootstrapping with --dev
disable_bootstrap_on_start: cli.dsn_disable_bootstrap_on_start
Expand Down
4 changes: 0 additions & 4 deletions crates/subspace-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ pub struct Cli {
#[arg(long, default_value_t = 150)]
pub dsn_pending_out_connections: u32,

/// Defines target total (in and out) connection number for DSN that should be maintained.
#[arg(long, default_value_t = 15)]
pub dsn_target_connections: u32,

/// Determines whether we allow keeping non-global (private, shared, loopback..) addresses
/// in Kademlia DHT for the DSN.
#[arg(long, default_value_t = false)]
Expand Down
10 changes: 4 additions & 6 deletions crates/subspace-service/src/dsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use thiserror::Error;
use tracing::{debug, error, trace};

const SEGMENT_HEADERS_NUMBER_LIMIT: u64 = 1000;
/// Should be sufficient number of target connections for everyone, limits are higher
const TARGET_CONNECTIONS: u32 = 15;

/// Errors that might happen during DSN configuration.
#[derive(Debug, Error)]
Expand Down Expand Up @@ -64,9 +66,6 @@ pub struct DsnConfig {
/// Defines max pending outgoing swarm connection limit.
pub max_pending_out_connections: u32,

/// Defines target total (in and out) connection number for DSN that should be maintained.
pub target_connections: u32,

/// Known external addresses
pub external_addresses: Vec<Multiaddr>,

Expand Down Expand Up @@ -181,10 +180,9 @@ where
max_pending_outgoing_connections: dsn_config.max_pending_out_connections,
// Maintain proactive connections with all peers
general_connected_peers_handler: Some(Arc::new(|_| true)),
general_connected_peers_target: dsn_config.target_connections,
general_connected_peers_target: TARGET_CONNECTIONS,
// Allow to maintain some extra general connections beyond direct interest too
general_connected_peers_limit: dsn_config.target_connections
+ dsn_config.max_in_connections / 4,
general_connected_peers_limit: TARGET_CONNECTIONS + dsn_config.max_in_connections / 4,
reserved_peers: dsn_config.reserved_peers,
bootstrap_addresses: dsn_config.bootstrap_nodes,
external_addresses: dsn_config.external_addresses,
Expand Down

0 comments on commit f2fc438

Please sign in to comment.