Skip to content

Commit 06dc544

Browse files
committed
fix: pass real challenge config values in ChallengeStarted event
- Enrich ChallengeStartedEvent with docker_image, mechanism_id, emission_weight, etc. - Server broadcasts full config when starting challenge - Validator uses real values from event instead of hardcoded defaults
1 parent 9047616 commit 06dc544

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

bins/platform/src/server.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ async fn start_challenge(
318318
models::ChallengeStartedEvent {
319319
id: id.clone(),
320320
endpoint: endpoint.clone(),
321+
docker_image: challenge.docker_image.clone(),
322+
mechanism_id: challenge.mechanism_id as u8,
323+
emission_weight: challenge.emission_weight,
324+
timeout_secs: 3600,
325+
cpu_cores: 2.0,
326+
memory_mb: 4096,
327+
gpu_required: false,
321328
},
322329
))
323330
.await;

bins/validator-node/src/main.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ pub struct ChallengeStoppedEvent {
217217
pub struct ChallengeStartedEvent {
218218
pub id: String,
219219
pub endpoint: String,
220+
pub docker_image: String,
221+
pub mechanism_id: u8,
222+
pub emission_weight: f64,
223+
#[serde(default = "default_timeout")]
224+
pub timeout_secs: u64,
225+
#[serde(default = "default_cpu")]
226+
pub cpu_cores: f64,
227+
#[serde(default = "default_memory")]
228+
pub memory_mb: u64,
229+
#[serde(default)]
230+
pub gpu_required: bool,
231+
}
232+
233+
fn default_timeout() -> u64 {
234+
3600
235+
}
236+
fn default_cpu() -> f64 {
237+
2.0
238+
}
239+
fn default_memory() -> u64 {
240+
4096
220241
}
221242

222243
/// Custom event from a challenge
@@ -858,24 +879,23 @@ async fn connect_to_websocket(
858879
}
859880
Ok(WsEvent::ChallengeStarted(event)) => {
860881
info!(
861-
"Received challenge_started event for: {} at {}",
862-
event.id, event.endpoint
882+
"Received challenge_started event for: {} at {} (image: {}, emission: {})",
883+
event.id, event.endpoint, event.docker_image, event.emission_weight
863884
);
864-
// Start the challenge container locally
885+
// Start the challenge container locally using values from the event
865886
if let Some(ref orch) = orchestrator {
866-
let docker_image = format!("ghcr.io/platformnetwork/{}:latest", event.id);
867887
let challenge_uuid =
868888
uuid::Uuid::new_v5(&uuid::Uuid::NAMESPACE_DNS, event.id.as_bytes());
869889
let config = challenge_orchestrator::ChallengeContainerConfig {
870890
challenge_id: platform_core::ChallengeId(challenge_uuid),
871891
name: event.id.clone(),
872-
docker_image,
873-
mechanism_id: 0, // Default mechanism
874-
emission_weight: 100.0,
875-
timeout_secs: 3600,
876-
cpu_cores: 2.0,
877-
memory_mb: 4096,
878-
gpu_required: false,
892+
docker_image: event.docker_image.clone(),
893+
mechanism_id: event.mechanism_id,
894+
emission_weight: event.emission_weight,
895+
timeout_secs: event.timeout_secs,
896+
cpu_cores: event.cpu_cores,
897+
memory_mb: event.memory_mb,
898+
gpu_required: event.gpu_required,
879899
};
880900

881901
match orch.add_challenge(config).await {

crates/platform-server/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,19 @@ async fn start_challenge(
446446

447447
info!("Challenge {} started by owner {}", id, req.owner_hotkey);
448448

449-
// Broadcast to validators
449+
// Broadcast to validators with full challenge config
450450
state
451451
.broadcast_event(models::WsEvent::ChallengeStarted(
452452
models::ChallengeStartedEvent {
453453
id: id.clone(),
454454
endpoint: endpoint.clone(),
455+
docker_image: challenge.docker_image.clone(),
456+
mechanism_id: challenge.mechanism_id as u8,
457+
emission_weight: challenge.emission_weight,
458+
timeout_secs: 3600,
459+
cpu_cores: 2.0,
460+
memory_mb: 4096,
461+
gpu_required: false,
455462
},
456463
))
457464
.await;

crates/platform-server/src/models/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ pub struct ChallengeRegisteredEvent {
459459
pub struct ChallengeStartedEvent {
460460
pub id: String,
461461
pub endpoint: String,
462+
pub docker_image: String,
463+
pub mechanism_id: u8,
464+
pub emission_weight: f64,
465+
#[serde(default = "default_timeout")]
466+
pub timeout_secs: u64,
467+
#[serde(default = "default_cpu")]
468+
pub cpu_cores: f64,
469+
#[serde(default = "default_memory")]
470+
pub memory_mb: u64,
471+
#[serde(default)]
472+
pub gpu_required: bool,
462473
}
463474

464475
#[derive(Debug, Clone, Serialize, Deserialize)]

0 commit comments

Comments
 (0)