@@ -1027,42 +1027,39 @@ impl BlockchainNode {
10271027 node_id : & str ,
10281028 unified_p2p : & Option < Arc < SimplifiedP2P > > ,
10291029 ) -> f64 {
1030- if let Some ( p2p) = unified_p2p {
1031- // Use EXISTING reputation system from P2P - already integrated!
1032- let reputation_system = p2p. get_reputation_system ( ) ;
1033- if let Ok ( reputation) = reputation_system. lock ( ) {
1034- let score = reputation. get_reputation ( node_id) ;
1035- // P2P system uses 0-100 scale, convert to 0-1 for consensus
1036- return ( score / 100.0 ) . max ( 0.0 ) . min ( 1.0 ) ;
1037- } ;
1030+ // CRITICAL FIX: Check Genesis status by environment variable FIRST
1031+ // node_id != activation_code, so we check QNET_BOOTSTRAP_ID instead
1032+
1033+ if let Ok ( bootstrap_id) = std:: env:: var ( "QNET_BOOTSTRAP_ID" ) {
1034+ match bootstrap_id. as_str ( ) {
1035+ "001" | "002" | "003" | "004" | "005" => {
1036+ println ! ( "[REPUTATION] 🛡️ Genesis node {} detected - granting 90% reputation" , bootstrap_id) ;
1037+ return 0.90 ; // Genesis nodes get 90% reputation immediately
1038+ }
1039+ _ => { }
1040+ }
10381041 }
10391042
1040- // SECURITY: Genesis bootstrap nodes get perfect reputation (ONLY these 5 nodes)
1041- // PRODUCTION: Exact matching prevents impersonation attacks
1042- const GENESIS_BOOTSTRAP_NODES : & [ & str ] = & [
1043- "QNET-BOOT-0001-STRAP" , "QNET-BOOT-0002-STRAP" , "QNET-BOOT-0003-STRAP" ,
1044- "QNET-BOOT-0004-STRAP" , "QNET-BOOT-0005-STRAP"
1045- ] ;
1043+ // Check for legacy genesis environment variable
1044+ if std:: env:: var ( "QNET_GENESIS_BOOTSTRAP" ) . unwrap_or_default ( ) == "1" {
1045+ println ! ( "[REPUTATION] 🛡️ Legacy Genesis node detected - granting 90% reputation" ) ;
1046+ return 0.90 ;
1047+ }
10461048
1047- // CRITICAL FIX: Use exact matching instead of .contains() to prevent spoofing
1048- for genesis_id in GENESIS_BOOTSTRAP_NODES {
1049- if node_id == * genesis_id {
1050- // PRODUCTION: Additional cryptographic verification for genesis nodes
1051- if verify_genesis_node_certificate ( node_id) {
1052- return 1.0 ; // Perfect reputation for VERIFIED genesis nodes only
1053- } else {
1054- // SECURITY: Genesis node failed verification - treat as untrusted
1055- println ! ( "[SECURITY] ⚠️ Genesis node {} failed certificate verification" , node_id) ;
1056- return 0.1 ; // Very low reputation for failed genesis verification
1049+ // SECURITY: Check activation code directly if available
1050+ if let Ok ( activation_code) = std:: env:: var ( "QNET_ACTIVATION_CODE" ) {
1051+ use crate :: genesis_constants:: GENESIS_BOOTSTRAP_CODES ;
1052+
1053+ for genesis_code in GENESIS_BOOTSTRAP_CODES {
1054+ if activation_code == * genesis_code {
1055+ println ! ( "[REPUTATION] 🛡️ Genesis activation code {} detected - granting 90% reputation" , genesis_code) ;
1056+ return 0.90 ;
10571057 }
10581058 }
10591059 }
10601060
10611061 // SECURITY: Legacy genesis nodes with exact matching (backward compatibility)
1062- const LEGACY_GENESIS_NODES : & [ & str ] = & [
1063- "genesis_node_1" , "genesis_node_2" , "genesis_node_3" ,
1064- "genesis_node_4" , "genesis_node_5"
1065- ] ;
1062+ use crate :: genesis_constants:: LEGACY_GENESIS_NODES ;
10661063
10671064 for legacy_id in LEGACY_GENESIS_NODES {
10681065 if node_id == * legacy_id {
@@ -1075,8 +1072,20 @@ impl BlockchainNode {
10751072 }
10761073 }
10771074
1078- // PRODUCTION: Smart reputation system for network health
1079- // Genesis bootstrap nodes get high reputation, regular nodes start at 70% for network participation
1075+ // FALLBACK: Use P2P reputation system for regular nodes
1076+ if let Some ( p2p) = unified_p2p {
1077+ let reputation_system = p2p. get_reputation_system ( ) ;
1078+ if let Ok ( reputation) = reputation_system. lock ( ) {
1079+ let score = reputation. get_reputation ( node_id) ;
1080+ // P2P system uses 0-100 scale, convert to 0-1 for consensus
1081+ let p2p_reputation = ( score / 100.0 ) . max ( 0.0 ) . min ( 1.0 ) ;
1082+ if p2p_reputation > 0.0 {
1083+ return p2p_reputation;
1084+ }
1085+ } ;
1086+ }
1087+
1088+ // DEFAULT: Starting reputation for new nodes based on type
10801089 let is_genesis_bootstrap = std:: env:: var ( "QNET_BOOTSTRAP_ID" ) . is_ok ( ) ||
10811090 std:: env:: var ( "QNET_GENESIS_BOOTSTRAP" ) . unwrap_or_default ( ) == "1" ;
10821091
@@ -1810,13 +1819,12 @@ impl BlockchainNode {
18101819 return Err ( QNetError :: ValidationError ( "Empty activation code" . to_string ( ) ) ) ;
18111820 }
18121821
1813- // Check for genesis bootstrap codes first (different format)
1814- const BOOTSTRAP_WHITELIST : & [ & str ] = & [
1815- "QNET-BOOT-0001-STRAP" , "QNET-BOOT-0002-STRAP" , "QNET-BOOT-0003-STRAP" ,
1816- "QNET-BOOT-0004-STRAP" , "QNET-BOOT-0005-STRAP"
1817- ] ;
1822+ // Check for genesis bootstrap codes first (different format)
1823+ // IMPORT from shared constants to avoid duplication
1824+ use crate :: genesis_constants:: GENESIS_BOOTSTRAP_CODES ;
1825+ let bootstrap_whitelist = GENESIS_BOOTSTRAP_CODES ;
18181826
1819- if BOOTSTRAP_WHITELIST . contains ( & code) {
1827+ if bootstrap_whitelist . contains ( & code) {
18201828 println ! ( "✅ Genesis bootstrap code detected in node.rs: {}" , code) ;
18211829 // Skip format validation for genesis codes
18221830 } else {
0 commit comments