Skip to content

Commit

Permalink
Merge pull request #2182 from subspace/add-disable-bootstrap-on-start
Browse files Browse the repository at this point in the history
Add `--disable-bootstrap-on-start` flag for DSN apps.
  • Loading branch information
nazar-pc authored Nov 1, 2023
2 parents c0f905f + 1e296bd commit 3dfea07
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ struct DsnArgs {
/// Known external addresses
#[arg(long, alias = "external-address")]
external_addresses: Vec<Multiaddr>,
/// 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)]
Expand Down Expand Up @@ -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()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<Option<ReadersAndPieces>>>,
node_client: NodeRpcClient,
Expand Down Expand Up @@ -194,6 +195,7 @@ pub(super) fn configure_dsn(
},
external_addresses,
metrics,
disable_bootstrap_on_start,
..default_config
};

Expand Down
5 changes: 5 additions & 0 deletions crates/subspace-networking/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ pub struct Config<LocalRecordProvider> {
pub external_addresses: Vec<Multiaddr>,
/// 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<LocalRecordProvider> fmt::Debug for Config<LocalRecordProvider> {
Expand Down Expand Up @@ -370,6 +372,7 @@ where
kademlia_mode: KademliaMode::Static(Mode::Client),
external_addresses: Vec::new(),
enable_autonat: true,
disable_bootstrap_on_start: false,
}
}
}
Expand Down Expand Up @@ -433,6 +436,7 @@ where
kademlia_mode,
external_addresses,
enable_autonat,
disable_bootstrap_on_start,
} = config;
let local_peer_id = peer_id(&keypair);

Expand Down Expand Up @@ -557,6 +561,7 @@ where
bootstrap_addresses,
kademlia_mode,
external_addresses,
disable_bootstrap_on_start,
});

Ok((node, node_runner))
Expand Down
11 changes: 10 additions & 1 deletion crates/subspace-networking/src/node_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HandlerId>,
/// Defines whether we should run blocking Kademlia bootstrap() operation before other requests.
disable_bootstrap_on_start: bool,
}

// Helper struct for NodeRunner configuration (clippy requirement).
Expand All @@ -169,6 +171,7 @@ where
pub(crate) bootstrap_addresses: Vec<Multiaddr>,
pub(crate) kademlia_mode: KademliaMode,
pub(crate) external_addresses: Vec<Multiaddr>,
pub(crate) disable_bootstrap_on_start: bool,
}

impl<LocalRecordProvider> NodeRunner<LocalRecordProvider>
Expand All @@ -192,6 +195,7 @@ where
bootstrap_addresses,
kademlia_mode,
external_addresses,
disable_bootstrap_on_start,
}: NodeRunnerConfig<LocalRecordProvider>,
) -> Self {
// Setup the address removal events exchange between persistent params storage and Kademlia.
Expand Down Expand Up @@ -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! {
Expand Down
3 changes: 3 additions & 0 deletions crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
};

Expand Down
4 changes: 4 additions & 0 deletions crates/subspace-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions crates/subspace-service/src/dsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ pub struct DsnConfig {

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

/// Defines whether we should run blocking Kademlia bootstrap() operation before other requests.
pub disable_bootstrap_on_start: bool,
}

pub(crate) fn create_dsn_instance<AS>(
Expand Down Expand Up @@ -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
};
Expand Down

0 comments on commit 3dfea07

Please sign in to comment.