Skip to content

Commit 29f8a54

Browse files
committed
Ignore partially-pruned channels during routing
If we prune one side of a channel's `ChannelUpdateInfo` that means the node hasn't been online for two weeks (as they haven't generated a new `channel_update` in that time). In such cases, even if we haven't yet pruned the channel entirely, we should definitely not be treating these channels as candidates for routing. Fixes #1824
1 parent 37c431a commit 29f8a54

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lightning/src/routing/gossip.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ impl ChannelInfo {
879879
/// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a
880880
/// returned `source`, or `None` if `target` is not one of the channel's counterparties.
881881
pub fn as_directed_to(&self, target: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
882+
if self.one_to_two.is_none() || self.two_to_one.is_none() { return None; }
882883
let (direction, source, outbound) = {
883884
if target == &self.node_one {
884885
(self.two_to_one.as_ref(), &self.node_two, false)
@@ -888,12 +889,14 @@ impl ChannelInfo {
888889
return None;
889890
}
890891
};
891-
direction.map(|dir| (DirectedChannelInfo::new(self, dir, outbound), source))
892+
let dir = direction.expect("We checked that both directions are available at the start");
893+
Some((DirectedChannelInfo::new(self, dir, outbound), source))
892894
}
893895

894896
/// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a
895897
/// returned `target`, or `None` if `source` is not one of the channel's counterparties.
896898
pub fn as_directed_from(&self, source: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
899+
if self.one_to_two.is_none() || self.two_to_one.is_none() { return None; }
897900
let (direction, target, outbound) = {
898901
if source == &self.node_one {
899902
(self.one_to_two.as_ref(), &self.node_two, true)
@@ -903,7 +906,8 @@ impl ChannelInfo {
903906
return None;
904907
}
905908
};
906-
direction.map(|dir| (DirectedChannelInfo::new(self, dir, outbound), target))
909+
let dir = direction.expect("We checked that both directions are available at the start");
910+
Some((DirectedChannelInfo::new(self, dir, outbound), target))
907911
}
908912

909913
/// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.

0 commit comments

Comments
 (0)