From 552226b489dc26366c2da87a9b7223821e19a204 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Fri, 3 Nov 2023 20:58:21 -0700 Subject: [PATCH] Allow seen override for announcements. --- src/persistence.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/persistence.rs b/src/persistence.rs index 7b451b7..4ede02f 100644 --- a/src/persistence.rs +++ b/src/persistence.rs @@ -111,21 +111,34 @@ impl GossipPersister 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; -- 2.39.5