+ {
+ // THIS STEP IS USED TO DETERMINE IF A REMINDER UPDATE SHOULD BE SENT
+
+ println!("Annotating channel announcements whose latest channel update in a given direction occurred more than six days ago");
+ // Steps:
+ // — Obtain all updates, distinct by (scid, direction), ordered by seen DESC
+ // — From those updates, select distinct by (scid), ordered by seen ASC (to obtain the older one per direction)
+ let reminder_threshold_timestamp = SystemTime::now().checked_sub(config::CHANNEL_REMINDER_AGE).unwrap();
+
+ let params: [&(dyn tokio_postgres::types::ToSql + Sync); 2] =
+ [&channel_ids, &reminder_threshold_timestamp];
+ let older_latest_directional_updates = client.query_raw("
+ SELECT short_channel_id FROM (
+ SELECT DISTINCT ON (short_channel_id) *
+ FROM (
+ SELECT DISTINCT ON (short_channel_id, direction) short_channel_id, seen
+ FROM channel_updates
+ WHERE short_channel_id = any($1)
+ ORDER BY short_channel_id ASC, direction ASC, seen DESC
+ ) AS directional_last_seens
+ ORDER BY short_channel_id ASC, seen ASC
+ ) AS distinct_chans
+ WHERE distinct_chans.seen <= $2
+ ", params).await.unwrap();
+ let mut pinned_updates = Box::pin(older_latest_directional_updates);
+
+ while let Some(row_res) = pinned_updates.next().await {
+ let current_row = row_res.unwrap();
+ let scid: i64 = current_row.get("short_channel_id");
+
+ // annotate this channel as requiring that reminders be sent to the client
+ let current_channel_delta = delta_set.entry(scid as u64).or_insert(ChannelDelta::default());
+
+ // way might be able to get away with not using this
+ (*current_channel_delta).requires_reminder = true;
+
+ if let Some(current_channel_info) = network_graph.read_only().channel(scid as u64) {
+ if current_channel_info.one_to_two.is_none() || current_channel_info.two_to_one.is_none() {
+ // we don't send reminders if we don't have bidirectional update data
+ continue;
+ }
+
+ if let Some(info) = current_channel_info.one_to_two.as_ref() {
+ let flags: u8 = if info.enabled { 0 } else { 2 };
+ let current_update = (*current_channel_delta).updates.0.get_or_insert(DirectedUpdateDelta::default());
+ current_update.serialization_update_flags = Some(flags);
+ }
+
+ if let Some(info) = current_channel_info.two_to_one.as_ref() {
+ let flags: u8 = if info.enabled { 1 } else { 3 };
+ let current_update = (*current_channel_delta).updates.1.get_or_insert(DirectedUpdateDelta::default());
+ current_update.serialization_update_flags = Some(flags);
+ }
+ } else {
+ // we don't send reminders if we don't have the channel
+ continue;
+ }
+ }