Skip to content

Commit 4362a3c

Browse files
committed
feat: auto-start challenge containers from platform-server registry
Validator now: 1. Fetches challenge list from platform-server (with infinite retry) 2. Pulls Docker images for each challenge 3. Starts challenge containers via orchestrator 4. Starts health monitoring for all containers
1 parent d8e28b6 commit 4362a3c

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed

Cargo.lock

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

bins/validator-node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ anyhow = { workspace = true }
4444
hex = { workspace = true }
4545
parking_lot = { workspace = true }
4646
sp-core = { workspace = true }
47+
uuid = { version = "1.0", features = ["v5"] }

bins/validator-node/src/main.rs

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,6 @@ async fn main() -> Result<()> {
282282
info!("Platform server: {}", args.platform_server);
283283
platform_client.health_with_retry().await;
284284

285-
// List challenges
286-
match platform_client.list_challenges().await {
287-
Ok(c) if !c.is_empty() => {
288-
info!("Challenges:");
289-
for ch in &c {
290-
info!(
291-
" - {} (mechanism={}, healthy={})",
292-
ch.id, ch.mechanism_id, ch.is_healthy
293-
);
294-
}
295-
}
296-
Ok(_) => info!("No challenges yet"),
297-
Err(e) => warn!("Failed to list challenges: {}", e),
298-
}
299-
300285
// Container broker
301286
info!("Container broker on port {}...", args.broker_port);
302287
let broker = Arc::new(ContainerBroker::with_policy(SecurityPolicy::default()).await?);
@@ -314,7 +299,7 @@ async fn main() -> Result<()> {
314299
});
315300

316301
// Challenge orchestrator
317-
let _orchestrator = if args.docker_challenges {
302+
let orchestrator = if args.docker_challenges {
318303
match ChallengeOrchestrator::new(OrchestratorConfig {
319304
network_name: "platform-network".to_string(),
320305
health_check_interval: Duration::from_secs(30),
@@ -333,6 +318,55 @@ async fn main() -> Result<()> {
333318
None
334319
};
335320

321+
// List challenges and start containers
322+
let challenges = platform_client.list_challenges().await?;
323+
if challenges.is_empty() {
324+
info!("No challenges registered on platform-server");
325+
} else {
326+
info!("Challenges from platform-server:");
327+
for ch in &challenges {
328+
info!(
329+
" - {} (mechanism={}, healthy={})",
330+
ch.id, ch.mechanism_id, ch.is_healthy
331+
);
332+
}
333+
334+
// Start challenge containers
335+
if let Some(ref orch) = orchestrator {
336+
for ch in &challenges {
337+
let docker_image = format!("ghcr.io/platformnetwork/{}:latest", ch.id);
338+
// Generate a deterministic UUID from challenge name
339+
let challenge_uuid =
340+
uuid::Uuid::new_v5(&uuid::Uuid::NAMESPACE_DNS, ch.id.as_bytes());
341+
let config = challenge_orchestrator::ChallengeContainerConfig {
342+
challenge_id: platform_core::ChallengeId(challenge_uuid),
343+
name: ch.id.clone(),
344+
docker_image,
345+
mechanism_id: ch.mechanism_id as u8,
346+
emission_weight: ch.emission_weight,
347+
timeout_secs: 3600,
348+
cpu_cores: 2.0,
349+
memory_mb: 4096,
350+
gpu_required: false,
351+
};
352+
353+
info!("Starting challenge container: {}", ch.id);
354+
match orch.add_challenge(config).await {
355+
Ok(_) => info!("Challenge container started: {}", ch.id),
356+
Err(e) => error!("Failed to start challenge {}: {}", ch.id, e),
357+
}
358+
}
359+
360+
// Start health monitoring
361+
let orch_clone = orch.clone();
362+
tokio::spawn(async move {
363+
if let Err(e) = orch_clone.start().await {
364+
error!("Orchestrator health monitor error: {}", e);
365+
}
366+
});
367+
}
368+
}
369+
336370
// RPC server
337371
let addr: SocketAddr = format!("{}:{}", args.rpc_addr, args.rpc_port).parse()?;
338372
let rpc_server = RpcServer::new(

0 commit comments

Comments
 (0)