@@ -212,7 +212,7 @@ pub enum NetworkUpdate {
212
212
msg : ChannelUpdate ,
213
213
} ,
214
214
/// 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 .
216
216
ChannelFailure {
217
217
/// The short channel id of the closed channel.
218
218
short_channel_id : u64 ,
@@ -352,9 +352,10 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
352
352
let _ = self . update_channel ( msg) ;
353
353
} ,
354
354
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
+ }
358
359
} ,
359
360
NetworkUpdate :: NodeFailure { ref node_id, is_permanent } => {
360
361
if is_permanent {
@@ -1632,40 +1633,27 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1632
1633
Ok ( ( ) )
1633
1634
}
1634
1635
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 ) {
1640
1640
#[ cfg( feature = "std" ) ]
1641
1641
let current_time_unix = Some ( SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) ) ;
1642
1642
#[ cfg( not( feature = "std" ) ) ]
1643
1643
let current_time_unix = None ;
1644
1644
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)
1646
1646
}
1647
1647
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 > ) {
1653
1652
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) ;
1669
1657
}
1670
1658
}
1671
1659
@@ -2450,7 +2438,7 @@ pub(crate) mod tests {
2450
2438
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_some( ) ) ;
2451
2439
}
2452
2440
2453
- // Non-permanent closing just disables a channel
2441
+ // Non-permanent failure doesn't touch the channel at all
2454
2442
{
2455
2443
match network_graph. read_only ( ) . channels ( ) . get ( & short_channel_id) {
2456
2444
None => panic ! ( ) ,
@@ -2467,7 +2455,7 @@ pub(crate) mod tests {
2467
2455
match network_graph. read_only ( ) . channels ( ) . get ( & short_channel_id) {
2468
2456
None => panic ! ( ) ,
2469
2457
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) ;
2471
2459
}
2472
2460
} ;
2473
2461
}
@@ -2601,7 +2589,7 @@ pub(crate) mod tests {
2601
2589
2602
2590
// Mark the channel as permanently failed. This will also remove the two nodes
2603
2591
// 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) ) ;
2605
2593
2606
2594
// Should not remove from tracking if insufficient time has passed
2607
2595
network_graph. remove_stale_channels_and_tracking_with_time (
@@ -2634,7 +2622,7 @@ pub(crate) mod tests {
2634
2622
2635
2623
// Mark the channel as permanently failed. This will also remove the two nodes
2636
2624
// 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) ;
2638
2626
2639
2627
// The first time we call the following, the channel will have a removal time assigned.
2640
2628
network_graph. remove_stale_channels_and_tracking_with_time ( removal_time) ;
0 commit comments