Skip to content

Commit ac1c21f

Browse files
committed
Track the time a stale channel was pruned
1 parent a150dbf commit ac1c21f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lightning/src/routing/gossip.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
17041704
for scid in scids_to_remove {
17051705
let info = channels.remove(&scid).expect("We just accessed this scid, it should be present");
17061706
Self::remove_channel_in_nodes(&mut nodes, &info, scid);
1707+
self.removed_channels.lock().unwrap().insert(scid, Some(current_time_unix));
17071708
}
17081709
}
17091710

@@ -2578,6 +2579,16 @@ mod tests {
25782579
assert_eq!(network_graph.read_only().nodes().len(), 2);
25792580

25802581
network_graph.remove_stale_channels_and_tracking_with_time(101 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS);
2582+
2583+
#[cfg(not(feature = "std"))]
2584+
{
2585+
// Make sure removed channels are tracked.
2586+
assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1);
2587+
// Provide a later time so that sufficient time has passed
2588+
network_graph.remove_stale_channels_and_tracking_with_time(101 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS +
2589+
REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS);
2590+
}
2591+
25812592
#[cfg(feature = "std")]
25822593
{
25832594
// In std mode, a further check is performed before fully removing the channel -
@@ -2598,10 +2609,16 @@ mod tests {
25982609
assert!(gossip_sync.handle_channel_update(&valid_channel_update).is_ok());
25992610
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_some());
26002611
network_graph.remove_stale_channels_and_tracking_with_time(announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS);
2612+
// Make sure removed channels are tracked.
2613+
assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1);
2614+
// Provide a later time so that sufficient time has passed
2615+
network_graph.remove_stale_channels_and_tracking_with_time(announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS +
2616+
REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS);
26012617
}
26022618

26032619
assert_eq!(network_graph.read_only().channels().len(), 0);
26042620
assert_eq!(network_graph.read_only().nodes().len(), 0);
2621+
assert!(network_graph.removed_channels.lock().unwrap().is_empty());
26052622

26062623
#[cfg(feature = "std")]
26072624
{

0 commit comments

Comments
 (0)