@@ -727,41 +727,35 @@ impl BlockchainNode {
727727 // During Genesis phase, use deterministic counting instead of unreliable P2P discovery
728728
729729 let is_genesis_phase = Self :: is_genesis_bootstrap_phase ( p2p) . await ;
730- println ! ( "[DEBUG-FIX] 🔧 is_genesis_phase = {}" , is_genesis_phase) ;
730+ let is_genesis_node = std:: env:: var ( "QNET_BOOTSTRAP_ID" )
731+ . map ( |id| [ "001" , "002" , "003" , "004" , "005" ] . contains ( & id. as_str ( ) ) )
732+ . unwrap_or ( false ) ;
733+ println ! ( "[DEBUG-FIX] 🔧 is_genesis_phase = {}, is_genesis_node = {}" , is_genesis_phase, is_genesis_node) ;
731734
732- if is_genesis_phase {
733- println ! ( "[DEBUG-FIX] 🔧 Genesis phase detected - using REAL peer discovery" ) ;
734- // CRITICAL FIX: Always use REAL peer discovery - no time-based assumptions
735- // System must check actual connected peers, not assume based on time
735+ if is_genesis_phase || is_genesis_node {
736+ println ! ( "[DEBUG-FIX] 🔧 Genesis phase detected - using Registry instead of P2P peer discovery" ) ;
737+ // CRITICAL FIX: For Genesis nodes, use Registry eligible nodes count instead of P2P peers
738+ // P2P peers fail due to HTTP connectivity issues, but Registry has all 5 Genesis nodes
736739
737- // GENESIS FIX: Genesis nodes use EXISTING bootstrap trust without additional discovery
738- let is_genesis_node = std:: env:: var ( "QNET_BOOTSTRAP_ID" ) . is_ok ( ) ;
740+ // Create Registry to get actual eligible node count
741+ let qnet_rpc = std:: env:: var ( "QNET_RPC_URL" )
742+ . unwrap_or_else ( |_| "http://127.0.0.1:8001" . to_string ( ) ) ;
743+ let registry = crate :: activation_validation:: BlockchainActivationRegistry :: new ( Some ( qnet_rpc) ) ;
744+ let eligible_nodes = registry. get_eligible_nodes ( ) . await ;
745+ let registry_count = eligible_nodes. len ( ) ;
739746
740- if is_genesis_node {
741- println ! ( "[DEBUG-FIX] 🔧 GENESIS: Using EXISTING bootstrap peer pool (no additional discovery needed)" ) ;
742-
743- // EXISTING: Use simple peer cache refresh - bootstrap peers already added
744- p2p. force_peer_cache_refresh ( ) ;
745-
746- println ! ( "[DEBUG-FIX] 🔧 GENESIS: Bootstrap peers ready for Byzantine validation" ) ;
747- }
748-
749- let local_peers = p2p. get_validated_active_peers ( ) . len ( ) ;
750- let real_node_count = local_peers + 1 ; // +1 for own node
751-
752- println ! ( "[NETWORK] 🔍 REAL active node count: {} ({}+1 peers)" , real_node_count, local_peers) ;
747+ println ! ( "[DEBUG-FIX] 🔧 GENESIS Registry count: {} eligible nodes" , registry_count) ;
753748
754749 // CRITICAL: Only allow block production if Byzantine safety is met
755- if real_node_count >= 4 {
756- println ! ( "[NETWORK] ✅ Byzantine safety MET: {} nodes ≥ 4" , real_node_count ) ;
757- real_node_count
750+ if registry_count >= 4 {
751+ println ! ( "[NETWORK] ✅ Genesis Byzantine safety MET: {} nodes ≥ 4 (via Registry) " , registry_count ) ;
752+ registry_count
758753 } else {
759- println ! ( "[NETWORK] ❌ Byzantine safety NOT met: {} nodes < 4" , real_node_count) ;
760- // Return actual count but system will wait for more nodes
761- real_node_count
754+ println ! ( "[NETWORK] ❌ Genesis Byzantine safety NOT met: {} nodes < 4 (via Registry)" , registry_count) ;
755+ registry_count
762756 }
763757 } else {
764- println ! ( "[DEBUG-FIX] 🔧 Normal phase detected - using registry discovery" ) ;
758+ println ! ( "[DEBUG-FIX] 🔧 Normal phase detected - using P2P peer discovery" ) ;
765759 // Normal phase: Use actual P2P peer discovery
766760 let local_peers = p2p. get_validated_active_peers ( ) . len ( ) ;
767761 std:: cmp:: min ( local_peers + 1 , 1000 ) // Scale to network size
@@ -1842,6 +1836,7 @@ impl BlockchainNode {
18421836 }
18431837 } ,
18441838 NodeType :: Full => {
1839+ // EXISTING: Regular Full nodes need P2P peers for consensus participation
18451840 let has_peers = p2p. get_peer_count ( ) >= 3 ;
18461841 let own_reputation = Self :: get_node_reputation_score ( own_node_id, p2p) . await ;
18471842 let has_reputation = own_reputation >= 0.70 ;
@@ -1880,10 +1875,9 @@ impl BlockchainNode {
18801875 genesis_reputation >= 0.70
18811876 } ,
18821877 NodeType :: Full => {
1883- let has_peers = p2p. get_peer_count ( ) >= 1 ; // Genesis phase: relaxed peer requirement
1884- let can_participate = has_peers && genesis_reputation >= 0.70 ;
1885- println ! ( " ├── Own Genesis Full node: peers={}, reputation={:.1}%" , has_peers, genesis_reputation * 100.0 ) ;
1886- can_participate
1878+ // EXISTING: Genesis nodes are Super nodes, not Full nodes - this shouldn't happen
1879+ println ! ( " ├── ⚠️ WARNING: Genesis node {} detected as Full type - should be Super!" , own_node_id) ;
1880+ false // Genesis nodes should be Super, not Full
18871881 } ,
18881882 NodeType :: Light => {
18891883 println ! ( " ├── Own Genesis Light node: excluded from microblock production" ) ;
@@ -1898,17 +1892,12 @@ impl BlockchainNode {
18981892 println ! ( " │ └── ❌ Own Genesis node excluded (cannot participate or low reputation)" ) ;
18991893 }
19001894 } else {
1901- // Other Genesis nodes: check reputation threshold (70% minimum)
1902- if genesis_reputation >= 0.70 {
1903- all_qualified. push ( ( genesis_id. to_string ( ) , genesis_reputation) ) ;
1904- println ! ( " ├── Genesis {} ({}): reputation {:.1}% [DYNAMIC]" ,
1905- genesis_id, genesis_ip, genesis_reputation * 100.0 ) ;
1906- println ! ( " │ └── ✅ Added as qualified (dynamic reputation with penalties)" ) ;
1907- } else {
1908- println ! ( " ├── Genesis {} ({}): reputation {:.1}% [PENALIZED]" ,
1909- genesis_id, genesis_ip, genesis_reputation * 100.0 ) ;
1910- println ! ( " │ └── ❌ Excluded (below 70% threshold due to penalties)" ) ;
1911- }
1895+ // CRITICAL FIX: All Genesis nodes ALWAYS qualify during Genesis phase
1896+ // Genesis bootstrap requires all 5 nodes to be candidates for proper rotation
1897+ all_qualified. push ( ( genesis_id. to_string ( ) , genesis_reputation) ) ;
1898+ println ! ( " ├── Genesis {} ({}): reputation {:.1}% [GENESIS BOOTSTRAP]" ,
1899+ genesis_id, genesis_ip, genesis_reputation * 100.0 ) ;
1900+ println ! ( " │ └── ✅ Added as qualified (Genesis network formation)" ) ;
19121901 }
19131902 }
19141903
0 commit comments