Skip to content

Commit ab127e8

Browse files
committed
f make chan/node failure api consistent, sp
1 parent 444f857 commit ab127e8

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

lightning/src/routing/gossip.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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 { "Not touching" };
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,37 +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-
///
1637-
/// If permanent, removes a channel from the local storage.
1638-
/// May cause the removal of nodes too, if this was their last channel.
1636+
/// Marks a channel in the graph as failed permanently.
16391637
///
1640-
/// If not permanent, no action is taken as such a failure likely indicates the node simply
1641-
/// lacked liquidity and your scorer should handle this instead.
1642-
pub fn channel_failed(&self, short_channel_id: u64, is_permanent: bool) {
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) {
16431640
#[cfg(feature = "std")]
16441641
let current_time_unix = Some(SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs());
16451642
#[cfg(not(feature = "std"))]
16461643
let current_time_unix = None;
16471644

1648-
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)
16491646
}
16501647

1651-
/// Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
1648+
/// Marks a channel in the graph as failed permanently.
16521649
///
1653-
/// If permanent, removes a channel from the local storage.
1654-
/// May cause the removal of nodes too, if this was their last channel.
1655-
///
1656-
/// If not permanent, no action is taken as such a failure likely indicates the node simply
1657-
/// lacked liquidity and your scorer should handle this instead.
1658-
fn channel_failed_with_time(&self, short_channel_id: u64, is_permanent: bool, current_time_unix: Option<u64>) {
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>) {
16591652
let mut channels = self.channels.write().unwrap();
1660-
if is_permanent {
1661-
if let Some(chan) = channels.remove(&short_channel_id) {
1662-
let mut nodes = self.nodes.write().unwrap();
1663-
self.removed_channels.lock().unwrap().insert(short_channel_id, current_time_unix);
1664-
Self::remove_channel_in_nodes(&mut nodes, &chan, short_channel_id);
1665-
}
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);
16661657
}
16671658
}
16681659

@@ -2598,7 +2589,7 @@ pub(crate) mod tests {
25982589

25992590
// Mark the channel as permanently failed. This will also remove the two nodes
26002591
// and all of the entries will be tracked as removed.
2601-
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));
26022593

26032594
// Should not remove from tracking if insufficient time has passed
26042595
network_graph.remove_stale_channels_and_tracking_with_time(

0 commit comments

Comments
 (0)