From: Matt Corallo Date: Mon, 22 Aug 2022 03:22:09 +0000 (+0000) Subject: Drop Arcs around the TestLogger, as its an empty struct anyway X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=f42b4035894b74400b306abaf23afe74d9ece71a;p=rapid-gossip-sync-server Drop Arcs around the TestLogger, as its an empty struct anyway --- diff --git a/src/downloader.rs b/src/downloader.rs index 72e55c5..3e6f91e 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -30,16 +30,15 @@ impl GossipCounter { } pub(crate) struct GossipRouter { - native_router: P2PGossipSync>>, GossipChainAccess, Arc>, + native_router: P2PGossipSync>, GossipChainAccess, TestLogger>, pub(crate) counter: RwLock, sender: mpsc::Sender, } impl GossipRouter { - pub(crate) fn new(network_graph: Arc>>, sender: mpsc::Sender) -> Self { + pub(crate) fn new(network_graph: Arc>, sender: mpsc::Sender) -> 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 } diff --git a/src/lib.rs b/src/lib.rs index e9ca343..07a40c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ mod hex_utils; mod verifier; pub struct RapidSyncProcessor { - network_graph: Arc>>, + network_graph: Arc>, pub initial_sync_complete: Arc, } @@ -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>>, last_sync_timestamp: u32, consider_intermediate_updates: bool) -> SerializedResponse { +async fn serialize_delta(network_graph: Arc>, last_sync_timestamp: u32, consider_intermediate_updates: bool) -> SerializedResponse { let (client, connection) = lookup::connect_to_db().await; tokio::spawn(async move { diff --git a/src/lookup.rs b/src/lookup.rs index b6e46a3..0cca7c1 100644 --- a/src/lookup.rs +++ b/src/lookup.rs @@ -64,7 +64,7 @@ pub(super) async fn connect_to_db() -> (Client, Connection) /// 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>>, client: &Client, last_sync_timestamp: u32) { +pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaSet, network_graph: Arc>, 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 = { diff --git a/src/persistence.rs b/src/persistence.rs index 820dda7..cd7ff40 100644 --- a/src/persistence.rs +++ b/src/persistence.rs @@ -13,11 +13,11 @@ use crate::types::GossipMessage; pub(crate) struct GossipPersister { gossip_persistence_receiver: mpsc::Receiver, server_sync_completion_sender: mpsc::Sender<()>, - network_graph: Arc>>, + network_graph: Arc>, } impl GossipPersister { - pub fn new(server_sync_completion_sender: mpsc::Sender<()>, network_graph: Arc>>) -> (Self, mpsc::Sender) { + 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 { diff --git a/src/snapshot.rs b/src/snapshot.rs index ab664ca..9e633f2 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -9,11 +9,11 @@ use lightning::routing::gossip::NetworkGraph; use crate::{config, TestLogger}; pub(crate) struct Snapshotter { - network_graph: Arc>>, + network_graph: Arc>, } impl Snapshotter { - pub fn new(network_graph: Arc>>) -> Self { + pub fn new(network_graph: Arc>) -> Self { Self { network_graph } } diff --git a/src/tracking.rs b/src/tracking.rs index af24055..672b75f 100644 --- a/src/tracking.rs +++ b/src/tracking.rs @@ -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, network_graph: Arc>>) { +pub(crate) async fn download_gossip(persistence_sender: mpsc::Sender, network_graph: Arc>) { 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; -pub(crate) type GossipPeerManager = Arc, Arc, IgnoringMessageHandler>>; +pub(crate) type GossipPeerManager = Arc, 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 {