@@ -863,7 +863,7 @@ async fn main() -> Result<()> {
863863
864864 let mut skipped_low_stake = 0 ;
865865 let mut add_failed = 0 ;
866-
866+
867867 for neuron in metagraph. neurons . values ( ) {
868868 // Convert AccountId32 hotkey to our Hotkey type
869869 let hotkey_bytes: & [ u8 ; 32 ] = neuron. hotkey . as_ref ( ) ;
@@ -873,7 +873,8 @@ async fn main() -> Result<()> {
873873 // Use total_stake from metagraph - this is the ACTUAL stake used in consensus
874874 // It includes: alpha stake + (tao stake * tao_weight)
875875 // The runtime API calculates this including parent inheritance
876- let stake_rao = neuron. total_stake . min ( u64:: MAX as u128 ) as u64 ;
876+ let stake_rao =
877+ neuron. total_stake . min ( u64:: MAX as u128 ) as u64 ;
877878
878879 // ALWAYS cache stake in protection for debugging
879880 // This allows us to show actual stake when rejecting low-stake validators
@@ -915,7 +916,7 @@ async fn main() -> Result<()> {
915916 v. stake = Stake :: new ( stake_rao) ;
916917 }
917918 }
918-
919+
919920 if skipped_low_stake > 0 {
920921 debug ! (
921922 "Skipped {} neurons with stake below {} TAO threshold" ,
@@ -1021,7 +1022,11 @@ async fn main() -> Result<()> {
10211022 let mut network = NetworkNode :: with_hotkey ( node_config. clone ( ) , Some ( & our_hotkey_hex) ) . await ?;
10221023 let mut event_rx = network. take_event_receiver ( ) . unwrap ( ) ;
10231024
1024- info ! ( "Local peer ID: {} (hotkey: {})" , network. local_peer_id( ) , keypair. ss58_address( ) ) ;
1025+ info ! (
1026+ "Local peer ID: {} (hotkey: {})" ,
1027+ network. local_peer_id( ) ,
1028+ keypair. ss58_address( )
1029+ ) ;
10251030
10261031 // Start network
10271032 network. start ( & node_config) . await ?;
@@ -1032,7 +1037,8 @@ async fn main() -> Result<()> {
10321037 // Spawn network event loop in a separate task
10331038 tokio:: spawn ( async move {
10341039 // Bootstrap retry interval - reconnect to bootnode if disconnected
1035- let mut bootstrap_retry_interval = tokio:: time:: interval ( std:: time:: Duration :: from_secs ( 30 ) ) ;
1040+ let mut bootstrap_retry_interval =
1041+ tokio:: time:: interval ( std:: time:: Duration :: from_secs ( 30 ) ) ;
10361042 bootstrap_retry_interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
10371043
10381044 loop {
@@ -1160,21 +1166,26 @@ async fn main() -> Result<()> {
11601166 info ! ( "Challenge container '{}' started successfully" , config. name) ;
11611167
11621168 // Get actual endpoint from orchestrator and update the endpoints map
1163- let endpoint = if let Some ( instance) = orch. get_challenge ( & config. challenge_id ) {
1169+ let endpoint = if let Some ( instance) =
1170+ orch. get_challenge ( & config. challenge_id )
1171+ {
11641172 instance. endpoint . clone ( )
11651173 } else {
11661174 // Fallback to constructed URL if instance not found
11671175 let container_name = config. name . to_lowercase ( ) . replace ( ' ' , "-" ) ;
11681176 format ! ( "http://challenge-{}:8080" , container_name)
11691177 } ;
1170-
1178+
11711179 // Update endpoints map for HTTP proxying (store by both UUID and name)
11721180 {
11731181 let mut eps = endpoints_for_orch. write ( ) ;
11741182 eps. insert ( config. challenge_id . to_string ( ) , endpoint. clone ( ) ) ;
11751183 eps. insert ( config. name . clone ( ) , endpoint. clone ( ) ) ;
11761184 }
1177- info ! ( "Updated endpoint for challenge '{}' ({}): {}" , config. name, config. challenge_id, endpoint) ;
1185+ info ! (
1186+ "Updated endpoint for challenge '{}' ({}): {}" ,
1187+ config. name, config. challenge_id, endpoint
1188+ ) ;
11781189
11791190 // Discover routes from the container via /.well-known/routes
11801191 if let Some ( ref routes) = routes_map {
@@ -1325,12 +1336,17 @@ async fn main() -> Result<()> {
13251336
13261337 for config in configs {
13271338 // Get actual endpoint from orchestrator (includes validator suffix in dev mode)
1328- let routes_url = if let Some ( instance) = orch_for_discovery. get_challenge ( & config. challenge_id ) {
1339+ let routes_url = if let Some ( instance) =
1340+ orch_for_discovery. get_challenge ( & config. challenge_id )
1341+ {
13291342 format ! ( "{}/.well-known/routes" , instance. endpoint)
13301343 } else {
13311344 // Fallback to constructed URL if instance not found
13321345 let container_name = config. name . to_lowercase ( ) . replace ( ' ' , "-" ) ;
1333- format ! ( "http://challenge-{}:8080/.well-known/routes" , container_name)
1346+ format ! (
1347+ "http://challenge-{}:8080/.well-known/routes" ,
1348+ container_name
1349+ )
13341350 } ;
13351351
13361352 info ! (
@@ -1875,7 +1891,7 @@ async fn main() -> Result<()> {
18751891 NetworkEvent :: PeerIdentified { peer_id, hotkey, agent_version } => {
18761892 let peer_str = peer_id. to_string( ) ;
18771893 let should_validate_stake = protection. config( ) . validate_stake;
1878-
1894+
18791895 if let Some ( ref hk) = hotkey {
18801896 // Convert hex hotkey to SS58 for display
18811897 let ss58 = if let Ok ( bytes) = hex:: decode( hk) {
@@ -2222,7 +2238,7 @@ async fn main() -> Result<()> {
22222238 let hotkey_bytes: & [ u8 ; 32 ] = neuron. hotkey. as_ref( ) ;
22232239 let hotkey = Hotkey ( * hotkey_bytes) ;
22242240 let hotkey_hex = hotkey. to_hex( ) ;
2225-
2241+
22262242 // Use total_stake from metagraph (includes parent inheritance + TAO weight)
22272243 let stake_rao = neuron. total_stake. min( u64 :: MAX as u128 ) as u64 ;
22282244
@@ -2455,14 +2471,22 @@ async fn handle_message(
24552471 error ! ( "Failed to start challenge container: {}" , e) ;
24562472 } else {
24572473 info ! ( "Challenge container started: {}" , config. name) ;
2458-
2474+
24592475 // Update endpoints map with actual container endpoint
24602476 if let Some ( endpoints) = challenge_endpoints {
2461- if let Some ( instance) = orchestrator. get_challenge ( & config. challenge_id ) {
2477+ if let Some ( instance) =
2478+ orchestrator. get_challenge ( & config. challenge_id )
2479+ {
24622480 let mut eps = endpoints. write ( ) ;
2463- eps. insert ( config. challenge_id . to_string ( ) , instance. endpoint . clone ( ) ) ;
2481+ eps. insert (
2482+ config. challenge_id . to_string ( ) ,
2483+ instance. endpoint . clone ( ) ,
2484+ ) ;
24642485 eps. insert ( config. name . clone ( ) , instance. endpoint . clone ( ) ) ;
2465- info ! ( "Updated endpoint for challenge '{}': {}" , config. name, instance. endpoint) ;
2486+ info ! (
2487+ "Updated endpoint for challenge '{}': {}" ,
2488+ config. name, instance. endpoint
2489+ ) ;
24662490 }
24672491 }
24682492 }
@@ -2605,14 +2629,21 @@ async fn handle_message(
26052629 error ! ( "Failed to start challenge container from P2P: {}" , e) ;
26062630 } else {
26072631 info ! ( "Challenge container '{}' started from P2P" , config. name) ;
2608-
2632+
26092633 // Update endpoints map with actual container endpoint
26102634 if let Some ( endpoints) = challenge_endpoints {
2611- if let Some ( instance) = orchestrator. get_challenge ( & config. challenge_id ) {
2635+ if let Some ( instance) = orchestrator. get_challenge ( & config. challenge_id )
2636+ {
26122637 let mut eps = endpoints. write ( ) ;
2613- eps. insert ( config. challenge_id . to_string ( ) , instance. endpoint . clone ( ) ) ;
2638+ eps. insert (
2639+ config. challenge_id . to_string ( ) ,
2640+ instance. endpoint . clone ( ) ,
2641+ ) ;
26142642 eps. insert ( config. name . clone ( ) , instance. endpoint . clone ( ) ) ;
2615- info ! ( "Updated endpoint for challenge '{}' (P2P): {}" , config. name, instance. endpoint) ;
2643+ info ! (
2644+ "Updated endpoint for challenge '{}' (P2P): {}" ,
2645+ config. name, instance. endpoint
2646+ ) ;
26162647 }
26172648 }
26182649 }
0 commit comments