Skip to content

Commit 6b1dfbd

Browse files
authored
Merge pull request #3659 from autonomys/move-net-utils
Move process utilities out of subspace-networking
2 parents b811cc4 + df49e8c commit 6b1dfbd

File tree

51 files changed

+494
-547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+494
-547
lines changed

Cargo.lock

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ subspace-erasure-coding = { version = "0.1.0", path = "crates/subspace-erasure-c
257257
subspace-farmer-components = { version = "0.1.0", path = "crates/subspace-farmer-components" }
258258
subspace-gateway-rpc = { version = "0.1.0", path = "crates/subspace-gateway-rpc" }
259259
subspace-kzg = { version = "0.1.0", path = "shared/subspace-kzg", default-features = false }
260-
subspace-logging = { version = "0.0.1", path = "shared/subspace-logging" }
261260
subspace-metrics = { version = "0.1.0", path = "shared/subspace-metrics" }
262261
subspace-networking = { version = "0.1.0", path = "crates/subspace-networking" }
262+
subspace-process = { version = "0.0.1", path = "shared/subspace-process" }
263263
subspace-proof-of-space = { version = "0.1.0", path = "crates/subspace-proof-of-space", default-features = false }
264264
subspace-proof-of-space-gpu = { version = "0.1.0", path = "shared/subspace-proof-of-space-gpu" }
265265
subspace-proof-of-time = { version = "0.1.0", path = "crates/subspace-proof-of-time" }

crates/subspace-bootstrap-node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ libp2p = { workspace = true, features = ["kad"] }
2626
prometheus-client.workspace = true
2727
serde = { workspace = true, features = ["derive"] }
2828
serde_json.workspace = true
29-
subspace-logging.workspace = true
3029
subspace-metrics.workspace = true
3130
subspace-networking.workspace = true
31+
subspace-process.workspace = true
3232
tokio = { workspace = true, features = ["macros", "parking_lot", "rt-multi-thread"] }
3333
tracing.workspace = true

crates/subspace-bootstrap-node/src/main.rs

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
1515
use std::panic;
1616
use std::process::exit;
1717
use std::sync::Arc;
18-
use subspace_logging::init_logger;
1918
use subspace_metrics::{RegistryAdapter, start_prometheus_metrics_server};
2019
use subspace_networking::libp2p::multiaddr::Protocol;
21-
use subspace_networking::utils::{raise_fd_limit, run_future_in_dedicated_thread, shutdown_signal};
2220
use subspace_networking::{Config, KademliaMode, peer_id};
21+
use subspace_process::{
22+
init_logger, raise_fd_limit, run_future_in_dedicated_thread, shutdown_signal,
23+
};
2324
use tracing::{debug, info};
2425

2526
/// Size of the LRU cache for peers.
@@ -185,11 +186,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
185186

186187
let node_runner_fut = run_future_in_dedicated_thread(
187188
move || async move { node_runner.run().await },
188-
"bootstrap-node-networking".to_string(),
189+
"bootstrap-networking".to_string(),
189190
)?;
190191

191192
info!("Subspace Bootstrap Node started");
192193

194+
// TODO: spawn this in a dedicated thread
193195
let prometheus_task = should_start_prometheus_server
194196
.then(|| {
195197
start_prometheus_metrics_server(
@@ -199,36 +201,26 @@ async fn main() -> Result<(), Box<dyn Error>> {
199201
})
200202
.transpose()?;
201203

202-
// If a spawned future is running for a long time, it can block receiving exit signals.
203-
// Rather than hunting down every possible blocking future, we give the exit signal itself a
204-
// dedicated thread to run on.
205-
let exit_signal_select_fut = run_future_in_dedicated_thread(
206-
move || async move {
207-
if let Some(prometheus_task) = prometheus_task {
208-
select! {
209-
// Signal future
210-
() = signal.fuse() => {},
211-
_ = node_runner_fut.fuse() => {
212-
info!("DSN network runner exited.");
213-
},
214-
_ = prometheus_task.fuse() => {
215-
info!("Prometheus server exited.");
216-
},
217-
}
218-
} else {
219-
select! {
220-
// Signal future
221-
() = signal.fuse() => {},
222-
_ = node_runner_fut.fuse() => {
223-
info!("DSN network runner exited.");
224-
},
225-
}
226-
}
227-
},
228-
"bootstrap-node-exit-signal-select".to_string(),
229-
)?;
230-
231-
exit_signal_select_fut.await?;
204+
if let Some(prometheus_task) = prometheus_task {
205+
select! {
206+
// Signal future
207+
() = signal.fuse() => {},
208+
_ = node_runner_fut.fuse() => {
209+
info!("DSN network runner exited.");
210+
},
211+
_ = prometheus_task.fuse() => {
212+
info!("Prometheus server exited.");
213+
},
214+
}
215+
} else {
216+
select! {
217+
// Signal future
218+
() = signal.fuse() => {},
219+
_ = node_runner_fut.fuse() => {
220+
info!("DSN network runner exited.");
221+
},
222+
}
223+
}
232224
}
233225
Command::GenerateKeypair { json } => {
234226
let output = KeypairOutput::new(Keypair::generate());

crates/subspace-farmer/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ subspace-data-retrieval.workspace = true
5555
subspace-erasure-coding.workspace = true
5656
subspace-farmer-components.workspace = true
5757
subspace-kzg.workspace = true
58-
subspace-logging = { workspace = true, optional = true }
5958
subspace-metrics = { workspace = true, optional = true }
6059
subspace-networking.workspace = true
60+
subspace-process = { workspace = true, optional = true }
6161
subspace-proof-of-space.workspace = true
6262
subspace-rpc-primitives.workspace = true
6363
subspace-verification = { workspace = true, features = ["kzg"] }
@@ -97,5 +97,5 @@ binary = [
9797
"dep:criterion",
9898
"dep:mimalloc",
9999
"dep:subspace-metrics",
100-
"dep:subspace-logging",
100+
"dep:subspace-process",
101101
]

crates/subspace-farmer/src/bin/subspace-farmer/commands/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn create_thread_pool(
9292
.unwrap_or_else(recommended_number_of_farming_threads);
9393

9494
ThreadPoolBuilder::new()
95-
.thread_name(|thread_index| format!("benchmark.{thread_index}"))
95+
.thread_name(|thread_index| format!("benchmark.{thread_index:02}"))
9696
.num_threads(farming_thread_pool_size)
9797
.spawn_handler(tokio_rayon_spawn_handler())
9898
.build()

crates/subspace-farmer/src/bin/subspace-farmer/commands/cluster.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ use std::pin::Pin;
2121
use std::time::Duration;
2222
use subspace_farmer::cluster::nats_client::NatsClient;
2323
use subspace_metrics::{RegistryAdapter, start_prometheus_metrics_server};
24-
use subspace_networking::utils::{
25-
AsyncJoinOnDrop, run_future_in_dedicated_thread, shutdown_signal,
26-
};
24+
use subspace_process::{AsyncJoinOnDrop, shutdown_signal};
2725
use subspace_proof_of_space::Table;
2826

2927
const REQUEST_RETRY_MAX_ELAPSED_TIME: Duration = Duration::from_mins(1);
@@ -159,33 +157,22 @@ where
159157
RegistryAdapter::PrometheusClient(registry),
160158
)?;
161159

160+
// TODO: spawn this in a dedicated thread
162161
let join_handle = tokio::spawn(prometheus_task);
163162
tasks.push(Box::pin(async move {
164163
Ok(AsyncJoinOnDrop::new(join_handle, true).await??)
165164
}));
166165
}
167166

168-
// If a spawned future is running for a long time, it can block receiving exit signals.
169-
// Rather than hunting down every possible blocking future, we give the exit signal itself a
170-
// dedicated thread to run on.
171-
let exit_signal_select_fut = run_future_in_dedicated_thread(
172-
move || async move {
173-
select! {
174-
// Signal future
175-
_ = signal.fuse() => {
176-
Ok(())
177-
},
178-
179-
// Run future
180-
result = tasks.next() => {
181-
result.expect("List of tasks is not empty; qed")
182-
},
183-
}
184-
},
185-
"farmer-cluster-exit-signal-select".to_string(),
186-
)?;
167+
select! {
168+
// Signal future
169+
() = signal.fuse() => {},
187170

188-
exit_signal_select_fut.await??;
171+
// Run future
172+
result = tasks.next() => {
173+
result.expect("List of tasks is not empty; qed")?;
174+
},
175+
}
189176

190177
anyhow::Ok(())
191178
}

crates/subspace-farmer/src/bin/subspace-farmer/commands/cluster/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::time::Duration;
1414
use subspace_farmer::cluster::cache::cache_service;
1515
use subspace_farmer::cluster::nats_client::NatsClient;
1616
use subspace_farmer::disk_piece_cache::DiskPieceCache;
17-
use subspace_networking::utils::AsyncJoinOnDrop;
17+
use subspace_process::AsyncJoinOnDrop;
1818

1919
/// Interval between cache self-identification broadcast messages
2020
pub(super) const CACHE_IDENTIFICATION_BROADCAST_INTERVAL: Duration = Duration::from_secs(30);

crates/subspace-farmer/src/bin/subspace-farmer/commands/cluster/controller.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use subspace_farmer::node_client::rpc_node_client::RpcNodeClient;
2929
use subspace_farmer::single_disk_farm::identity::Identity;
3030
use subspace_kzg::Kzg;
3131
use subspace_networking::utils::piece_provider::PieceProvider;
32-
use subspace_networking::utils::{AsyncJoinOnDrop, run_future_in_dedicated_thread};
32+
use subspace_process::{AsyncJoinOnDrop, run_future_in_dedicated_thread};
3333
use tracing::{Instrument, info, info_span};
3434

3535
/// Get piece retry attempts number.
@@ -210,7 +210,7 @@ pub(super) async fn controller(
210210

211211
async move {
212212
let fut =
213-
run_future_in_dedicated_thread(move || fut, format!("cache-worker-{index}"));
213+
run_future_in_dedicated_thread(move || fut, format!("cache-worker-{index:02}"));
214214
anyhow::Ok(fut?.await?)
215215
}
216216
})
@@ -311,7 +311,7 @@ pub(super) async fn controller(
311311
)
312312
.await
313313
},
314-
format!("caches-{index}"),
314+
format!("caches-{index:02}"),
315315
);
316316
anyhow::Ok(fut?.await?)
317317
}

crates/subspace-farmer/src/bin/subspace-farmer/commands/cluster/farmer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use subspace_farmer::utils::recommended_number_of_farming_threads;
3333
use subspace_farmer::utils::ss58::parse_ss58_reward_address;
3434
use subspace_farmer_components::reading::ReadSectorRecordChunksMode;
3535
use subspace_kzg::Kzg;
36-
use subspace_networking::utils::{AsyncJoinOnDrop, run_future_in_dedicated_thread};
36+
use subspace_process::{AsyncJoinOnDrop, run_future_in_dedicated_thread};
3737
use subspace_proof_of_space::Table;
3838
use tracing::{Instrument, error, info, info_span, warn};
3939

0 commit comments

Comments
 (0)