]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Drop Arcs around the TestLogger, as its an empty struct anyway
authorMatt Corallo <git@bluematt.me>
Mon, 22 Aug 2022 03:22:09 +0000 (03:22 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 22 Aug 2022 17:07:39 +0000 (17:07 +0000)
src/downloader.rs
src/lib.rs
src/lookup.rs
src/persistence.rs
src/snapshot.rs
src/tracking.rs
src/types.rs

index 72e55c5673970c6481be403e1c001d8564b3c374..3e6f91e051881b49ea516b94b45c32c9dc506441 100644 (file)
@@ -30,16 +30,15 @@ impl GossipCounter {
 }
 
 pub(crate) struct GossipRouter {
-       native_router: P2PGossipSync<Arc<NetworkGraph<Arc<TestLogger>>>, GossipChainAccess, Arc<TestLogger>>,
+       native_router: P2PGossipSync<Arc<NetworkGraph<TestLogger>>, GossipChainAccess, TestLogger>,
        pub(crate) counter: RwLock<GossipCounter>,
        sender: mpsc::Sender<GossipMessage>,
 }
 
 impl GossipRouter {
-       pub(crate) fn new(network_graph: Arc<NetworkGraph<Arc<TestLogger>>>, sender: mpsc::Sender<GossipMessage>) -> Self {
+       pub(crate) fn new(network_graph: Arc<NetworkGraph<TestLogger>>, sender: mpsc::Sender<GossipMessage>) -> Self {
                Self {
-                       native_router: P2PGossipSync::new(network_graph, Some(Arc::new(ChainVerifier::new())),
-                               Arc::new(TestLogger::new())),
+                       native_router: P2PGossipSync::new(network_graph, Some(Arc::new(ChainVerifier::new())), TestLogger::new()),
                        counter: RwLock::new(GossipCounter::new()),
                        sender
                }
index e9ca34307812d52d5ba1946f6264a93e8b107a8c..07a40c538756bd77df01b7ea64d5546a14bc9f7d 100644 (file)
@@ -41,7 +41,7 @@ mod hex_utils;
 mod verifier;
 
 pub struct RapidSyncProcessor {
-       network_graph: Arc<NetworkGraph<Arc<TestLogger>>>,
+       network_graph: Arc<NetworkGraph<TestLogger>>,
        pub initial_sync_complete: Arc<AtomicBool>,
 }
 
@@ -58,11 +58,10 @@ impl RapidSyncProcessor {
        pub fn new() -> Self {
                let logger = TestLogger::new();
                let mut initial_sync_complete = false;
-               let arc_logger = Arc::new(logger);
                let network_graph = if let Ok(file) = File::open(&config::network_graph_cache_path()) {
                        println!("Initializing from cached network graph…");
                        let mut buffered_reader = BufReader::new(file);
-                       let network_graph_result = NetworkGraph::read(&mut buffered_reader, Arc::clone(&arc_logger));
+                       let network_graph_result = NetworkGraph::read(&mut buffered_reader, logger);
                        if let Ok(network_graph) = network_graph_result {
                                initial_sync_complete = true;
                                network_graph.remove_stale_channels();
@@ -70,10 +69,10 @@ impl RapidSyncProcessor {
                                network_graph
                        } else {
                                println!("Initialization from cached network graph failed: {}", network_graph_result.err().unwrap());
-                               NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), arc_logger)
+                               NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), logger)
                        }
                } else {
-                       NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), arc_logger)
+                       NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), logger)
                };
                let arc_network_graph = Arc::new(network_graph);
                Self {
@@ -117,7 +116,7 @@ impl RapidSyncProcessor {
        }
 }
 
