@@ -212,7 +212,7 @@ pub enum NetworkUpdate {
212212 msg : ChannelUpdate ,
213213 } ,
214214 /// An error indicating that a channel failed to route a payment, which should be applied via
215- /// [`NetworkGraph::channel_failed`] .
215+ /// [`NetworkGraph::channel_failed_permanent`] if permanent .
216216 ChannelFailure {
217217 /// The short channel id of the closed channel.
218218 short_channel_id : u64 ,
@@ -352,9 +352,10 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
352352 let _ = self . update_channel ( msg) ;
353353 } ,
354354 NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent } => {
355- let action = if is_permanent { "Removing" } else { "Disabling" } ;
356- log_debug ! ( self . logger, "{} channel graph entry for {} due to a payment failure." , action, short_channel_id) ;
357- self . channel_failed ( short_channel_id, is_permanent) ;
355+ if is_permanent {
356+ log_debug ! ( self . logger, "Removing channel graph entry for {} due to a payment failure." , short_channel_id) ;
357+ self . channel_failed_permanent ( short_channel_id) ;
358+ }
358359 } ,
359360 NetworkUpdate :: NodeFailure { ref node_id, is_permanent } => {
360361 if is_permanent {
@@ -1632,40 +1633,27 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
16321633 Ok ( ( ) )
16331634 }
16341635
1635- /// Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
1636- /// If permanent, removes a channel from the local storage.
1637- /// May cause the removal of nodes too, if this was their last channel.
1638- /// If not permanent, makes channels unavailable for routing.
1639- pub fn channel_failed ( & self , short_channel_id : u64 , is_permanent : bool ) {
1636+ /// Marks a channel in the graph as failed permanently.
1637+ ///
1638+ /// The channel and any node for which this was their last channel are removed from the graph.
1639+ pub fn channel_failed_permanent ( & self , short_channel_id : u64 ) {
16401640 #[ cfg( feature = "std" ) ]
16411641 let current_time_unix = Some ( SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) ) ;
16421642 #[ cfg( not( feature = "std" ) ) ]
16431643 let current_time_unix = None ;
16441644
1645- self . channel_failed_with_time ( short_channel_id, is_permanent , current_time_unix)
1645+ self . channel_failed_permanent_with_time ( short_channel_id, current_time_unix)
16461646 }
16471647
1648- /// Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
1649- /// If permanent, removes a channel from the local storage.
1650- /// May cause the removal of nodes too, if this was their last channel.
1651- /// If not permanent, makes channels unavailable for routing.
1652- fn channel_failed_with_time ( & self , short_channel_id : u64 , is_permanent : bool , current_time_unix : Option < u64 > ) {
1648+ /// Marks a channel in the graph as failed permanently.
1649+ ///
1650+ /// The channel and any node for which this was their last channel are removed from the graph.
1651+ fn channel_failed_permanent_with_time ( & self , short_channel_id : u64 , current_time_unix : Option < u64 > ) {
16531652 let mut channels = self . channels . write ( ) . unwrap ( ) ;
1654- if is_permanent {
1655- if let Some ( chan) = channels. remove ( & short_channel_id) {
1656- let mut nodes = self . nodes . write ( ) . unwrap ( ) ;
1657- self . removed_channels . lock ( ) . unwrap ( ) . insert ( short_channel_id, current_time_unix) ;
1658- Self :: remove_channel_in_nodes ( & mut nodes, & chan, short_channel_id) ;
1659- }
1660- } else {
1661- if let Some ( chan) = channels. get_mut ( & short_channel_id) {
1662- if let Some ( one_to_two) = chan. one_to_two . as_mut ( ) {
1663- one_to_two. enabled = false ;
1664- }
1665- if let Some ( two_to_one) = chan. two_to_one . as_mut ( ) {
1666- two_to_one. enabled = false ;
1667- }
1668- }
1653+ if let Some ( chan) = channels. remove ( & short_channel_id) {
1654+ let mut nodes = self . nodes . write ( ) . unwrap ( ) ;
1655+ self . removed_channels . lock ( ) . unwrap ( ) . insert ( short_channel_id, current_time_unix) ;
1656+ Self :: remove_channel_in_nodes ( & mut nodes, & chan, short_channel_id) ;
16691657 }
16701658 }
16711659
@@ -2450,7 +2438,7 @@ pub(crate) mod tests {
24502438 assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_some( ) ) ;
24512439 }
24522440
2453- // Non-permanent closing just disables a channel
2441+ // Non-permanent failure doesn't touch the channel at all
24542442 {
24552443 match network_graph. read_only ( ) . channels ( ) . get ( & short_channel_id) {
24562444 None => panic ! ( ) ,
@@ -2467,7 +2455,7 @@ pub(crate) mod tests {
24672455 match network_graph. read_only ( ) . channels ( ) . get ( & short_channel_id) {
24682456 None => panic ! ( ) ,
24692457 Some ( channel_info) => {
2470- assert ! ( ! channel_info. one_to_two. as_ref( ) . unwrap( ) . enabled) ;
2458+ assert ! ( channel_info. one_to_two. as_ref( ) . unwrap( ) . enabled) ;
24712459 }
24722460 } ;
24732461 }
@@ -2601,7 +2589,7 @@ pub(crate) mod tests {
26012589
26022590 // Mark the channel as permanently failed. This will also remove the two nodes
26032591 // and all of the entries will be tracked as removed.
2604- network_graph. channel_failed_with_time ( short_channel_id, true , Some ( tracking_time) ) ;
2592+ network_graph. channel_failed_permanent_with_time ( short_channel_id, Some ( tracking_time) ) ;
26052593
26062594 // Should not remove from tracking if insufficient time has passed
26072595 network_graph. remove_stale_channels_and_tracking_with_time (
@@ -2634,7 +2622,7 @@ pub(crate) mod tests {
26342622
26352623 // Mark the channel as permanently failed. This will also remove the two nodes
26362624 // and all of the entries will be tracked as removed.
2637- network_graph. channel_failed ( short_channel_id, true ) ;
2625+ network_graph. channel_failed_permanent ( short_channel_id) ;
26382626
26392627 // The first time we call the following, the channel will have a removal time assigned.
26402628 network_graph. remove_stale_channels_and_tracking_with_time ( removal_time) ;
0 commit comments