@@ -1877,32 +1877,14 @@ async fn detect_region_from_local_interfaces() -> Result<Region, String> {
18771877
18781878#[ tokio:: main]
18791879async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
1880- // Critical: This must be the FIRST line to catch any issues
1881- println ! ( "[DEBUG] QNet node binary started - checking basic functionality..." ) ;
1882-
1883- // Prevent restart spam in case of errors
1884- println ! ( "[DEBUG] Startup delay to prevent restart loops..." ) ;
1885- tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 2 ) ) . await ;
1886-
1887- // Test basic functionality before doing anything else
1888- println ! ( "[DEBUG] Testing std::env..." ) ;
1880+ // Initialize environment
18891881 if std:: env:: var ( "RUST_LOG" ) . is_err ( ) {
18901882 std:: env:: set_var ( "RUST_LOG" , "info" ) ;
18911883 }
1892- println ! ( "[DEBUG] std::env working" ) ;
1893-
1894- // Initialize logging
1895- println ! ( "[DEBUG] Initializing logger..." ) ;
18961884 env_logger:: init ( ) ;
1897- println ! ( "[DEBUG] Logger initialized" ) ;
18981885
18991886 // Auto-configure everything
1900- println ! ( "[DEBUG] Auto-configuring QNet node..." ) ;
19011887 let config = AutoConfig :: new ( ) . await ?;
1902- println ! ( "[DEBUG] AutoConfig completed successfully!" ) ;
1903-
1904- // Choose setup mode - interactive or auto
1905- println ! ( "[DEBUG] Starting setup mode selection..." ) ;
19061888
19071889 // PRODUCTION: Check for existing activation or run interactive setup
19081890 let ( node_type, activation_code) = check_existing_activation_or_setup ( ) . await ?;
@@ -2023,30 +2005,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
20232005 let log_file_path = std:: path:: Path :: new ( & config. data_dir ) . join ( "qnet-node.log" ) ;
20242006 println ! ( "📝 Log file: {}" , log_file_path. display( ) ) ;
20252007
2026- // Start node in background
2008+ // Start node with live console logging (not redirected to file)
20272009 let node_handle = {
20282010 let log_path = log_file_path. clone ( ) ;
20292011 tokio:: spawn ( async move {
2030- // Redirect logs to file for daemon mode
2031- if let Err ( e) = redirect_logs_to_file ( & log_path) . await {
2032- eprintln ! ( "⚠️ Failed to redirect logs: {}" , e) ;
2033- }
2034-
2035- // Start the blockchain node
2012+ // Start the blockchain node with console output
20362013 if let Err ( e) = node. start ( ) . await {
20372014 eprintln ! ( "❌ Node failed to start: {}" , e) ;
20382015 }
20392016 } )
20402017 } ;
20412018
2042- // Give node a moment to start
2019+ // Give node a moment to start and show initial config once
20432020 tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 2 ) ) . await ;
20442021
2045- // DAEMON MODE: Show startup info and management commands
2046- println ! ( "✅ QNet Node started successfully in daemon mode!" ) ;
2047- println ! ( "" ) ;
2048-
2049- // Get external IP for status display
2022+ // Show initial configuration ONCE
20502023 let external_ip = match tokio:: process:: Command :: new ( "curl" )
20512024 . arg ( "-s" )
20522025 . arg ( "--max-time" )
@@ -2061,87 +2034,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
20612034 _ => "localhost" . to_string ( )
20622035 } ;
20632036
2064- println ! ( "🌍 === QNet Node Status ===" ) ;
2065- println ! ( "🆔 Node Type: {:?}" , node_type) ;
2066- println ! ( "🌐 Region: {:?}" , region) ;
2067- println ! ( "📡 External IP: {}" , external_ip) ;
2068- println ! ( "🔗 P2P Port: {}" , config. p2p_port) ;
2069- println ! ( "🔧 RPC Port: {}" , config. rpc_port) ;
2070- println ! ( "📁 Data Directory: {}" , config. data_dir. display( ) ) ;
2071- println ! ( "📝 Log File: {}" , log_file_path. display( ) ) ;
2072- println ! ( "" ) ;
2073-
2074- println ! ( "💡 === Log Management ===" ) ;
2075- println ! ( "📖 View live logs: tail -f {}" , log_file_path. display( ) ) ;
2076- println ! ( "🔍 Search logs: grep 'ERROR' {}" , log_file_path. display( ) ) ;
2077- println ! ( "📊 Log size: du -h {}" , log_file_path. display( ) ) ;
2078- println ! ( "" ) ;
2079-
2080- println ! ( "🔧 === Node Management ===" ) ;
2081- println ! ( "🛑 Stop node: docker stop qnet-node" ) ;
2082- println ! ( "🔄 Restart node: docker restart qnet-node" ) ;
2083- println ! ( "📋 Container status: docker ps | grep qnet-node" ) ;
2084- println ! ( "🗑️ Remove container: docker rm qnet-node" ) ;
2085- println ! ( "" ) ;
2086-
2087- println ! ( "📊 === Service Endpoints ===" ) ;
2088- println ! ( "📡 RPC endpoint: http://{}:{}/rpc" , external_ip, config. rpc_port) ;
2089- println ! ( "🌐 API endpoint: http://{}:{}/api/v1/" , external_ip, std:: env:: var( "QNET_CURRENT_API_PORT" ) . unwrap_or( "8001" . to_string( ) ) ) ;
2090-
2091- // Start metrics server
2092- let metrics_port = config. rpc_port + 1000 ; // e.g., 9877 + 1000 = 10877
2093- let metrics_ip = external_ip. clone ( ) ;
2094- tokio:: spawn ( async move {
2095- println ! ( "📈 Metrics: http://{}:{}/metrics" , metrics_ip, metrics_port) ;
2096- } ) ;
2097-
2098- println ! ( "" ) ;
2099- println ! ( "⚡ === Blockchain Architecture ===" ) ;
2100- println ! ( "👑 Dynamic Leadership: Auto-failover consensus (Byzantine fault tolerant)" ) ;
2101- println ! ( " Priority 1: 154.38.160.39 (Primary Leader)" ) ;
2102- println ! ( " Priority 2: 62.171.157.44 (Backup Leader - Auto-failover)" ) ;
2103- println ! ( " Priority 3: 161.97.86.81 (Backup Leader - Auto-failover)" ) ;
2104- println ! ( " 🔄 Failover scenarios:" ) ;
2105- println ! ( " • If Primary goes offline → Backup #2 becomes leader" ) ;
2106- println ! ( " • If Primary returns → Leadership returns to Primary" ) ;
2107- println ! ( " • If all Genesis nodes offline → Any node can lead" ) ;
2108- println ! ( "📦 Microblocks: 1-second intervals (fast finality)" ) ;
2109- println ! ( "🏗️ Macroblocks: 90-second intervals (permanent finality)" ) ;
2110- println ! ( "🎯 Target TPS: 100,000+ transactions per second" ) ;
2111- println ! ( "🌐 Network scaling: Ready for 10M+ nodes" ) ;
2112- println ! ( "" ) ;
2113-
2114- // Simulate failover detection for demonstration
2115- println ! ( "🧪 Testing Dynamic Leadership..." ) ;
2116- tokio:: spawn ( async move {
2117- tokio:: time:: sleep ( Duration :: from_secs ( 10 ) ) . await ;
2118- println ! ( "[TEST] 🔄 Simulating leadership failover test..." ) ;
2119- println ! ( "[TEST] ✅ Dynamic leadership system: OPERATIONAL" ) ;
2120- println ! ( "[TEST] 💪 Network resilient to server failures" ) ;
2121- } ) ;
2122-
2123- println ! ( "🎉 === Setup Complete ===" ) ;
2124- println ! ( "✅ QNet Node is running in DAEMON MODE" ) ;
2125- println ! ( "🔄 Node will continue running in background" ) ;
2126- println ! ( "📝 All logs are being written to: {}" , log_file_path. display( ) ) ;
2037+ println ! ( "🚀 QNet Node #{} started successfully!" ,
2038+ std:: env:: var( "QNET_BOOTSTRAP_ID" ) . unwrap_or( "N/A" . to_string( ) ) ) ;
2039+ println ! ( "🌐 Region: {:?} | Type: {:?} | IP: {}" ,
2040+ region, node_type, external_ip) ;
2041+ println ! ( "📡 Endpoints: P2P={} RPC={} API={}" ,
2042+ config. p2p_port, config. rpc_port, std:: env:: var( "QNET_CURRENT_API_PORT" ) . unwrap_or( "8001" . to_string( ) ) ) ;
21272043 println ! ( "" ) ;
2128-
2129- // Show log viewing command prominently
2130- println ! ( "🔍 === TO VIEW LOGS ===" ) ;
2131- println ! ( "tail -f {}" , log_file_path. display( ) ) ;
2044+ println ! ( "📖 View detailed logs: docker logs -f qnet-node" ) ;
2045+ println ! ( "🔍 Filter blockchain logs: docker logs qnet-node | grep \" Block #\\ |Syncing\\ |Macroblock\" " ) ;
2046+ println ! ( "📊 Monitor P2P: docker logs qnet-node | grep \" peer\\ |P2P\\ |Connected\" " ) ;
21322047 println ! ( "" ) ;
2133- println ! ( "Press Ctrl+C in the log viewer to exit (node keeps running)" ) ;
2134- println ! ( "This terminal will now be free for other commands." ) ;
2135- println ! ( "" ) ;
2136-
2137- // Automatically transition to background mode
2138- println ! ( "🚀 Transitioning to background mode in 3 seconds..." ) ;
2139- tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 3 ) ) . await ;
2140-
2141- println ! ( "✅ Node is now running in background!" ) ;
2142- println ! ( "📖 Use: tail -f {} to view logs" , log_file_path. display( ) ) ;
2048+ println ! ( "=== BLOCKCHAIN LOGS (Live) ===" ) ;
21432049
2144- // Wait for the background node to complete (which should be never in normal operation)
2050+ // Continue with live blockchain logging - no background transition
21452051 let _ = node_handle. await ;
21462052
21472053 Ok ( ( ) )
0 commit comments