@@ -152,6 +152,9 @@ pub struct SimplifiedP2P {
152152
153153 /// PRODUCTION: Channel to send consensus messages to node
154154 consensus_tx : Option < tokio:: sync:: mpsc:: UnboundedSender < ConsensusMessage > > ,
155+
156+ /// PRODUCTION: Channel to send blocks to node for processing
157+ block_tx : Option < tokio:: sync:: mpsc:: UnboundedSender < ReceivedBlock > > ,
155158}
156159
157160impl SimplifiedP2P {
@@ -193,26 +196,25 @@ impl SimplifiedP2P {
193196 // CRITICAL FIX: Genesis nodes get reputation based on environment variable, not node_id
194197 // node_id format is "node_9876_2", but activation code is "QNET-BOOT-0001-STRAP"
195198
199+ // PRODUCTION: Genesis reputation will be set by initialize_genesis_reputations()
200+ // This prevents self-reputation bias where each node gives itself 100%
196201 if let Ok ( bootstrap_id) = std:: env:: var ( "QNET_BOOTSTRAP_ID" ) {
197202 match bootstrap_id. as_str ( ) {
198203 "001" | "002" | "003" | "004" | "005" => {
199- reputation_sys. update_reputation ( & node_id, 90.0 ) ;
200- println ! ( "[P2P] 🛡️ Genesis node {} (ID: {}) initialized with high reputation (90.0)" , bootstrap_id, node_id) ;
204+ println ! ( "[P2P] 🛡️ Genesis node {} (ID: {}) detected - reputation will be initialized by consensus system" , bootstrap_id, node_id) ;
201205 }
202206 _ => { }
203207 }
204208 } else if std:: env:: var ( "QNET_GENESIS_BOOTSTRAP" ) . unwrap_or_default ( ) == "1" {
205- reputation_sys. update_reputation ( & node_id, 90.0 ) ;
206- println ! ( "[P2P] 🛡️ Legacy Genesis node {} initialized with high reputation (90.0)" , node_id) ;
209+ println ! ( "[P2P] 🛡️ Legacy Genesis node {} detected - reputation will be initialized by consensus system" , node_id) ;
207210 } else {
208211 // Check activation code for Genesis codes
209212 if let Ok ( activation_code) = std:: env:: var ( "QNET_ACTIVATION_CODE" ) {
210213 use crate :: genesis_constants:: GENESIS_BOOTSTRAP_CODES ;
211214
212215 for genesis_code in GENESIS_BOOTSTRAP_CODES {
213216 if activation_code == * genesis_code {
214- reputation_sys. update_reputation ( & node_id, 90.0 ) ;
215- println ! ( "[P2P] 🛡️ Genesis activation code {} (node: {}) initialized with high reputation (90.0)" , genesis_code, node_id) ;
217+ println ! ( "[P2P] 🛡️ Genesis activation code {} (node: {}) detected - reputation will be initialized by consensus system" , genesis_code, node_id) ;
216218 break ;
217219 }
218220 }
@@ -222,6 +224,7 @@ impl SimplifiedP2P {
222224 Arc :: new ( Mutex :: new ( reputation_sys) )
223225 } ,
224226 consensus_tx : None ,
227+ block_tx : None ,
225228 }
226229 }
227230
@@ -231,6 +234,12 @@ impl SimplifiedP2P {
231234 println ! ( "[P2P] 🏛️ Consensus integration channel established" ) ;
232235 }
233236
237+ /// PRODUCTION: Set block processing channel for storage integration
238+ pub fn set_block_channel ( & mut self , block_tx : tokio:: sync:: mpsc:: UnboundedSender < ReceivedBlock > ) {
239+ self . block_tx = Some ( block_tx) ;
240+ println ! ( "[P2P] 📦 Block processing channel established for storage integration" ) ;
241+ }
242+
234243 /// Start simplified P2P network with load balancing
235244 pub fn start ( & self ) {
236245 println ! ( "[P2P] Starting P2P network with intelligent load balancing" ) ;
@@ -1103,8 +1112,12 @@ impl SimplifiedP2P {
11031112 /// Create secure HTTP client for peer communication
11041113 fn create_secure_http_client ( ) -> Result < reqwest:: Client , String > {
11051114 reqwest:: Client :: builder ( )
1106- . timeout ( Duration :: from_secs ( 10 ) )
1115+ . timeout ( Duration :: from_secs ( 30 ) ) // PRODUCTION: Extended timeout for international Genesis nodes
1116+ . connect_timeout ( Duration :: from_secs ( 15 ) ) // Separate connection timeout
11071117 . user_agent ( "QNet-Node/1.0" )
1118+ . tcp_nodelay ( true ) // Disable Nagle's algorithm for faster responses
1119+ . tcp_keepalive ( Duration :: from_secs ( 60 ) ) // Keep connections alive
1120+ . pool_idle_timeout ( Duration :: from_secs ( 90 ) ) // Reuse connections
11081121 . build ( )
11091122 . map_err ( |e| format ! ( "HTTP client creation failed: {}" , e) )
11101123 }
@@ -2262,10 +2275,13 @@ impl SimplifiedP2P {
22622275 ] ;
22632276 // PRODUCTION: Use proper HTTP client instead of curl
22642277 for url in urls {
2265- // Create HTTP client
2278+ // Create HTTP client with production-ready configuration
22662279 let client = match reqwest:: Client :: builder ( )
2267- . timeout ( std:: time:: Duration :: from_secs ( 10 ) ) // CRITICAL FIX: Increased timeout for peer connectivity
2280+ . timeout ( std:: time:: Duration :: from_secs ( 25 ) ) // PRODUCTION: Extended timeout for international nodes
2281+ . connect_timeout ( std:: time:: Duration :: from_secs ( 12 ) ) // Connection timeout
22682282 . user_agent ( "QNet-Node/1.0" )
2283+ . tcp_nodelay ( true ) // Faster responses
2284+ . tcp_keepalive ( std:: time:: Duration :: from_secs ( 60 ) ) // Keep connections alive
22692285 . build ( ) {
22702286 Ok ( client) => client,
22712287 Err ( _) => continue ,
@@ -2382,13 +2398,48 @@ pub enum ConsensusMessage {
23822398 } ,
23832399}
23842400
2401+ /// Block received from P2P network for processing
2402+ #[ derive( Debug , Clone ) ]
2403+ pub struct ReceivedBlock {
2404+ pub height : u64 ,
2405+ pub data : Vec < u8 > ,
2406+ pub block_type : String ,
2407+ pub from_peer : String ,
2408+ pub timestamp : u64 ,
2409+ }
2410+
23852411impl SimplifiedP2P {
23862412 /// Handle incoming network message
23872413 pub fn handle_message ( & self , from_peer : & str , message : NetworkMessage ) {
23882414 match message {
23892415 NetworkMessage :: Block { height, data, block_type } => {
23902416 println ! ( "[P2P] ← Received {} block #{} from {} ({} bytes)" ,
23912417 block_type, height, from_peer, data. len( ) ) ;
2418+
2419+ // PRODUCTION: Send block to main node for processing via storage
2420+ if let Some ( ref block_tx) = self . block_tx {
2421+ let received_block = ReceivedBlock {
2422+ height,
2423+ data,
2424+ block_type : block_type. clone ( ) ,
2425+ from_peer : from_peer. to_string ( ) ,
2426+ timestamp : std:: time:: SystemTime :: now ( )
2427+ . duration_since ( std:: time:: UNIX_EPOCH )
2428+ . unwrap_or_default ( )
2429+ . as_secs ( ) ,
2430+ } ;
2431+
2432+ match block_tx. send ( received_block) {
2433+ Ok ( _) => {
2434+ println ! ( "[P2P] ✅ {} block #{} queued for processing" , block_type, height) ;
2435+ }
2436+ Err ( e) => {
2437+ println ! ( "[P2P] ❌ Failed to queue {} block #{}: {}" , block_type, height, e) ;
2438+ }
2439+ }
2440+ } else {
2441+ println ! ( "[P2P] ⚠️ Block processing channel not available - block #{} discarded" , height) ;
2442+ }
23922443 }
23932444
23942445 NetworkMessage :: Transaction { data } => {
@@ -2648,8 +2699,11 @@ impl SimplifiedP2P {
26482699 // Send asynchronously in background thread
26492700 tokio:: spawn ( async move {
26502701 let client = match reqwest:: Client :: builder ( )
2651- . timeout ( std:: time:: Duration :: from_secs ( 10 ) ) // CRITICAL FIX: Increased timeout for peer connectivity
2652- . user_agent ( "QNet-Node/1.0" )
2702+ . timeout ( std:: time:: Duration :: from_secs ( 20 ) ) // PRODUCTION: Timeout for Genesis node P2P messages
2703+ . connect_timeout ( std:: time:: Duration :: from_secs ( 10 ) ) // Connection timeout
2704+ . user_agent ( "QNet-Node/1.0" )
2705+ . tcp_nodelay ( true ) // Faster message delivery
2706+ . tcp_keepalive ( std:: time:: Duration :: from_secs ( 30 ) ) // P2P connection persistence
26532707 . build ( ) {
26542708 Ok ( client) => client,
26552709 Err ( e) => {
0 commit comments