Skip to content

Commit 2adda1a

Browse files
committed
fix: use stored endpoints for challenge container URLs
Previously, P2P message handlers constructed container URLs like 'http://challenge-term-challenge:8080' without the validator suffix. Now they look up the correct endpoint from the challenge_endpoints map which contains the actual container URLs with suffixes like 'http://challenge-term-challenge-8fd119a138d6:8080'. This fixes authentication failures when forwarding P2P messages to challenge containers on validators running in Docker.
1 parent 5bf156f commit 2adda1a

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

bins/validator-node/src/main.rs

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,15 +3155,37 @@ async fn handle_message(
31553155
}
31563156

31573157
let challenge_id = challenge_msg.challenge_id.clone();
3158-
let container_name = challenge_id.to_lowercase().replace([' ', '_'], "-");
31593158
let from_hotkey = signer.to_hex();
31603159
let msg_payload = challenge_msg.payload.clone();
31613160
let kp = keypair.unwrap().clone();
31623161
let sessions = container_auth_sessions.unwrap().clone();
3162+
3163+
// Look up the correct endpoint from the stored endpoints map
3164+
let base_url = if let Some(endpoints) = challenge_endpoints {
3165+
let eps = endpoints.read();
3166+
// Try to find endpoint by challenge name or ID
3167+
eps.get(&challenge_id)
3168+
.or_else(|| eps.get(&challenge_id.to_lowercase().replace([' ', '_'], "-")))
3169+
.cloned()
3170+
} else {
3171+
None
3172+
};
3173+
3174+
let base_url = match base_url {
3175+
Some(url) => url,
3176+
None => {
3177+
// Fallback to constructed URL (may not work with suffixed container names)
3178+
let container_name = challenge_id.to_lowercase().replace([' ', '_'], "-");
3179+
warn!(
3180+
"No endpoint found for challenge '{}', using fallback URL (may fail)",
3181+
challenge_id
3182+
);
3183+
format!("http://challenge-{}:8080", container_name)
3184+
}
3185+
};
31633186

31643187
tokio::spawn(async move {
31653188
let client = reqwest::Client::new();
3166-
let base_url = format!("http://challenge-{}:8080", container_name);
31673189
let p2p_endpoint = format!("{}/p2p/message", base_url);
31683190

31693191
// Get or create authentication token
@@ -3172,8 +3194,8 @@ async fn handle_message(
31723194
Ok(token) => token,
31733195
Err(e) => {
31743196
warn!(
3175-
"Failed to authenticate with container {}: {}",
3176-
container_name, e
3197+
"Failed to authenticate with container for challenge {}: {}",
3198+
challenge_id, e
31773199
);
31783200
return;
31793201
}
@@ -3232,20 +3254,20 @@ async fn handle_message(
32323254
{
32333255
Ok(resp) if resp.status().is_success() => {
32343256
debug!(
3235-
"Forwarded challenge message to container {} (authenticated)",
3236-
container_name
3257+
"Forwarded challenge message to {} (authenticated)",
3258+
challenge_id
32373259
);
32383260
}
32393261
Ok(resp) if resp.status() == reqwest::StatusCode::UNAUTHORIZED => {
32403262
// Token expired, remove from cache
32413263
sessions.write().remove(&challenge_id);
3242-
warn!("Auth token expired for container {}, will re-authenticate on next message", container_name);
3264+
warn!("Auth token expired for challenge {}, will re-authenticate on next message", challenge_id);
32433265
}
32443266
Ok(resp) => {
3245-
debug!("Container {} returned {}", container_name, resp.status());
3267+
debug!("Challenge {} container returned {}", challenge_id, resp.status());
32463268
}
32473269
Err(e) => {
3248-
debug!("Failed to forward to container {}: {}", container_name, e);
3270+
debug!("Failed to forward to challenge {} container: {}", challenge_id, e);
32493271
}
32503272
}
32513273
}
@@ -3287,7 +3309,6 @@ async fn handle_message(
32873309
};
32883310

32893311
if let Some(config) = challenge_config {
3290-
let container_name = config.name.to_lowercase().replace([' ', '_'], "-");
32913312
let agent_hash = submission.agent_hash.clone();
32923313
let agent_hash_for_log = agent_hash.clone();
32933314
let challenge_name = submission.challenge_id.clone();
@@ -3303,6 +3324,30 @@ async fn handle_message(
33033324
hex::encode(hasher.finalize())
33043325
});
33053326
let validator_hotkey = signer.to_hex();
3327+
3328+
// Look up the correct endpoint from the stored endpoints map
3329+
let base_url = if let Some(endpoints) = challenge_endpoints {
3330+
let eps = endpoints.read();
3331+
// Try to find endpoint by challenge name, config name, or challenge ID
3332+
eps.get(&config.name)
3333+
.or_else(|| eps.get(&challenge_id.to_string()))
3334+
.or_else(|| eps.get(&config.name.to_lowercase().replace([' ', '_'], "-")))
3335+
.cloned()
3336+
} else {
3337+
None
3338+
};
3339+
3340+
let base_url = match base_url {
3341+
Some(url) => url,
3342+
None => {
3343+
let container_name = config.name.to_lowercase().replace([' ', '_'], "-");
3344+
warn!(
3345+
"No endpoint found for challenge '{}', using fallback URL",
3346+
config.name
3347+
);
3348+
format!("http://challenge-{}:8080", container_name)
3349+
}
3350+
};
33063351

33073352
// Forward agent submission to container and sign consensus
33083353
tokio::spawn(async move {
@@ -3311,8 +3356,7 @@ async fn handle_message(
33113356
// Step 1: If we have source code, submit the agent to our local container
33123357
// This ensures the container has the agent registered for evaluation
33133358
if let Some(ref code) = source_code {
3314-
let submit_endpoint =
3315-
format!("http://challenge-{}:8080/submit", container_name);
3359+
let submit_endpoint = format!("{}/submit", base_url);
33163360

33173361
let submit_payload = serde_json::json!({
33183362
"source_code": code,
@@ -3355,8 +3399,7 @@ async fn handle_message(
33553399
}
33563400

33573401
// Step 2: Sign consensus for this agent (allows evaluation to proceed)
3358-
let consensus_endpoint =
3359-
format!("http://challenge-{}:8080/consensus/sign", container_name);
3402+
let consensus_endpoint = format!("{}/consensus/sign", base_url);
33603403

33613404
let sign_payload = serde_json::json!({
33623405
"agent_hash": agent_hash,

0 commit comments

Comments
 (0)