Skip to content

Commit 02874ae

Browse files
committed
style: cargo fmt — merge request_response import line + wrap long boolean expression
1 parent 42f556e commit 02874ae

8 files changed

Lines changed: 37 additions & 83 deletions

File tree

src/agent/daemon.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use libp2p::{
2424
autonat, dcutr,
2525
futures::StreamExt,
2626
gossipsub::{self, IdentTopic},
27-
identify, identity, ping, relay,
28-
request_response,
27+
identify, identity, ping, relay, request_response,
2928
swarm::{NetworkBehaviour, SwarmEvent},
3029
Multiaddr, PeerId, SwarmBuilder,
3130
};
@@ -493,7 +492,9 @@ pub async fn start_daemon(
493492
fn evaluate_offer(offer: &TaskOffer) -> bool {
494493
// Real implementation would consult the scheduler's broker state; for now,
495494
// accept any task within reasonable bounds.
496-
offer.min_cpu_cores <= 64 && offer.min_memory_mb <= 512 * 1024 && offer.max_wallclock_ms <= 600_000
495+
offer.min_cpu_cores <= 64
496+
&& offer.min_memory_mb <= 512 * 1024
497+
&& offer.max_wallclock_ms <= 600_000
497498
}
498499

499500
/// Report current load as a fraction 0.0–1.0. Stub returns 0.1 (mostly idle).
@@ -731,11 +732,8 @@ mod tests {
731732
submitter_signature: vec![1u8; 64],
732733
};
733734

734-
let req = TaskDispatchRequest {
735-
task_id: "t-real".into(),
736-
manifest,
737-
inline_inputs: Vec::new(),
738-
};
735+
let req =
736+
TaskDispatchRequest { task_id: "t-real".into(), manifest, inline_inputs: Vec::new() };
739737

740738
let resp = execute_dispatched_task(&req, &store);
741739
assert_eq!(resp.status, TaskStatus::Succeeded, "err={:?}", resp.error);
@@ -799,12 +797,7 @@ mod tests {
799797

800798
#[test]
801799
fn relay_circuit_multiaddr_format() {
802-
let addr = relay_circuit_multiaddr(
803-
"203.0.113.1",
804-
19999,
805-
"12D3KooWRelay",
806-
"12D3KooWTarget",
807-
);
800+
let addr = relay_circuit_multiaddr("203.0.113.1", 19999, "12D3KooWRelay", "12D3KooWTarget");
808801
assert_eq!(
809802
addr,
810803
"/ip4/203.0.113.1/tcp/19999/p2p/12D3KooWRelay/p2p-circuit/p2p/12D3KooWTarget"

src/cli/submitter.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ pub async fn execute_remote_submit(cmd: &JobCommand) -> Result<(), Box<dyn std::
115115
// Parse the manifest from disk.
116116
let manifest_json = std::fs::read_to_string(&manifest_path)
117117
.map_err(|e| format!("reading manifest '{manifest_path}': {e}"))?;
118-
let manifest: JobManifest = serde_json::from_str(&manifest_json)
119-
.map_err(|e| format!("parsing manifest JSON: {e}"))?;
118+
let manifest: JobManifest =
119+
serde_json::from_str(&manifest_json).map_err(|e| format!("parsing manifest JSON: {e}"))?;
120120

121121
// Optional inline workload.
122122
let inline_inputs: Vec<(String, Vec<u8>)> = if let Some(path) = workload_path {
@@ -161,8 +161,7 @@ pub async fn execute_remote_submit(cmd: &JobCommand) -> Result<(), Box<dyn std::
161161
StreamProtocol::new(PROTOCOL_TASK_DISPATCH),
162162
ProtocolSupport::Full,
163163
)),
164-
request_response::Config::default()
165-
.with_request_timeout(Duration::from_secs(300)),
164+
request_response::Config::default().with_request_timeout(Duration::from_secs(300)),
166165
),
167166
identify: identify::Behaviour::new(identify::Config::new(
168167
"/worldcompute/1.0.0".into(),

src/network/discovery.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ impl Default for DiscoveryConfig {
9292
let seeds: Vec<String> = std::env::var("WORLDCOMPUTE_BOOTSTRAP_SEEDS")
9393
.map(|s| s.split(',').map(|s| s.trim().to_string()).collect())
9494
.unwrap_or_else(|_| {
95-
let mut v: Vec<String> = BOOTSTRAP_DNS_SEEDS.iter().map(|s| s.to_string()).collect();
95+
let mut v: Vec<String> =
96+
BOOTSTRAP_DNS_SEEDS.iter().map(|s| s.to_string()).collect();
9697
v.extend(PUBLIC_LIBP2P_BOOTSTRAP_RELAYS.iter().map(|s| s.to_string()));
9798
v
9899
});

src/network/dispatch.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ pub enum TaskStatus {
104104

105105
/// Build the TaskOffer request-response behaviour.
106106
pub fn build_offer_behaviour() -> request_response::cbor::Behaviour<TaskOffer, TaskOfferResponse> {
107-
let protocols = std::iter::once((
108-
StreamProtocol::new(PROTOCOL_TASK_OFFER),
109-
ProtocolSupport::Full,
110-
));
107+
let protocols =
108+
std::iter::once((StreamProtocol::new(PROTOCOL_TASK_OFFER), ProtocolSupport::Full));
111109
let config = request_response::Config::default()
112110
.with_request_timeout(Duration::from_secs(10))
113111
.with_max_concurrent_streams(100);
@@ -117,10 +115,8 @@ pub fn build_offer_behaviour() -> request_response::cbor::Behaviour<TaskOffer, T
117115
/// Build the TaskDispatch request-response behaviour.
118116
pub fn build_dispatch_behaviour(
119117
) -> request_response::cbor::Behaviour<TaskDispatchRequest, TaskDispatchResponse> {
120-
let protocols = std::iter::once((
121-
StreamProtocol::new(PROTOCOL_TASK_DISPATCH),
122-
ProtocolSupport::Full,
123-
));
118+
let protocols =
119+
std::iter::once((StreamProtocol::new(PROTOCOL_TASK_DISPATCH), ProtocolSupport::Full));
124120
// Dispatch has a much longer timeout — the executor is actually running the job.
125121
let config = request_response::Config::default()
126122
.with_request_timeout(Duration::from_secs(600))
@@ -153,8 +149,7 @@ mod tests {
153149
let mut bytes = Vec::new();
154150
ciborium::ser::into_writer(&offer, &mut bytes).expect("serialize");
155151
assert!(!bytes.is_empty());
156-
let decoded: TaskOffer =
157-
ciborium::de::from_reader(&bytes[..]).expect("deserialize");
152+
let decoded: TaskOffer = ciborium::de::from_reader(&bytes[..]).expect("deserialize");
158153
assert_eq!(decoded.task_id, offer.task_id);
159154
assert_eq!(decoded.needs_gpu, offer.needs_gpu);
160155
}

tests/distributed_dispatch.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ fn build_swarm(keypair: identity::Keypair) -> libp2p::Swarm<TestBehaviour> {
4646
StreamProtocol::new(PROTOCOL_TASK_DISPATCH),
4747
ProtocolSupport::Full,
4848
)),
49-
request_response::Config::default()
50-
.with_request_timeout(Duration::from_secs(30)),
49+
request_response::Config::default().with_request_timeout(Duration::from_secs(30)),
5150
),
5251
identify: identify::Behaviour::new(identify::Config::new(
5352
"/test/1.0.0".into(),
@@ -96,8 +95,8 @@ async fn distributed_wasm_job_dispatch_end_to_end() {
9695
0x00, 0x61, 0x73, 0x6d, // magic
9796
0x01, 0x00, 0x00, 0x00, // version 1
9897
];
99-
let workload_cid = worldcompute::data_plane::cid_store::compute_cid(&wasm_bytes)
100-
.expect("compute cid");
98+
let workload_cid =
99+
worldcompute::data_plane::cid_store::compute_cid(&wasm_bytes).expect("compute cid");
101100

102101
// Executor daemon
103102
let executor_kp = identity::Keypair::generate_ed25519();
@@ -173,8 +172,7 @@ async fn distributed_wasm_job_dispatch_end_to_end() {
173172
})
174173
.await;
175174

176-
let response: TaskDispatchResponse =
177-
result.expect("timed out waiting for dispatch response");
175+
let response: TaskDispatchResponse = result.expect("timed out waiting for dispatch response");
178176
assert_eq!(response.task_id, "dist-test-001");
179177
assert_eq!(
180178
response.status,
@@ -191,11 +189,8 @@ fn execute_task_for_test(req: &TaskDispatchRequest) -> TaskDispatchResponse {
191189
use worldcompute::network::dispatch::TaskStatus;
192190

193191
let start = Instant::now();
194-
let wasm_bytes = req
195-
.inline_inputs
196-
.iter()
197-
.find(|(n, _)| n == "workload")
198-
.map(|(_, b)| b.clone());
192+
let wasm_bytes =
193+
req.inline_inputs.iter().find(|(n, _)| n == "workload").map(|(_, b)| b.clone());
199194

200195
let wasm_bytes = match wasm_bytes {
201196
Some(b) => b,

tests/nat_traversal.rs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,11 @@ struct ClientBehaviour {
5858
dispatch: request_response::cbor::Behaviour<TaskDispatchRequest, TaskDispatchResponse>,
5959
}
6060

61-
fn build_dispatch_behaviour() -> request_response::cbor::Behaviour<TaskDispatchRequest, TaskDispatchResponse> {
61+
fn build_dispatch_behaviour(
62+
) -> request_response::cbor::Behaviour<TaskDispatchRequest, TaskDispatchResponse> {
6263
request_response::cbor::Behaviour::new(
63-
std::iter::once((
64-
StreamProtocol::new(PROTOCOL_TASK_DISPATCH),
65-
ProtocolSupport::Full,
66-
)),
67-
request_response::Config::default()
68-
.with_request_timeout(Duration::from_secs(60)),
64+
std::iter::once((StreamProtocol::new(PROTOCOL_TASK_DISPATCH), ProtocolSupport::Full)),
65+
request_response::Config::default().with_request_timeout(Duration::from_secs(60)),
6966
)
7067
}
7168

@@ -151,11 +148,7 @@ fn make_test_manifest(workload_cid: cid::Cid) -> JobManifest {
151148
fn execute_wasm_task(req: &TaskDispatchRequest) -> TaskDispatchResponse {
152149
use std::time::Instant;
153150
let start = Instant::now();
154-
let wasm = req
155-
.inline_inputs
156-
.iter()
157-
.find(|(n, _)| n == "workload")
158-
.map(|(_, b)| b.clone());
151+
let wasm = req.inline_inputs.iter().find(|(n, _)| n == "workload").map(|(_, b)| b.clone());
159152
let Some(bytes) = wasm else {
160153
return TaskDispatchResponse {
161154
task_id: req.task_id.clone(),
@@ -170,8 +163,7 @@ fn execute_wasm_task(req: &TaskDispatchRequest) -> TaskDispatchResponse {
170163
config.consume_fuel(true);
171164
let engine = wasmtime::Engine::new(&config).expect("engine");
172165
match worldcompute::sandbox::wasm::compile_module(&engine, &bytes) {
173-
Ok(module) => match worldcompute::sandbox::wasm::run_module(&engine, &module, 10_000_000)
174-
{
166+
Ok(module) => match worldcompute::sandbox::wasm::run_module(&engine, &module, 10_000_000) {
175167
Ok(output) => TaskDispatchResponse {
176168
task_id: req.task_id.clone(),
177169
status: TaskStatus::Succeeded,
@@ -214,9 +206,7 @@ async fn three_node_relay_circuit_wasm_dispatch() {
214206
let r_kp = identity::Keypair::generate_ed25519();
215207
let r_peer = PeerId::from(r_kp.public());
216208
let mut r_swarm = build_relay_swarm(r_kp);
217-
r_swarm
218-
.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap())
219-
.expect("relay listen");
209+
r_swarm.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()).expect("relay listen");
220210

221211
// Wait for relay to obtain a concrete listen address.
222212
let r_addr: Multiaddr = timeout(Duration::from_secs(10), async {
@@ -238,16 +228,12 @@ async fn three_node_relay_circuit_wasm_dispatch() {
238228
let a_kp = identity::Keypair::generate_ed25519();
239229
let a_peer = PeerId::from(a_kp.public());
240230
let mut a_swarm = build_client_swarm(a_kp);
241-
a_swarm
242-
.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap())
243-
.expect("A listen");
231+
a_swarm.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()).expect("A listen");
244232

245233
// ─── Spawn client B — will dial A through R ──────────────────────────
246234
let b_kp = identity::Keypair::generate_ed25519();
247235
let mut b_swarm = build_client_swarm(b_kp);
248-
b_swarm
249-
.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap())
250-
.expect("B listen");
236+
b_swarm.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()).expect("B listen");
251237

252238
// A dials R and requests a relay reservation.
253239
a_swarm.dial(r_addr_with_peer.clone()).expect("A->R dial");
@@ -266,8 +252,7 @@ async fn three_node_relay_circuit_wasm_dispatch() {
266252
0x00, 0x61, 0x73, 0x6d, // magic
267253
0x01, 0x00, 0x00, 0x00, // version 1
268254
];
269-
let workload_cid =
270-
worldcompute::data_plane::cid_store::compute_cid(&wasm_bytes).expect("cid");
255+
let workload_cid = worldcompute::data_plane::cid_store::compute_cid(&wasm_bytes).expect("cid");
271256
let dispatch_request = TaskDispatchRequest {
272257
task_id: "nat-test-001".into(),
273258
manifest: make_test_manifest(workload_cid),
@@ -429,8 +414,5 @@ async fn three_node_relay_circuit_wasm_dispatch() {
429414
"Dispatch via relay should succeed: {:?}",
430415
response.error
431416
);
432-
println!(
433-
"✓ Cross-NAT dispatch succeeded: {}ms via relay circuit",
434-
response.duration_ms
435-
);
417+
println!("✓ Cross-NAT dispatch succeeded: {}ms via relay circuit", response.duration_ms);
436418
}

tests/network/test_tls.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ fn cert_issuance_produces_valid_cert() {
1717
assert!(!cert.key_der.is_empty(), "issued key DER must not be empty");
1818
// Cert should expire approximately 90 days from now
1919
let days_until = (cert.not_after - chrono::Utc::now()).num_days();
20-
assert!(
21-
(89..=91).contains(&days_until),
22-
"cert should expire in ~90 days, got {days_until}"
23-
);
20+
assert!((89..=91).contains(&days_until), "cert should expire in ~90 days, got {days_until}");
2421
}
2522

2623
#[test]

tests/test_nat_and_discovery.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,12 @@ fn bootstrap_dns_seeds_constant_matches_config_prefix() {
9595
);
9696
// Project seeds come first.
9797
for (i, seed) in BOOTSTRAP_DNS_SEEDS.iter().enumerate() {
98-
assert_eq!(
99-
*seed,
100-
config.bootstrap_seeds[i].as_str(),
101-
"Project seed {i} mismatch"
102-
);
98+
assert_eq!(*seed, config.bootstrap_seeds[i].as_str(), "Project seed {i} mismatch");
10399
}
104100
// Public libp2p relays follow.
105101
for (i, seed) in PUBLIC_LIBP2P_BOOTSTRAP_RELAYS.iter().enumerate() {
106102
let config_idx = BOOTSTRAP_DNS_SEEDS.len() + i;
107-
assert_eq!(
108-
*seed,
109-
config.bootstrap_seeds[config_idx].as_str(),
110-
"Public relay {i} mismatch"
111-
);
103+
assert_eq!(*seed, config.bootstrap_seeds[config_idx].as_str(), "Public relay {i} mismatch");
112104
}
113105
}
114106

0 commit comments

Comments
 (0)