]> git.bitcoin.ninja Git - rapid-gossip-sync-server/commitdiff
Allow seen override for announcements.
authorArik Sosman <git@arik.io>
Sat, 4 Nov 2023 03:58:21 +0000 (20:58 -0700)
committerArik Sosman <git@arik.io>
Sat, 4 Nov 2023 04:17:43 +0000 (21:17 -0700)
src/persistence.rs

index 7b451b7ec252970050d908f231603730b13fd50a..4ede02f5258cac98cc977f71853f120d17e7aadf 100644 (file)
@@ -111,21 +111,34 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
                        }
 
                        match &gossip_message {
-                               GossipMessage::ChannelAnnouncement(announcement, _) => {
+                               GossipMessage::ChannelAnnouncement(announcement, seen_override) => {
                                        let scid = announcement.contents.short_channel_id as i64;
 
                                        // start with the type prefix, which is already known a priori
                                        let mut announcement_signed = Vec::new();
                                        announcement.write(&mut announcement_signed).unwrap();
 
-                                       tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
-                                               .execute("INSERT INTO channel_announcements (\
+                                       if cfg!(test) && seen_override.is_some() {
+                                               tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
+                                                       .execute("INSERT INTO channel_announcements (\
+                                                       short_channel_id, \
+                                                       announcement_signed, \
+                                                       seen \
+                                               ) VALUES ($1, $2, TO_TIMESTAMP($3)) ON CONFLICT (short_channel_id) DO NOTHING", &[
+                                                               &scid,
+                                                               &announcement_signed,
+                                                               &(seen_override.unwrap() as f64)
+                                                       ])).await.unwrap().unwrap();
+                                       } else {
+                                               tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
+                                                       .execute("INSERT INTO channel_announcements (\
                                                        short_channel_id, \
                                                        announcement_signed \
                                                ) VALUES ($1, $2) ON CONFLICT (short_channel_id) DO NOTHING", &[
-                                                       &scid,
-                                                       &announcement_signed
-                                               ])).await.unwrap().unwrap();
+                                                               &scid,
+                                                               &announcement_signed
+                                                       ])).await.unwrap().unwrap();
+                                       }
                                }
                                GossipMessage::ChannelUpdate(update, seen_override) => {
                                        let scid = update.contents.short_channel_id as i64;