X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fgossip.rs;h=1a5b978502c0922c651d6fd3175c67f7ff1897fd;hb=a03db3ca309413c3408f5971b5ed5a8020422a81;hp=f1a6ed9cecff571e6898b27dfabb828fa7fb5212;hpb=abf4e79dcda4c97dd80dd00233de32507184543a;p=rust-lightning diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index f1a6ed9c..1a5b9785 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -1541,6 +1541,14 @@ impl NetworkGraph where L::Target: Logger { #[cfg(not(feature = "std"))] let current_time_unix = None; + self.channel_failed_with_time(short_channel_id, is_permanent, current_time_unix) + } + + /// Marks a channel in the graph as failed if a corresponding HTLC fail was sent. + /// If permanent, removes a channel from the local storage. + /// May cause the removal of nodes too, if this was their last channel. + /// If not permanent, makes channels unavailable for routing. + fn channel_failed_with_time(&self, short_channel_id: u64, is_permanent: bool, current_time_unix: Option) { let mut channels = self.channels.write().unwrap(); if is_permanent { if let Some(chan) = channels.remove(&short_channel_id) { @@ -2538,18 +2546,18 @@ mod tests { // 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); + network_graph.channel_failed_with_time(short_channel_id, true, Some(tracking_time)); // 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); + assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1, "Removed channel count ≠ 1 with tracking_time {}", tracking_time); // 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()); + assert!(network_graph.removed_channels.lock().unwrap().is_empty(), "Unexpectedly removed channels with tracking_time {}", tracking_time); + assert!(network_graph.removed_nodes.lock().unwrap().is_empty(), "Unexpectedly removed nodes with tracking_time {}", tracking_time); } #[cfg(not(feature = "std"))]