Skip to content

Commit 6f4ab6f

Browse files
committed
Log per-channel lookup information.
1 parent 421487a commit 6f4ab6f

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/lookup.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use lightning::util::ser::Readable;
1010
use tokio_postgres::Client;
1111

1212
use futures::StreamExt;
13-
use lightning::log_info;
13+
use lightning::{log_info, log_trace};
1414
use lightning::util::logger::Logger;
1515

1616
use crate::config;
@@ -82,8 +82,9 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaS
8282
.map(|c| c.1.announcement_message.as_ref().unwrap().contents.short_channel_id as i64)
8383
.collect::<Vec<_>>()
8484
};
85-
#[cfg(test)]
86-
log_info!(logger, "Channel IDs: {:?}", channel_ids);
85+
if cfg!(test) {
86+
log_info!(logger, "Channel IDs: {:?}", channel_ids);
87+
}
8788
log_info!(logger, "Last sync timestamp: {}", last_sync_timestamp);
8889
let last_sync_timestamp_float = last_sync_timestamp as f64;
8990

@@ -112,6 +113,22 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaS
112113
}
113114
log_info!(logger, "Fetched {} announcement rows", announcement_count);
114115

116+
if cfg!(test) {
117+
// THIS STEP IS USED TO DEBUG THE NUMBER OF ROWS WHEN TESTING
118+
let update_rows = client.query("SELECT * FROM channel_updates", &[]).await.unwrap();
119+
log_info!(logger, "Fetched {} update rows", update_rows.len());
120+
121+
let update_rows = client.query("SELECT * FROM channel_updates WHERE short_channel_id = any($1)", &[&channel_ids]).await.unwrap();
122+
log_info!(logger, "Fetched {} update rows with filtered channels", update_rows.len());
123+
124+
// let timestamp_string = format!("{}", last_sync_timestamp);
125+
let update_rows = client.query("SELECT * FROM channel_updates WHERE seen >= TO_TIMESTAMP($1)", &[&last_sync_timestamp_float]).await.unwrap();
126+
log_info!(logger, "Fetched {} update rows with filtered seen", update_rows.len());
127+
128+
let update_rows = client.query("SELECT * FROM channel_updates WHERE short_channel_id = any($1) AND seen >= TO_TIMESTAMP($2)", &[&channel_ids, &last_sync_timestamp_float]).await.unwrap();
129+
log_info!(logger, "Fetched {} update rows with filtered channels and seen", update_rows.len());
130+
}
131+
115132
{
116133
// THIS STEP IS USED TO DETERMINE IF A CHANNEL SHOULD BE OMITTED FROM THE DELTA
117134

@@ -147,6 +164,8 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaS
147164
let scid: i64 = current_row.get("short_channel_id");
148165
let current_seen_timestamp = current_row.get::<_, i64>("seen") as u32;
149166

167+
log_trace!(logger, "Channel {} first update to complete bidirectional data seen at: {}", scid, current_seen_timestamp);
168+
150169
// the newer of the two oldest seen directional updates came after last sync timestamp
151170
let current_channel_delta = delta_set.entry(scid as u64).or_insert(ChannelDelta::default());
152171
// first time a channel was seen in both directions
@@ -188,6 +207,8 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaS
188207
let current_row = row_res.unwrap();
189208
let scid: i64 = current_row.get("short_channel_id");
190209

210+
log_trace!(logger, "Channel {} with newest update in less recently updated direction being at least 6 days ago", scid);
211+
191212
// annotate this channel as requiring that reminders be sent to the client
192213
let current_channel_delta = delta_set.entry(scid as u64).or_insert(ChannelDelta::default());
193214

@@ -217,7 +238,7 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaS
217238
}
218239
older_latest_directional_update_count += 1;
219240
}
220-
log_info!(logger, "Fetched {} update rows of the latest update in the less recently updated direction", older_latest_directional_update_count);
241+
log_info!(logger, "Fetched {} update rows of the latest update in the less recently updated direction being more than six days ago", older_latest_directional_update_count);
221242
}
222243
}
223244

@@ -267,7 +288,9 @@ pub(super) async fn fetch_channel_updates<L: Deref>(delta_set: &mut DeltaSet, cl
267288
} else {
268289
(*current_channel_delta).updates.1.get_or_insert(DirectedUpdateDelta::default())
269290
};
291+
log_trace!(logger, "Channel {} last update before seen: {}/{}/{}", scid, update_id, direction, unsigned_channel_update.timestamp);
270292
update_delta.last_update_before_seen = Some(unsigned_channel_update);
293+
271294
reference_row_count += 1;
272295
}
273296

@@ -328,12 +351,14 @@ pub(super) async fn fetch_channel_updates<L: Deref>(delta_set: &mut DeltaSet, cl
328351
seen: current_seen_timestamp,
329352
update: unsigned_channel_update.clone(),
330353
});
354+
log_trace!(logger, "Channel {} latest update in direction 0: {} (seen: {})", scid, unsigned_channel_update.timestamp, current_seen_timestamp)
331355
} else if direction && !previously_seen_directions.1 {
332356
previously_seen_directions.1 = true;
333357
update_delta.latest_update_after_seen = Some(UpdateDelta {
334358
seen: current_seen_timestamp,
335359
update: unsigned_channel_update.clone(),
336360
});
361+
log_trace!(logger, "Channel {} latest update in direction 1: {} (seen: {})", scid, unsigned_channel_update.timestamp, current_seen_timestamp)
337362
}
338363
}
339364

0 commit comments

Comments
 (0)