@@ -209,8 +209,9 @@ async fn main() -> Result<()> {
209209 } ;
210210
211211 // Log the derived hotkey for verification against Bittensor metagraph
212- info ! ( "Validator hotkey (hex): {}" , keypair. hotkey( ) . to_hex( ) ) ;
213- info ! ( "Validator SS58 address: {}" , keypair. ss58_address( ) ) ;
212+ // SS58 is the standard format used on Bittensor blockchain
213+ info ! ( "Validator hotkey: {}" , keypair. ss58_address( ) ) ;
214+ debug ! ( "Validator hotkey (hex): {}" , keypair. hotkey( ) . to_hex( ) ) ;
214215
215216 // The identity seed for P2P is derived from the hotkey (public key)
216217 // This ensures the peer ID corresponds to the SS58 address
@@ -730,49 +731,55 @@ async fn main() -> Result<()> {
730731
731732 // Initial metagraph sync to populate validators from Bittensor
732733 // IMPORTANT: Must complete before accepting peer connections to validate their stake
733- info ! ( "Waiting for metagraph sync to load validators (netuid={})..." , args. netuid) ;
734-
734+ info ! (
735+ "Waiting for metagraph sync to load validators (netuid={})..." ,
736+ args. netuid
737+ ) ;
738+
735739 let max_retries = 3 ;
736740 let mut sync_success = false ;
737-
741+
738742 for attempt in 1 ..=max_retries {
739743 info ! ( "Metagraph sync attempt {}/{}..." , attempt, max_retries) ;
740-
744+
741745 match BittensorClient :: new ( & args. subtensor_endpoint ) . await {
742746 Ok ( metagraph_client) => {
743747 match sync_metagraph ( & metagraph_client, args. netuid ) . await {
744748 Ok ( metagraph) => {
745749 let mut added = 0 ;
746750 let mut state = chain_state. write ( ) ;
747-
751+
748752 for neuron in metagraph. neurons . values ( ) {
749753 // Convert AccountId32 hotkey to our Hotkey type
750754 let hotkey_bytes: & [ u8 ; 32 ] = neuron. hotkey . as_ref ( ) ;
751755 let hotkey = Hotkey ( * hotkey_bytes) ;
752-
756+
753757 // Get stake (convert from u128 to u64, saturating)
754758 let stake_rao = neuron. stake . min ( u64:: MAX as u128 ) as u64 ;
755-
759+
756760 // Skip if below minimum stake
757761 if stake_rao < MIN_STAKE_RAO {
758762 continue ;
759763 }
760-
764+
761765 // Add validator if not already present
762766 if state. get_validator ( & hotkey) . is_none ( ) {
763- let info = ValidatorInfo :: new ( hotkey. clone ( ) , Stake :: new ( stake_rao) ) ;
767+ let info = ValidatorInfo :: new (
768+ hotkey. clone ( ) ,
769+ Stake :: new ( stake_rao) ,
770+ ) ;
764771 if state. add_validator ( info) . is_ok ( ) {
765772 added += 1 ;
766773 }
767774 } else if let Some ( v) = state. validators . get_mut ( & hotkey) {
768775 // Update stake for existing validator
769776 v. stake = Stake :: new ( stake_rao) ;
770777 }
771-
778+
772779 // Cache stake in protection for quick validation
773780 protection. validate_stake ( & hotkey. to_hex ( ) , stake_rao) ;
774781 }
775-
782+
776783 info ! ( "Metagraph sync complete: {} neurons, {} validators with sufficient stake (min {} TAO)" ,
777784 metagraph. n, added, MIN_STAKE_TAO ) ;
778785 info ! ( "Validator identity verification ready - will accept messages from {} known validators" ,
@@ -786,18 +793,24 @@ async fn main() -> Result<()> {
786793 }
787794 }
788795 Err ( e) => {
789- warn ! ( "Failed to connect for metagraph sync (attempt {}): {}" , attempt, e) ;
796+ warn ! (
797+ "Failed to connect for metagraph sync (attempt {}): {}" ,
798+ attempt, e
799+ ) ;
790800 }
791801 }
792-
802+
793803 if attempt < max_retries {
794804 info ! ( "Retrying metagraph sync in 5 seconds..." ) ;
795805 tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 5 ) ) . await ;
796806 }
797807 }
798-
808+
799809 if !sync_success {
800- warn ! ( "CRITICAL: Metagraph sync failed after {} attempts!" , max_retries) ;
810+ warn ! (
811+ "CRITICAL: Metagraph sync failed after {} attempts!" ,
812+ max_retries
813+ ) ;
801814 warn ! ( "Validator will only recognize itself and sudo. Other validators may be rejected." ) ;
802815 warn ! ( "Periodic sync will retry every 10 minutes." ) ;
803816 }
@@ -1248,7 +1261,7 @@ async fn main() -> Result<()> {
12481261 msg_value. get ( "target" ) . and_then ( |t| t. as_str ( ) ) ,
12491262 ) {
12501263 // Check if this is a DecryptApiKeyRequest - handle locally
1251- if let Ok ( platform_challenge_sdk:: ChallengeP2PMessage :: DecryptApiKeyRequest ( req) ) =
1264+ if let Ok ( platform_challenge_sdk:: ChallengeP2PMessage :: DecryptApiKeyRequest ( req) ) =
12521265 serde_json:: from_value :: < platform_challenge_sdk:: ChallengeP2PMessage > ( message. clone ( ) ) {
12531266 // Decrypt the API key locally and send response back to container
12541267 let response = match platform_challenge_sdk:: decrypt_api_key (
@@ -1291,7 +1304,6 @@ async fn main() -> Result<()> {
12911304 debug ! ( "Failed to send decrypt response to container: {}" , e) ;
12921305 }
12931306 continue ; // Don't broadcast this message
1294- }
12951307 }
12961308
12971309 // Create ChallengeNetworkMessage to broadcast
@@ -1909,7 +1921,7 @@ async fn main() -> Result<()> {
19091921 let endpoint = subtensor_endpoint. clone( ) ;
19101922 let chain_state_for_sync = chain_state. clone( ) ;
19111923 let protection_for_sync = protection. clone( ) ;
1912-
1924+
19131925 tokio:: spawn( async move {
19141926 match BittensorClient :: new( & endpoint) . await {
19151927 Ok ( client) => {
@@ -1918,16 +1930,16 @@ async fn main() -> Result<()> {
19181930 let mut added = 0 ;
19191931 let mut updated = 0 ;
19201932 let mut state = chain_state_for_sync. write( ) ;
1921-
1933+
19221934 for neuron in metagraph. neurons. values( ) {
19231935 let hotkey_bytes: & [ u8 ; 32 ] = neuron. hotkey. as_ref( ) ;
19241936 let hotkey = Hotkey ( * hotkey_bytes) ;
19251937 let stake_rao = neuron. stake. min( u64 :: MAX as u128 ) as u64 ;
1926-
1938+
19271939 if stake_rao < MIN_STAKE_RAO {
19281940 continue ;
19291941 }
1930-
1942+
19311943 if state. get_validator( & hotkey) . is_none( ) {
19321944 let info = ValidatorInfo :: new( hotkey. clone( ) , Stake :: new( stake_rao) ) ;
19331945 if state. add_validator( info) . is_ok( ) {
@@ -1939,13 +1951,13 @@ async fn main() -> Result<()> {
19391951 updated += 1 ;
19401952 }
19411953 }
1942-
1954+
19431955 // Update stake cache
19441956 protection_for_sync. validate_stake( & hotkey. to_hex( ) , stake_rao) ;
19451957 }
1946-
1958+
19471959 if added > 0 || updated > 0 {
1948- info!( "Metagraph periodic sync: {} added, {} updated (total: {} validators)" ,
1960+ info!( "Metagraph periodic sync: {} added, {} updated (total: {} validators)" ,
19491961 added, updated, state. validators. len( ) ) ;
19501962 }
19511963 }
@@ -2261,7 +2273,10 @@ async fn handle_message(
22612273
22622274 // Start container via orchestrator (same as SudoAction handler)
22632275 if let Some ( orchestrator) = challenge_orchestrator {
2264- info ! ( "Starting challenge container '{}' from P2P Proposal" , config. name) ;
2276+ info ! (
2277+ "Starting challenge container '{}' from P2P Proposal" ,
2278+ config. name
2279+ ) ;
22652280 if let Err ( e) = orchestrator. add_challenge ( config. clone ( ) ) . await {
22662281 error ! ( "Failed to start challenge container from P2P: {}" , e) ;
22672282 } else {
0 commit comments