@@ -2493,16 +2493,64 @@ async fn handle_message(
24932493 if let Some ( instance) =
24942494 orchestrator. get_challenge ( & config. challenge_id )
24952495 {
2496+ let endpoint = instance. endpoint . clone ( ) ;
24962497 let mut eps = endpoints. write ( ) ;
24972498 eps. insert (
24982499 config. challenge_id . to_string ( ) ,
2499- instance . endpoint . clone ( ) ,
2500+ endpoint. clone ( ) ,
25002501 ) ;
2501- eps. insert ( config. name . clone ( ) , instance . endpoint . clone ( ) ) ;
2502+ eps. insert ( config. name . clone ( ) , endpoint. clone ( ) ) ;
25022503 info ! (
25032504 "Updated endpoint for challenge '{}': {}" ,
2504- config. name, instance . endpoint
2505+ config. name, endpoint
25052506 ) ;
2507+
2508+ // Sync validators to the challenge container
2509+ let validators: Vec < _ > = chain_state
2510+ . read ( )
2511+ . validators
2512+ . iter ( )
2513+ . map ( |( hotkey, info) | {
2514+ serde_json:: json!( {
2515+ "hotkey" : hotkey,
2516+ "stake" : info. stake. 0 ,
2517+ "endpoint" : ""
2518+ } )
2519+ } )
2520+ . collect ( ) ;
2521+
2522+ if !validators. is_empty ( ) {
2523+ let sync_url = format ! ( "{}/p2p/validators" , endpoint) ;
2524+ let client = reqwest:: Client :: new ( ) ;
2525+ match client
2526+ . post ( & sync_url)
2527+ . json ( & serde_json:: json!( { "validators" : validators } ) )
2528+ . timeout ( std:: time:: Duration :: from_secs ( 5 ) )
2529+ . send ( )
2530+ . await
2531+ {
2532+ Ok ( resp) if resp. status ( ) . is_success ( ) => {
2533+ info ! (
2534+ "Synced {} validators to challenge '{}'" ,
2535+ validators. len( ) ,
2536+ config. name
2537+ ) ;
2538+ }
2539+ Ok ( resp) => {
2540+ warn ! (
2541+ "Failed to sync validators to challenge '{}': {}" ,
2542+ config. name,
2543+ resp. status( )
2544+ ) ;
2545+ }
2546+ Err ( e) => {
2547+ warn ! (
2548+ "Failed to sync validators to challenge '{}': {}" ,
2549+ config. name, e
2550+ ) ;
2551+ }
2552+ }
2553+ }
25062554 }
25072555 }
25082556 }
@@ -2650,16 +2698,64 @@ async fn handle_message(
26502698 if let Some ( endpoints) = challenge_endpoints {
26512699 if let Some ( instance) = orchestrator. get_challenge ( & config. challenge_id )
26522700 {
2701+ let endpoint = instance. endpoint . clone ( ) ;
26532702 let mut eps = endpoints. write ( ) ;
26542703 eps. insert (
26552704 config. challenge_id . to_string ( ) ,
2656- instance . endpoint . clone ( ) ,
2705+ endpoint. clone ( ) ,
26572706 ) ;
2658- eps. insert ( config. name . clone ( ) , instance . endpoint . clone ( ) ) ;
2707+ eps. insert ( config. name . clone ( ) , endpoint. clone ( ) ) ;
26592708 info ! (
26602709 "Updated endpoint for challenge '{}' (P2P): {}" ,
2661- config. name, instance . endpoint
2710+ config. name, endpoint
26622711 ) ;
2712+
2713+ // Sync validators to the challenge container
2714+ let validators: Vec < _ > = chain_state
2715+ . read ( )
2716+ . validators
2717+ . iter ( )
2718+ . map ( |( hotkey, info) | {
2719+ serde_json:: json!( {
2720+ "hotkey" : hotkey,
2721+ "stake" : info. stake. 0 ,
2722+ "endpoint" : ""
2723+ } )
2724+ } )
2725+ . collect ( ) ;
2726+
2727+ if !validators. is_empty ( ) {
2728+ let sync_url = format ! ( "{}/p2p/validators" , endpoint) ;
2729+ let client = reqwest:: Client :: new ( ) ;
2730+ match client
2731+ . post ( & sync_url)
2732+ . json ( & serde_json:: json!( { "validators" : validators } ) )
2733+ . timeout ( std:: time:: Duration :: from_secs ( 5 ) )
2734+ . send ( )
2735+ . await
2736+ {
2737+ Ok ( resp) if resp. status ( ) . is_success ( ) => {
2738+ info ! (
2739+ "Synced {} validators to challenge '{}' (P2P)" ,
2740+ validators. len( ) ,
2741+ config. name
2742+ ) ;
2743+ }
2744+ Ok ( resp) => {
2745+ warn ! (
2746+ "Failed to sync validators to challenge '{}': {}" ,
2747+ config. name,
2748+ resp. status( )
2749+ ) ;
2750+ }
2751+ Err ( e) => {
2752+ warn ! (
2753+ "Failed to sync validators to challenge '{}': {}" ,
2754+ config. name, e
2755+ ) ;
2756+ }
2757+ }
2758+ }
26632759 }
26642760 }
26652761 }
0 commit comments