From 0f247d9c5e80e66a3d972c04c9708a798dbcd79e Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 22 Aug 2022 02:39:26 +0000 Subject: [PATCH] Clean up the flow and variables in lib.rs and main.rs --- src/lib.rs | 24 +++++------------------- src/main.rs | 3 +-- src/persistence.rs | 8 +++----- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fe82489..c8fb6a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,6 @@ impl RapidSyncProcessor { NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), arc_logger) }; let arc_network_graph = Arc::new(network_graph); - let (_sync_termination_sender, _sync_termination_receiver) = mpsc::channel::<()>(1); Self { network_graph: arc_network_graph, initial_sync_complete: Arc::new(AtomicBool::new(initial_sync_complete)), @@ -88,27 +87,14 @@ impl RapidSyncProcessor { let (sync_completion_sender, mut sync_completion_receiver) = mpsc::channel::<()>(1); let initial_sync_complete = self.initial_sync_complete.clone(); - let network_graph = self.network_graph.clone(); - let snapshotter = Snapshotter::new(network_graph.clone()); - if config::DOWNLOAD_NEW_GOSSIP { + let (mut persister, persistence_sender) = + GossipPersister::new(sync_completion_sender, Arc::clone(&self.network_graph)); - let mut persister = GossipPersister::new(sync_completion_sender, self.network_graph.clone()); - - let persistence_sender = persister.gossip_persistence_sender.clone(); println!("Starting gossip download"); - let download_future = tracking::download_gossip(persistence_sender, network_graph.clone()); - tokio::spawn(async move { - // initiate the whole download stuff in the background - download_future.await; - }); + tokio::spawn(tracking::download_gossip(persistence_sender, Arc::clone(&self.network_graph))); println!("Starting gossip db persistence listener"); - tokio::spawn(async move { - // initiate persistence of the gossip data - let persistence_future = persister.persist_gossip(); - persistence_future.await; - }); - + tokio::spawn(async move { persister.persist_gossip().await; }); } else { sync_completion_sender.send(()).await.unwrap(); } @@ -122,7 +108,7 @@ impl RapidSyncProcessor { println!("Initial sync complete!"); // start the gossip snapshotting service - snapshotter.snapshot_gossip().await; + Snapshotter::new(Arc::clone(&self.network_graph)).snapshot_gossip().await; } } diff --git a/src/main.rs b/src/main.rs index 3e36edf..e3468be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,5 @@ use rapid_gossip_sync_server::RapidSyncProcessor; #[tokio::main] async fn main() { - let processor = RapidSyncProcessor::new(); - processor.start_sync().await; + RapidSyncProcessor::new().start_sync().await; } diff --git a/src/persistence.rs b/src/persistence.rs index 14a0173..820dda7 100644 --- a/src/persistence.rs +++ b/src/persistence.rs @@ -11,22 +11,20 @@ use crate::{config, hex_utils, TestLogger}; use crate::types::GossipMessage; pub(crate) struct GossipPersister { - pub(crate) gossip_persistence_sender: mpsc::Sender, gossip_persistence_receiver: mpsc::Receiver, server_sync_completion_sender: mpsc::Sender<()>, network_graph: Arc>>, } impl GossipPersister { - pub fn new(server_sync_completion_sender: mpsc::Sender<()>, network_graph: Arc>>) -> Self { + pub fn new(server_sync_completion_sender: mpsc::Sender<()>, network_graph: Arc>>) -> (Self, mpsc::Sender) { let (gossip_persistence_sender, gossip_persistence_receiver) = mpsc::channel::(100); - GossipPersister { - gossip_persistence_sender, + (GossipPersister { gossip_persistence_receiver, server_sync_completion_sender, network_graph - } + }, gossip_persistence_sender) } pub(crate) async fn persist_gossip(&mut self) { -- 2.39.5