]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Allow setting custom gossip seen timestamps.
authorArik Sosman <git@arik.io>
Sat, 14 Oct 2023 01:39:27 +0000 (18:39 -0700)
committerArik Sosman <git@arik.io>
Thu, 19 Oct 2023 19:24:38 +0000 (12:24 -0700)
src/downloader.rs
src/persistence.rs
src/tests/mod.rs
src/types.rs

index 8d5cdb0005e7d8e3ea74f5036ee6c20220a9729e..af854c8317d059444b9ee2df6598bb1edbeeccb7 100644 (file)
@@ -62,7 +62,7 @@ impl<L: Deref + Clone + Send + Sync> GossipRouter<L> where L::Target: Logger {
                        counter.channel_announcements += 1;
                }
 
-               let gossip_message = GossipMessage::ChannelAnnouncement(msg);
+               let gossip_message = GossipMessage::ChannelAnnouncement(msg, None);
                if let Err(err) = self.sender.try_send(gossip_message) {
                        let gossip_message = match err { TrySendError::Full(msg)|TrySendError::Closed(msg) => msg };
                        tokio::task::block_in_place(move || { tokio::runtime::Handle::current().block_on(async move {
@@ -73,7 +73,7 @@ impl<L: Deref + Clone + Send + Sync> GossipRouter<L> where L::Target: Logger {
 
        fn new_channel_update(&self, msg: ChannelUpdate) {
                self.counter.write().unwrap().channel_updates += 1;
-               let gossip_message = GossipMessage::ChannelUpdate(msg);
+               let gossip_message = GossipMessage::ChannelUpdate(msg, None);
 
                if let Err(err) = self.sender.try_send(gossip_message) {
                        let gossip_message = match err { TrySendError::Full(msg)|TrySendError::Closed(msg) => msg };
index 8bb7b188af72fb692aa218a20b1ede9bd24c116a..7b451b7ec252970050d908f231603730b13fd50a 100644 (file)
@@ -111,7 +111,7 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
                        }
 
                        match &gossip_message {
-                               GossipMessage::ChannelAnnouncement(announcement) => {
+                               GossipMessage::ChannelAnnouncement(announcement, _) => {
                                        let scid = announcement.contents.short_channel_id as i64;
 
                                        // start with the type prefix, which is already known a priori
@@ -127,7 +127,7 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
                                                        &announcement_signed
                                                ])).await.unwrap().unwrap();
                                }
-                               GossipMessage::ChannelUpdate(update) => {
+                               GossipMessage::ChannelUpdate(update, seen_override) => {
                                        let scid = update.contents.short_channel_id as i64;
 
                                        let timestamp = update.contents.timestamp as i64;
@@ -146,10 +146,11 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
                                        let mut update_signed = Vec::new();
                                        update.write(&mut update_signed).unwrap();
 
-                                       tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
-                                               .execute("INSERT INTO channel_updates (\
+                                       let insertion_statement = if cfg!(test) {
+                                               "INSERT INTO channel_updates (\
                                                        short_channel_id, \
                                                        timestamp, \
+                                                       seen, \
                                                        channel_flags, \
                                                        direction, \
                                                        disable, \
@@ -159,9 +160,32 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
                                                        fee_proportional_millionths, \
                                                        htlc_maximum_msat, \
                                                        blob_signed \
-                                               ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)  ON CONFLICT DO NOTHING", &[
+                                               ) VALUES ($1, $2, TO_TIMESTAMP($3), $4, $5, $6, $7, $8, $9, $10, $11, $12)  ON CONFLICT DO NOTHING"
+                                       } else {
+                                               "INSERT INTO channel_updates (\
+                                                       short_channel_id, \
+                                                       timestamp, \
+                                                       channel_flags, \
+                                                       direction, \
+                                                       disable, \
+                                                       cltv_expiry_delta, \
+                                                       htlc_minimum_msat, \
+                                                       fee_base_msat, \
+                                                       fee_proportional_millionths, \
+                                                       htlc_maximum_msat, \
+                                                       blob_signed \
+                                               ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)  ON CONFLICT DO NOTHING"
+                                       };
+
+                                       // this may not be used outside test cfg
+                                       let _seen_timestamp = seen_override.unwrap_or(timestamp as u32) as f64;
+
+                                       tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
+                                               .execute(insertion_statement, &[
                                                        &scid,
                                                        &timestamp,
+                                                       #[cfg(test)]
+                                                               &_seen_timestamp,
                                                        &(update.contents.flags as i16),
                                                        &direction,
                                                        &disable,
index 09147e920b501fd735ee7016c41a90da055b794b..f26cea8b44f180f3756b632e827c393fe857a57d 100644 (file)
@@ -168,9 +168,9 @@ async fn test_trivial_setup() {
                network_graph_arc.update_channel_unsigned(&update_1.contents).unwrap();
                network_graph_arc.update_channel_unsigned(&update_2.contents).unwrap();
 
-               receiver.send(GossipMessage::ChannelAnnouncement(announcement)).await.unwrap();
-               receiver.send(GossipMessage::ChannelUpdate(update_1)).await.unwrap();
-               receiver.send(GossipMessage::ChannelUpdate(update_2)).await.unwrap();
+               receiver.send(GossipMessage::ChannelAnnouncement(announcement, None)).await.unwrap();
+               receiver.send(GossipMessage::ChannelUpdate(update_1, None)).await.unwrap();
+               receiver.send(GossipMessage::ChannelUpdate(update_2, None)).await.unwrap();
                drop(receiver);
                persister.persist_gossip().await;
        }
index f530bd41a112e41e082079e20fce4f19295c3877..93527a45b837c7368d9bc2842167323ff4c2e397 100644 (file)
@@ -14,8 +14,9 @@ pub(crate) type GossipPeerManager<L> = Arc<PeerManager<lightning_net_tokio::Sock
 
 #[derive(Debug)]
 pub(crate) enum GossipMessage {
-       ChannelAnnouncement(ChannelAnnouncement),
-       ChannelUpdate(ChannelUpdate),
+       // the second element is an optional override for the seen value
+       ChannelAnnouncement(ChannelAnnouncement, Option<u32>),
+       ChannelUpdate(ChannelUpdate, Option<u32>),
 }
 
 #[derive(Clone, Copy)]