diff --git a/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs b/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs index 2916023b60..80343b0fec 100644 --- a/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs +++ b/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs @@ -198,6 +198,9 @@ struct DsnArgs { /// Known external addresses #[arg(long, alias = "external-address")] external_addresses: Vec, + /// Defines whether we should run blocking Kademlia bootstrap() operation before other requests. + #[arg(long, default_value_t = false)] + disable_bootstrap_on_start: bool, } #[derive(Debug, Clone)] @@ -293,8 +296,9 @@ where replotting_thread_pool_size, } = farming_args; - // Override the `--enable_private_ips` flag with `--dev` + // Override flags with `--dev` dsn.enable_private_ips = dsn.enable_private_ips || dev; + dsn.disable_bootstrap_on_start = dsn.disable_bootstrap_on_start || dev; let _tmp_directory = if let Some(plot_size) = tmp { let tmp_directory = TempDir::new()?; diff --git a/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm/dsn.rs b/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm/dsn.rs index f0fe5b7c25..295e790f00 100644 --- a/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm/dsn.rs +++ b/crates/subspace-farmer/src/bin/subspace-farmer/commands/farm/dsn.rs @@ -42,6 +42,7 @@ pub(super) fn configure_dsn( pending_out_connections, target_connections, external_addresses, + disable_bootstrap_on_start, }: DsnArgs, weak_readers_and_pieces: Weak>>, node_client: NodeRpcClient, @@ -194,6 +195,7 @@ pub(super) fn configure_dsn( }, external_addresses, metrics, + disable_bootstrap_on_start, ..default_config }; diff --git a/crates/subspace-networking/src/constructor.rs b/crates/subspace-networking/src/constructor.rs index 9e3e8aea5b..446e2e6827 100644 --- a/crates/subspace-networking/src/constructor.rs +++ b/crates/subspace-networking/src/constructor.rs @@ -252,6 +252,8 @@ pub struct Config { pub external_addresses: Vec, /// Enable autonat protocol. Helps detecting whether we're behind the firewall. pub enable_autonat: bool, + /// Defines whether we should run blocking Kademlia bootstrap() operation before other requests. + pub disable_bootstrap_on_start: bool, } impl fmt::Debug for Config { @@ -370,6 +372,7 @@ where kademlia_mode: KademliaMode::Static(Mode::Client), external_addresses: Vec::new(), enable_autonat: true, + disable_bootstrap_on_start: false, } } } @@ -433,6 +436,7 @@ where kademlia_mode, external_addresses, enable_autonat, + disable_bootstrap_on_start, } = config; let local_peer_id = peer_id(&keypair); @@ -557,6 +561,7 @@ where bootstrap_addresses, kademlia_mode, external_addresses, + disable_bootstrap_on_start, }); Ok((node, node_runner)) diff --git a/crates/subspace-networking/src/node_runner.rs b/crates/subspace-networking/src/node_runner.rs index 9a05ddb8a3..155612791d 100644 --- a/crates/subspace-networking/src/node_runner.rs +++ b/crates/subspace-networking/src/node_runner.rs @@ -147,6 +147,8 @@ where /// Optional storage for the [`HandlerId`] of the address removal task. /// We keep to stop the task along with the rest of the networking. _address_removal_task_handler_id: Option, + /// Defines whether we should run blocking Kademlia bootstrap() operation before other requests. + disable_bootstrap_on_start: bool, } // Helper struct for NodeRunner configuration (clippy requirement). @@ -169,6 +171,7 @@ where pub(crate) bootstrap_addresses: Vec, pub(crate) kademlia_mode: KademliaMode, pub(crate) external_addresses: Vec, + pub(crate) disable_bootstrap_on_start: bool, } impl NodeRunner @@ -192,6 +195,7 @@ where bootstrap_addresses, kademlia_mode, external_addresses, + disable_bootstrap_on_start, }: NodeRunnerConfig, ) -> Self { // Setup the address removal events exchange between persistent params storage and Kademlia. @@ -235,12 +239,17 @@ where external_addresses, removed_addresses_rx, _address_removal_task_handler_id: address_removal_task_handler_id, + disable_bootstrap_on_start, } } /// Drives the main networking future forward. pub async fn run(&mut self) { - self.bootstrap().await; + if !self.disable_bootstrap_on_start { + self.bootstrap().await; + } else { + debug!("Kademlia bootstrapping was skipped."); + } loop { futures::select! { diff --git a/crates/subspace-node/src/bin/subspace-node.rs b/crates/subspace-node/src/bin/subspace-node.rs index 0647d14a42..4836b507a5 100644 --- a/crates/subspace-node/src/bin/subspace-node.rs +++ b/crates/subspace-node/src/bin/subspace-node.rs @@ -516,6 +516,9 @@ fn main() -> Result<(), Error> { 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 + || cli.run.shared_params.dev, } }; diff --git a/crates/subspace-node/src/lib.rs b/crates/subspace-node/src/lib.rs index eac10b0085..0055151280 100644 --- a/crates/subspace-node/src/lib.rs +++ b/crates/subspace-node/src/lib.rs @@ -267,6 +267,10 @@ pub struct Cli { #[arg(long, default_value_t = false)] pub dsn_enable_private_ips: bool, + /// Defines whether we should run blocking Kademlia bootstrap() operation before other requests. + #[arg(long, default_value_t = false)] + pub dsn_disable_bootstrap_on_start: bool, + /// Enables DSN-sync on startup. #[arg(long, default_value_t = true, action = clap::ArgAction::Set)] pub sync_from_dsn: bool, diff --git a/crates/subspace-service/src/dsn.rs b/crates/subspace-service/src/dsn.rs index 25e8d92c21..9aedc2e1e1 100644 --- a/crates/subspace-service/src/dsn.rs +++ b/crates/subspace-service/src/dsn.rs @@ -69,6 +69,9 @@ pub struct DsnConfig { /// Known external addresses pub external_addresses: Vec, + + /// Defines whether we should run blocking Kademlia bootstrap() operation before other requests. + pub disable_bootstrap_on_start: bool, } pub(crate) fn create_dsn_instance( @@ -185,6 +188,7 @@ where external_addresses: dsn_config.external_addresses, kademlia_mode: KademliaMode::Static(Mode::Client), metrics, + disable_bootstrap_on_start: dsn_config.disable_bootstrap_on_start, ..default_networking_config };