]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Clean up the flow and variables in lib.rs and main.rs
authorMatt Corallo <git@bluematt.me>
Mon, 22 Aug 2022 02:39:26 +0000 (02:39 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 22 Aug 2022 03:07:01 +0000 (03:07 +0000)
src/lib.rs
src/main.rs
src/persistence.rs

index fe824894171d221cece8b9a2a0a67383445916cb..c8fb6a78fdaeaf3d35b507d3bb157ce75815c661 100644 (file)
@@ -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;
                }
        }
 
index 3e36edff8e2c869b5c0887257368c5ce0bca06ac..e3468be840d9265884aead3ac521d9ce95e52513 100644 (file)
@@ -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;
 }
index 14a0173b6301e09e34ed89cee38dbac3511d760b..820dda7e5f285f0f7c92fef5ce3ab6c9dac06a30 100644 (file)
@@ -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<GossipMessage>,
        gossip_persistence_receiver: mpsc::Receiver<GossipMessage>,
        server_sync_completion_sender: mpsc::Sender<()>,
        network_graph: Arc<NetworkGraph<Arc<TestLogger>>>,
 }
 
 impl GossipPersister {
-       pub fn new(server_sync_completion_sender: mpsc::Sender<()>, network_graph: Arc<NetworkGraph<Arc<TestLogger>>>) -> Self {
+       pub fn new(server_sync_completion_sender: mpsc::Sender<()>, network_graph: Arc<NetworkGraph<Arc<TestLogger>>>) -> (Self, mpsc::Sender<GossipMessage>) {
                let (gossip_persistence_sender, gossip_persistence_receiver) =
                        mpsc::channel::<GossipMessage>(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) {