-async fn serialize_delta(network_graph: Arc<NetworkGraph<Arc<TestLogger>>>, last_sync_timestamp: u32, consider_intermediate_updates: bool) -> SerializedResponse {
+async fn serialize_delta(network_graph: Arc<NetworkGraph<TestLogger>>, last_sync_timestamp: u32, consider_intermediate_updates: bool) -> SerializedResponse {
        let (client, connection) = lookup::connect_to_db().await;
 
        tokio::spawn(async move {
index b6e46a35cd600354dd8d83f0f0d99ab3b389b5b2..0cca7c1b649ad891c8a64052297c62253000e0fc 100644 (file)
@@ -64,7 +64,7 @@ pub(super) async fn connect_to_db() -> (Client, Connection<Socket, NoTlsStream>)
 /// whether they had been seen before.
 /// Also include all announcements for which the first update was announced
 /// after `last_syc_timestamp`
-pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaSet, network_graph: Arc<NetworkGraph<Arc<TestLogger>>>, client: &Client, last_sync_timestamp: u32) {
+pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaSet, network_graph: Arc<NetworkGraph<TestLogger>>, client: &Client, last_sync_timestamp: u32) {
        let last_sync_timestamp_object = SystemTime::UNIX_EPOCH.add(Duration::from_secs(last_sync_timestamp as u64));
        println!("Obtaining channel ids from network graph");
        let channel_ids = {
index 820dda7e5f285f0f7c92fef5ce3ab6c9dac06a30..cd7ff400b2ca985eb4f54d0ecbb9abe5113bc1a8 100644 (file)
@@ -13,11 +13,11 @@ use crate::types::GossipMessage;
 pub(crate) struct GossipPersister {
        gossip_persistence_receiver: mpsc::Receiver<GossipMessage>,
        server_sync_completion_sender: mpsc::Sender<()>,
-       network_graph: Arc<NetworkGraph<Arc<TestLogger>>>,
+       network_graph: Arc<NetworkGraph<TestLogger>>,
 }
 
 impl GossipPersister {
-       pub fn new(server_sync_completion_sender: mpsc::Sender<()>, network_graph: Arc<NetworkGraph<Arc<TestLogger>>>) -> (Self, mpsc::Sender<GossipMessage>) {
+       pub fn new(server_sync_completion_sender: mpsc::Sender<()>, network_graph: Arc<NetworkGraph<TestLogger>>) -> (Self, mpsc::Sender<GossipMessage>) {
                let (gossip_persistence_sender, gossip_persistence_receiver) =
                        mpsc::channel::<GossipMessage>(100);
                (GossipPersister {
index ab664ca34836a74884adbc917b31af61e0ba96bb..9e633f2274a7aaae77967945790a642ddbc0552a 100644 (file)
@@ -9,11 +9,11 @@ use lightning::routing::gossip::NetworkGraph;
 use crate::{config, TestLogger};
 
 pub(crate) struct Snapshotter {
-       network_graph: Arc<NetworkGraph<Arc<TestLogger>>>,
+       network_graph: Arc<NetworkGraph<TestLogger>>,
 }
 
 impl Snapshotter {
-       pub fn new(network_graph: Arc<NetworkGraph<Arc<TestLogger>>>) -> Self {
+       pub fn new(network_graph: Arc<NetworkGraph<TestLogger>>) -> Self {
                Self { network_graph }
        }
 
index af24055151bd4d52df8d32fe363ac487899eedc7..672b75f3764fa5113afd0a98fa72c94a29f451f3 100644 (file)
@@ -16,7 +16,7 @@ use crate::{config, TestLogger};
 use crate::downloader::GossipRouter;
 use crate::types::{GossipMessage, GossipPeerManager};
 
-pub(crate) async fn download_gossip(persistence_sender: mpsc::Sender<GossipMessage>, network_graph: Arc<NetworkGraph<Arc<TestLogger>>>) {
+pub(crate) async fn download_gossip(persistence_sender: mpsc::Sender<GossipMessage>, network_graph: Arc<NetworkGraph<TestLogger>>) {
        let mut key = [0; 32];
        let mut random_data = [0; 32];
        thread_rng().fill_bytes(&mut key);
@@ -33,7 +33,7 @@ pub(crate) async fn download_gossip(persistence_sender: mpsc::Sender<GossipMessa
                message_handler,
                our_node_secret,
                &random_data,
-               Arc::new(TestLogger::new()),
+               TestLogger::new(),
                IgnoringMessageHandler {},
        ));
 
index 824896d5e623fe95533982bb59503c1e71585c78..9badc1e4c2abe5b87ba878b3d63a446461e8aed0 100644 (file)
@@ -1,4 +1,5 @@
 use std::sync::Arc;
+use std::ops::Deref;
 
 use lightning::ln::msgs::{ChannelAnnouncement, ChannelUpdate};
 use lightning::ln::peer_handler::{ErroringMessageHandler, IgnoringMessageHandler, PeerManager};
@@ -8,7 +9,7 @@ use crate::downloader::GossipRouter;
 use crate::verifier::ChainVerifier;
 
 pub(crate) type GossipChainAccess = Arc<ChainVerifier>;
-pub(crate) type GossipPeerManager = Arc<PeerManager<lightning_net_tokio::SocketDescriptor, ErroringMessageHandler, Arc<GossipRouter>, Arc<TestLogger>, IgnoringMessageHandler>>;
+pub(crate) type GossipPeerManager = Arc<PeerManager<lightning_net_tokio::SocketDescriptor, ErroringMessageHandler, Arc<GossipRouter>, TestLogger, IgnoringMessageHandler>>;
 
 #[derive(Debug)]
 pub(crate) enum GossipMessage {
@@ -17,7 +18,12 @@ pub(crate) enum GossipMessage {
        InitialSyncComplete,
 }
 
+#[derive(Clone, Copy)]
 pub(crate) struct TestLogger {}
+impl Deref for TestLogger {
+       type Target = Self;
+       fn deref(&self) -> &Self { self }
+}
 
 impl TestLogger {
        pub(crate) fn new() -> TestLogger {