@@ -1541,6 +1541,14 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
15411541 #[ cfg( not( feature = "std" ) ) ]
15421542 let current_time_unix = None ;
15431543
1544+ self . channel_failed_with_time ( short_channel_id, is_permanent, current_time_unix)
1545+ }
1546+
1547+ /// Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
1548+ /// If permanent, removes a channel from the local storage.
1549+ /// May cause the removal of nodes too, if this was their last channel.
1550+ /// If not permanent, makes channels unavailable for routing.
1551+ fn channel_failed_with_time ( & self , short_channel_id : u64 , is_permanent : bool , current_time_unix : Option < u64 > ) {
15441552 let mut channels = self . channels . write ( ) . unwrap ( ) ;
15451553 if is_permanent {
15461554 if let Some ( chan) = channels. remove ( & short_channel_id) {
@@ -2537,18 +2545,18 @@ mod tests {
25372545
25382546 // Mark the channel as permanently failed. This will also remove the two nodes
25392547 // and all of the entries will be tracked as removed.
2540- network_graph. channel_failed ( short_channel_id, true ) ;
2548+ network_graph. channel_failed_with_time ( short_channel_id, true , Some ( tracking_time ) ) ;
25412549
25422550 // Should not remove from tracking if insufficient time has passed
25432551 network_graph. remove_stale_channels_and_tracking_with_time (
25442552 tracking_time + REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS - 1 ) ;
2545- assert_eq ! ( network_graph. removed_channels. lock( ) . unwrap( ) . len( ) , 1 ) ;
2553+ assert_eq ! ( network_graph. removed_channels. lock( ) . unwrap( ) . len( ) , 1 , "Removed channel count ≠ 1 with tracking_time {}" , tracking_time ) ;
25462554
25472555 // Provide a later time so that sufficient time has passed
25482556 network_graph. remove_stale_channels_and_tracking_with_time (
25492557 tracking_time + REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS ) ;
2550- assert ! ( network_graph. removed_channels. lock( ) . unwrap( ) . is_empty( ) ) ;
2551- assert ! ( network_graph. removed_nodes. lock( ) . unwrap( ) . is_empty( ) ) ;
2558+ assert ! ( network_graph. removed_channels. lock( ) . unwrap( ) . is_empty( ) , "Unexpectedly removed channels with tracking_time {}" , tracking_time ) ;
2559+ assert ! ( network_graph. removed_nodes. lock( ) . unwrap( ) . is_empty( ) , "Unexpectedly removed nodes with tracking_time {}" , tracking_time ) ;
25522560 }
25532561
25542562 #[ cfg( not( feature = "std" ) ) ]
0 commit comments