Skip to content

Commit 002ef78

Browse files
committed
gossip: Implement NetworkGraph::node_failed_permanent
The original method, `NetworkGraph::node_failed` was not yet implemented. Since `Scorer` is responsible for handling non-permanent node failures, we've changed the method name here to indicate we handle just permanent failures by removing a node (and related channels) from the graph local storage.
1 parent 28c9b56 commit 002ef78

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lightning/src/routing/gossip.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<L: Deref> EventHandler for NetworkGraph<L> where L::Target: Logger {
269269
NetworkUpdate::NodeFailure { ref node_id, is_permanent } => {
270270
let action = if is_permanent { "Removing" } else { "Disabling" };
271271
log_debug!(self.logger, "{} node graph entry for {} due to a payment failure.", action, node_id);
272-
self.node_failed(node_id, is_permanent);
272+
if is_permanent { self.node_failed_permanent(node_id); }
273273
},
274274
}
275275
}
@@ -1522,12 +1522,27 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
15221522
}
15231523
}
15241524

1525-
/// Marks a node in the graph as failed.
1526-
pub fn node_failed(&self, _node_id: &PublicKey, is_permanent: bool) {
1527-
if is_permanent {
1528-
// TODO: Wholly remove the node
1529-
} else {
1530-
// TODO: downgrade the node
1525+
/// Marks a node in the graph as permanently failed, effectively removing it and its channels
1526+
/// from local storage.
1527+
pub fn node_failed_permanent(&self, node_id: &PublicKey) {
1528+
let node_id = NodeId::from_pubkey(node_id);
1529+
let mut nodes = self.nodes.write().unwrap();
1530+
let mut channels = self.channels.write().unwrap();
1531+
1532+
let mut scids_to_remove = Vec::new();
1533+
for (scid, info) in channels.iter_mut() {
1534+
if info.node_one == node_id || info.node_two == node_id {
1535+
scids_to_remove.push(*scid);
1536+
}
1537+
}
1538+
nodes.remove(&node_id);
1539+
1540+
if !scids_to_remove.is_empty() {
1541+
// TODO: Use BTreeMap::retain when our MSRV is >= 1.53.
1542+
for scid in scids_to_remove {
1543+
let info = channels.remove(&scid).expect("We just accessed this scid, it should be present");
1544+
Self::remove_channel_in_nodes(&mut nodes, &info, scid);
1545+
}
15311546
}
15321547
}
15331548

0 commit comments

Comments
 (0)