+ assert!(network_graph.removed_channels.lock().unwrap().is_empty());
+
+ #[cfg(feature = "std")]
+ {
+ use std::time::{SystemTime, UNIX_EPOCH};
+
+ let tracking_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs();
+
+ // Clear tracked nodes and channels for clean slate
+ network_graph.removed_channels.lock().unwrap().clear();
+ network_graph.removed_nodes.lock().unwrap().clear();
+
+ // Add a channel and nodes from channel announcement. So our network graph will
+ // now only consist of two nodes and one channel between them.
+ assert!(network_graph.update_channel_from_announcement(
+ &valid_channel_announcement, &chain_source).is_ok());
+
+ // Mark the channel as permanently failed. This will also remove the two nodes
+ // and all of the entries will be tracked as removed.
+ network_graph.channel_failed(short_channel_id, true);
+
+ // Should not remove from tracking if insufficient time has passed
+ network_graph.remove_stale_channels_and_tracking_with_time(
+ tracking_time + REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS - 1);
+ assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1);
+
+ // Provide a later time so that sufficient time has passed
+ network_graph.remove_stale_channels_and_tracking_with_time(
+ tracking_time + REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS);
+ assert!(network_graph.removed_channels.lock().unwrap().is_empty());
+ assert!(network_graph.removed_nodes.lock().unwrap().is_empty());
+ }
+
+ #[cfg(not(feature = "std"))]
+ {
+ // When we don't have access to the system clock, the time we started tracking removal will only
+ // be that provided by the first call to `remove_stale_channels_and_tracking_with_time`. Hence,
+ // only if sufficient time has passed after that first call, will the next call remove it from
+ // tracking.
+ let removal_time = 1664619654;
+
+ // Clear removed nodes and channels for clean slate
+ network_graph.removed_channels.lock().unwrap().clear();
+ network_graph.removed_nodes.lock().unwrap().clear();
+
+ // Add a channel and nodes from channel announcement. So our network graph will
+ // now only consist of two nodes and one channel between them.
+ assert!(network_graph.update_channel_from_announcement(
+ &valid_channel_announcement, &chain_source).is_ok());
+
+ // Mark the channel as permanently failed. This will also remove the two nodes
+ // and all of the entries will be tracked as removed.
+ network_graph.channel_failed(short_channel_id, true);
+
+ // The first time we call the following, the channel will have a removal time assigned.
+ network_graph.remove_stale_channels_and_tracking_with_time(removal_time);
+ assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1);
+
+ // Provide a later time so that sufficient time has passed
+ network_graph.remove_stale_channels_and_tracking_with_time(
+ removal_time + REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS);
+ assert!(network_graph.removed_channels.lock().unwrap().is_empty());
+ assert!(network_graph.removed_nodes.lock().unwrap().is_empty());
+ }