From: Arik Sosman Date: Sat, 4 Nov 2023 03:58:21 +0000 (-0700) Subject: Allow seen override for announcements. X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=552226b489dc26366c2da87a9b7223821e19a204;p=rapid-gossip-sync-server Allow seen override for announcements. --- 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;