From b6bbdf5500568fb3194d725b9a42379ce64ae37d Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Wed, 2 Aug 2023 18:26:55 -0700 Subject: [PATCH] Remove println from tracking.rs --- src/tracking.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/tracking.rs b/src/tracking.rs index 99166af..c53fc5b 100644 --- a/src/tracking.rs +++ b/src/tracking.rs @@ -11,6 +11,7 @@ use lightning; use lightning::ln::peer_handler::{ ErroringMessageHandler, IgnoringMessageHandler, MessageHandler, PeerManager, }; +use lightning::{log_error, log_info, log_warn}; use lightning::routing::gossip::NetworkGraph; use lightning::sign::KeysManager; use lightning::util::logger::Logger; @@ -49,7 +50,7 @@ pub(crate) async fn download_gossip(pe message_handler, 0xdeadbeef, &random_data, - logger, + logger.clone(), keys_manager, )); router.set_pm(Arc::clone(&peer_handler)); @@ -63,12 +64,12 @@ pub(crate) async fn download_gossip(pe } }); - println!("Connecting to Lightning peers..."); + log_info!(logger, "Connecting to Lightning peers..."); let peers = config::ln_peers(); let mut connected_peer_count = 0; for current_peer in peers { - let initial_connection_succeeded = connect_peer(current_peer, Arc::clone(&peer_handler)).await; + let initial_connection_succeeded = connect_peer(current_peer, peer_handler.clone(), logger.clone()).await; if initial_connection_succeeded { connected_peer_count += 1; } @@ -78,7 +79,7 @@ pub(crate) async fn download_gossip(pe panic!("Failed to connect to any peer."); } - println!("Connected to {} Lightning peers!", connected_peer_count); + log_info!(logger, "Connected to {} Lightning peers!", connected_peer_count); tokio::spawn(async move { let mut previous_announcement_count = 0u64; @@ -108,7 +109,8 @@ pub(crate) async fn download_gossip(pe // if we either aren't caught up, or just stopped/started being caught up if !is_caught_up_with_gossip || (is_caught_up_with_gossip != was_previously_caught_up_with_gossip) { - println!( + log_info!( + logger, "gossip count (iteration {}): {} (delta: {}):\n\tannouncements: {}\n\t\tmismatched scripts: {}\n\tupdates: {}\n\t\tno HTLC max: {}\n", i, total_message_count, @@ -119,19 +121,19 @@ pub(crate) async fn download_gossip(pe counter.channel_updates_without_htlc_max_msats ); } else { - println!("Monitoring for gossip…") + log_info!(logger, "Monitoring for gossip…") } if is_caught_up_with_gossip && !was_previously_caught_up_with_gossip { - println!("caught up with gossip!"); + log_info!(logger, "caught up with gossip!"); needs_to_notify_persister = true; } else if !is_caught_up_with_gossip && was_previously_caught_up_with_gossip { - println!("Received new messages since catching up with gossip!"); + log_info!(logger, "Received new messages since catching up with gossip!"); } let continuous_caught_up_duration = latest_new_gossip_time.elapsed(); if continuous_caught_up_duration.as_secs() > 600 { - eprintln!("No new gossip messages in 10 minutes! Something's amiss!"); + log_warn!(logger, "No new gossip messages in 10 minutes! Something's amiss!"); } previous_announcement_count = counter.channel_announcements; @@ -146,19 +148,19 @@ pub(crate) async fn download_gossip(pe }); } -async fn connect_peer(current_peer: (PublicKey, SocketAddr), peer_manager: GossipPeerManager) -> bool where L::Target: Logger { - eprintln!("Connecting to peer {}@{}...", current_peer.0.to_hex(), current_peer.1.to_string()); +async fn connect_peer(current_peer: (PublicKey, SocketAddr), peer_manager: GossipPeerManager, logger: L) -> bool where L::Target: Logger { + log_info!(logger, "Connecting to peer {}@{}...", current_peer.0.to_hex(), current_peer.1.to_string()); let connection = lightning_net_tokio::connect_outbound( Arc::clone(&peer_manager), current_peer.0, current_peer.1, ).await; if let Some(disconnection_future) = connection { - eprintln!("Connected to peer {}@{}!", current_peer.0.to_hex(), current_peer.1.to_string()); + log_info!(logger, "Connected to peer {}@{}!", current_peer.0.to_hex(), current_peer.1.to_string()); tokio::spawn(async move { disconnection_future.await; loop { - eprintln!("Reconnecting to peer {}@{}...", current_peer.0.to_hex(), current_peer.1.to_string()); + log_warn!(logger, "Reconnecting to peer {}@{}...", current_peer.0.to_hex(), current_peer.1.to_string()); if let Some(disconnection_future) = lightning_net_tokio::connect_outbound( Arc::clone(&peer_manager), current_peer.0, @@ -171,7 +173,7 @@ async fn connect_peer(current_peer: (P }); true } else { - eprintln!("Failed to connect to peer {}@{}", current_peer.0.to_hex(), current_peer.1.to_string()); + log_error!(logger, "Failed to connect to peer {}@{}", current_peer.0.to_hex(), current_peer.1.to_string()); false } } -- 2.39.5