Skip to content

Commit 63edf99

Browse files
committed
Add second value to announcement tuple to allow overriding the Postgres-default seen timestamp.
1 parent 3f97cb3 commit 63edf99

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/downloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<L: Deref + Clone + Send + Sync> GossipRouter<L> where L::Target: Logger {
6262
counter.channel_announcements += 1;
6363
}
6464

65-
let gossip_message = GossipMessage::ChannelAnnouncement(msg);
65+
let gossip_message = GossipMessage::ChannelAnnouncement(msg, None);
6666
if let Err(err) = self.sender.try_send(gossip_message) {
6767
let gossip_message = match err { TrySendError::Full(msg)|TrySendError::Closed(msg) => msg };
6868
tokio::task::block_in_place(move || { tokio::runtime::Handle::current().block_on(async move {

src/persistence.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,34 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
115115
}
116116

117117
match &gossip_message {
118-
GossipMessage::ChannelAnnouncement(announcement) => {
118+
GossipMessage::ChannelAnnouncement(announcement, timestamp) => {
119119
let scid = announcement.contents.short_channel_id as i64;
120120

121121
// start with the type prefix, which is already known a priori
122122
let mut announcement_signed = Vec::new();
123123
announcement.write(&mut announcement_signed).unwrap();
124124

125-
tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
126-
.execute("INSERT INTO channel_announcements (\
125+
if let Some(timestamp) = timestamp {
126+
tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
127+
.execute("INSERT INTO channel_announcements (\
128+
short_channel_id, \
129+
announcement_signed, \
130+
seen \
131+
) VALUES ($1, $2, TO_TIMESTAMP($3)) ON CONFLICT (short_channel_id) DO NOTHING", &[
132+
&scid,
133+
&announcement_signed,
134+
&(*timestamp as f64)
135+
])).await.unwrap().unwrap();
136+
} else {
137+
tokio::time::timeout(POSTGRES_INSERT_TIMEOUT, client
138+
.execute("INSERT INTO channel_announcements (\
127139
short_channel_id, \
128140
announcement_signed \
129141
) VALUES ($1, $2) ON CONFLICT (short_channel_id) DO NOTHING", &[
130-
&scid,
131-
&announcement_signed
132-
])).await.unwrap().unwrap();
142+
&scid,
143+
&announcement_signed
144+
])).await.unwrap().unwrap();
145+
}
133146
}
134147
GossipMessage::ChannelUpdate(update) => {
135148
let scid = update.contents.short_channel_id as i64;

src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async fn test_trivial_setup() {
125125
network_graph_arc.update_channel_unsigned(&update_1.contents).unwrap();
126126
network_graph_arc.update_channel_unsigned(&update_2.contents).unwrap();
127127

128-
receiver.send(GossipMessage::ChannelAnnouncement(announcement)).await.unwrap();
128+
receiver.send(GossipMessage::ChannelAnnouncement(announcement, Some(timestamp))).await.unwrap();
129129
receiver.send(GossipMessage::ChannelUpdate(update_1)).await.unwrap();
130130
receiver.send(GossipMessage::ChannelUpdate(update_2)).await.unwrap();
131131
drop(receiver);

src/types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ pub(crate) type GossipPeerManager<L> = Arc<PeerManager<lightning_net_tokio::Sock
1414

1515
#[derive(Debug)]
1616
pub(crate) enum GossipMessage {
17-
ChannelAnnouncement(ChannelAnnouncement),
17+
ChannelAnnouncement(
18+
ChannelAnnouncement,
19+
Option<u32> // optionally include a persistence timestamp
20+
),
1821
ChannelUpdate(ChannelUpdate),
1922
}
2023

0 commit comments

Comments
 (0)