]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Remove println from persistence.rs
authorArik Sosman <git@arik.io>
Thu, 3 Aug 2023 01:19:13 +0000 (18:19 -0700)
committerArik Sosman <git@arik.io>
Thu, 3 Aug 2023 01:19:13 +0000 (18:19 -0700)
src/lib.rs
src/persistence.rs

index 41057d31ba7d4d17dc8d12cb57f61a290d30262e..b6281bcb6836b58f7ecff75664ba6075bde8df13 100644 (file)
@@ -88,7 +88,7 @@ impl<L: Deref + Clone + Send + Sync + 'static> RapidSyncProcessor<L> where L::Ta
                let (sync_completion_sender, mut sync_completion_receiver) = mpsc::channel::<()>(1);
 
                if config::DOWNLOAD_NEW_GOSSIP {
-                       let (mut persister, persistence_sender) = GossipPersister::new(Arc::clone(&self.network_graph));
+                       let (mut persister, persistence_sender) = GossipPersister::new(self.network_graph.clone(), self.logger.clone());
 
                        log_info!(self.logger, "Starting gossip download");
                        tokio::spawn(tracking::download_gossip(persistence_sender, sync_completion_sender,
index e2d9eb0dd170ab44b0849cf5e9af80f97e16d781..f638894dd3590c9d0c583452c7e03aba8275cb15 100644 (file)
@@ -3,6 +3,7 @@ use std::io::{BufWriter, Write};
 use std::ops::Deref;
 use std::sync::Arc;
 use std::time::{Duration, Instant};
+use lightning::log_info;
 use lightning::routing::gossip::NetworkGraph;
 use lightning::util::logger::Logger;
 use lightning::util::ser::Writeable;
@@ -17,15 +18,17 @@ const POSTGRES_INSERT_TIMEOUT: Duration = Duration::from_secs(15);
 pub(crate) struct GossipPersister<L: Deref> where L::Target: Logger {
        gossip_persistence_receiver: mpsc::Receiver<GossipMessage>,
        network_graph: Arc<NetworkGraph<L>>,
+       logger: L
 }
 
 impl<L: Deref> GossipPersister<L> where L::Target: Logger {
-       pub fn new(network_graph: Arc<NetworkGraph<L>>) -> (Self, mpsc::Sender<GossipMessage>) {
+       pub fn new(network_graph: Arc<NetworkGraph<L>>, logger: L) -> (Self, mpsc::Sender<GossipMessage>) {
                let (gossip_persistence_sender, gossip_persistence_receiver) =
                        mpsc::channel::<GossipMessage>(100);
                (GossipPersister {
                        gossip_persistence_receiver,
-                       network_graph
+                       network_graph,
+                       logger
                }, gossip_persistence_sender)
        }
 
@@ -101,7 +104,7 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
                        i += 1; // count the persisted gossip messages
 
                        if latest_persistence_log.elapsed().as_secs() >= 60 {
-                               println!("Persisting gossip message #{}", i);
+                               log_info!(self.logger, "Persisting gossip message #{}", i);
                                latest_persistence_log = Instant::now();
                        }
 
@@ -179,7 +182,7 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
        }
 
        fn persist_network_graph(&self) {
-               println!("Caching network graph…");
+               log_info!(self.logger, "Caching network graph…");
                let cache_path = config::network_graph_cache_path();
                let file = OpenOptions::new()
                        .create(true)
@@ -191,6 +194,6 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
                let mut writer = BufWriter::new(file);
                self.network_graph.write(&mut writer).unwrap();
                writer.flush().unwrap();
-               println!("Cached network graph!");
+               log_info!(self.logger, "Cached network graph!");
        }
 }