Allow custom logger types.
[rapid-gossip-sync-server] / src / lookup.rs
index 04e46bd0d8ec9f1292445605085e659c5dc3c95b..79fb84e8d599ca4d993fc8ab4bb955cb3cf2648b 100644 (file)
@@ -11,8 +11,9 @@ use tokio_postgres::{Client, Connection, NoTls, Socket};
 use tokio_postgres::tls::NoTlsStream;
 
 use futures::StreamExt;
+use lightning::util::logger::Logger;
 
-use crate::{config, TestLogger};
+use crate::config;
 use crate::serialization::MutatedProperties;
 
 /// The delta set needs to be a BTreeMap so the keys are sorted.
@@ -75,7 +76,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_sync_timestamp`
-pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaSet, network_graph: Arc<NetworkGraph<TestLogger>>, client: &Client, last_sync_timestamp: u32) {
+pub(super) async fn fetch_channel_announcements<L: Logger>(delta_set: &mut DeltaSet, network_graph: Arc<NetworkGraph<Arc<L>>>, client: &Client, last_sync_timestamp: u32) {
        println!("Obtaining channel ids from network graph");
        let last_sync_timestamp_object = SystemTime::UNIX_EPOCH.add(Duration::from_secs(last_sync_timestamp as u64));
        let channel_ids = {
@@ -160,7 +161,6 @@ pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaSet, networ
                // — Obtain all updates, distinct by (scid, direction), ordered by seen DESC
                // — From those updates, select distinct by (scid), ordered by seen ASC (to obtain the older one per direction)
                let reminder_threshold_timestamp = SystemTime::now().checked_sub(config::CHANNEL_REMINDER_AGE).unwrap();
-               let read_only_graph = network_graph.read_only();
 
                let params: [&(dyn tokio_postgres::types::ToSql + Sync); 2] =
                        [&channel_ids, &reminder_threshold_timestamp];
@@ -189,7 +189,7 @@ pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaSet, networ
                        // way might be able to get away with not using this
                        (*current_channel_delta).requires_reminder = true;
 
-                       if let Some(current_channel_info) = read_only_graph.channel(scid as u64) {
+                       if let Some(current_channel_info) = network_graph.read_only().channel(scid as u64) {
                                if current_channel_info.one_to_two.is_none() || current_channel_info.two_to_one.is_none() {
                                        // we don't send reminders if we don't have bidirectional update data
                                        continue;
@@ -226,12 +226,12 @@ pub(super) async fn fetch_channel_updates(delta_set: &mut DeltaSet, client: &Cli
                WHERE id IN (
                        SELECT DISTINCT ON (short_channel_id, direction) id
                        FROM channel_updates
-                       WHERE seen < $1
+                       WHERE seen < $1 AND short_channel_id IN (
+                               SELECT DISTINCT ON (short_channel_id) short_channel_id
+                               FROM channel_updates
+                               WHERE seen >= $1
+                       )
                        ORDER BY short_channel_id ASC, direction ASC, seen DESC
-               ) AND short_channel_id IN (
-                       SELECT DISTINCT ON (short_channel_id) short_channel_id
-                       FROM channel_updates
-                       WHERE seen >= $1
                )
                ", [last_sync_timestamp_object]).await.unwrap();
        let mut pinned_rows = Box::pin(reference_rows);