Skip to content

Commit 54fb439

Browse files
committed
Improve blockchain logging: clean live console output without background transition
1 parent a5b5e88 commit 54fb439

2 files changed

Lines changed: 29 additions & 131 deletions

File tree

development/qnet-integration/src/bin/qnet-node.rs

Lines changed: 16 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,32 +1877,14 @@ async fn detect_region_from_local_interfaces() -> Result<Region, String> {
18771877

18781878
#[tokio::main]
18791879
async 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(())

development/qnet-integration/src/node.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -462,20 +462,16 @@ impl BlockchainNode {
462462
match p2p.sync_blockchain_height() {
463463
Ok(network_height) => {
464464
if network_height > microblock_height {
465-
println!("[CONSENSUS] 🔄 Network height {} ahead of local {}. Attempting block download...", network_height, microblock_height);
465+
println!("Syncing: downloading blocks {}-{}", microblock_height, network_height);
466466
p2p.download_missing_microblocks(storage.as_ref(), microblock_height, network_height).await;
467467
if let Ok(Some(_)) = storage.load_microblock(network_height) {
468-
println!("[SYNC] ✅ Downloaded up to #{}. Updating local cursor.", network_height);
469468
microblock_height = network_height;
470-
} else {
471-
println!("[SYNC] ⚠️ Download incomplete. Continuing with local height {}.", microblock_height);
469+
println!("Synced to block #{}", network_height);
472470
}
473-
} else if can_participate_consensus && microblock_height == network_height {
474-
println!("[CONSENSUS] ✅ Node synchronized, height: {}", microblock_height);
475471
}
476472
},
477-
Err(e) => {
478-
println!("[CONSENSUS] ⚠️ Sync failed: {}, continuing with local height", e);
473+
Err(_) => {
474+
// Silent sync failure - normal for isolated nodes
479475
}
480476
}
481477
}
@@ -488,7 +484,6 @@ impl BlockchainNode {
488484

489485
// PRODUCTION: Real QNet CommitReveal Consensus for Block Creation
490486
microblock_height += 1;
491-
println!("[CONSENSUS] 🏗️ Starting consensus round for block #{}", microblock_height);
492487

493488
// Get connected peers for consensus participation
494489
let participants = if let Some(p2p) = &unified_p2p {
@@ -509,19 +504,16 @@ impl BlockchainNode {
509504
// Start consensus round with connected participants
510505
match consensus_engine.start_round(participants.clone()) {
511506
Ok(round_id) => {
512-
println!("[CONSENSUS] ✅ Started consensus round {} with {} participants",
513-
round_id, participants.len());
514507

515508
// In production: This would involve network communication for commit-reveal
516509
// For now: Fast local consensus simulation for compatible block creation
517510
Some(round_id)
518511
}
519512
Err(ConsensusError::InsufficientNodes) => {
520-
println!("[CONSENSUS] ⚠️ Insufficient nodes for consensus, creating local block");
521513
None // Fallback to local block creation
522514
}
523515
Err(e) => {
524-
println!("[CONSENSUS] ❌ Consensus error: {:?}, skipping round", e);
516+
println!("Consensus error: {:?}, skipping", e);
525517
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
526518
continue;
527519
}
@@ -646,22 +638,22 @@ impl BlockchainNode {
646638
}
647639
}
648640

649-
// Enhanced logging with performance metrics
641+
// Clean blockchain logging
650642
if txs.len() > 0 {
651-
println!("[Microblock] ✅ #{} created: {} tx, {:.2} TPS, {}ms interval, {} bytes, {} finalized",
643+
println!("Block #{} | {} tx | {:.0} TPS | {} peers",
652644
microblock.height,
653645
txs.len(),
654646
tps,
655-
current_interval.as_millis(),
656-
microblock_data.len(),
657-
locally_finalized_count);
658-
} else if microblock_height % 10 == 0 {
659-
println!("[Microblock] ⏳ #{} empty (waiting for transactions)", microblock.height);
647+
if let Some(ref p2p) = unified_p2p { p2p.get_peer_count() } else { 0 });
648+
} else if microblock_height % 30 == 0 {
649+
println!("Block #{} | No transactions | {} peers connected",
650+
microblock.height,
651+
if let Some(ref p2p) = unified_p2p { p2p.get_peer_count() } else { 0 });
660652
}
661653

662654
// Trigger macroblock consensus every 90 microblocks
663655
if microblock_height - last_macroblock_trigger >= 90 {
664-
println!("[Macroblock] 🏗️ Triggering consensus for blocks {}-{}",
656+
println!("Macroblock consensus: blocks {}-{}",
665657
last_macroblock_trigger + 1, microblock_height);
666658

667659
tokio::spawn(Self::trigger_macroblock_consensus(

0 commit comments

Comments
 (0)