Skip to content

Commit aba9e61

Browse files
OM pathfinding: don't consider offline network successors
As judged by whether the channel is disabled, similar to payment routing
1 parent 32cde8f commit aba9e61

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

lightning/src/routing/onion_message.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,19 @@ pub fn find_path<L: Deref, GL: Deref>(
8282
} else { continue; }
8383
for scid in &node_info.channels {
8484
if let Some(chan_info) = network_channels.get(&scid) {
85-
if let Some((_, successor)) = chan_info.as_directed_from(&node_id) {
86-
// We may push a given successor multiple times, but the heap should sort its best entry
87-
// to the top. We do this because there is no way to adjust the priority of an existing
88-
// entry in `BinaryHeap`.
89-
frontier.push(PathBuildingHop {
90-
cost: cost + 1,
91-
node_id: *successor,
92-
parent_node_id: node_id,
93-
});
85+
if let Some((directed_channel, successor)) = chan_info.as_directed_from(&node_id) {
86+
if let Some(direction) = directed_channel.direction() {
87+
if direction.enabled {
88+
// We may push a given successor multiple times, but the heap should sort its best
89+
// entry to the top. We do this because there is no way to adjust the priority of an
90+
// existing entry in `BinaryHeap`.
91+
frontier.push(PathBuildingHop {
92+
cost: cost + 1,
93+
node_id: *successor,
94+
parent_node_id: node_id,
95+
});
96+
}
97+
}
9498
}
9599
}
96100
}
@@ -243,4 +247,21 @@ mod tests {
243247
let err = super::find_path(&our_id, &node_pks[2], &network_graph, None, Arc::clone(&logger)).unwrap_err();
244248
assert_eq!(err, super::Error::PathNotFound);
245249
}
250+
251+
#[test]
252+
fn disabled_channels_test() {
253+
// Check that we won't attempt to route over nodes where the channel is disabled from their
254+
// direction (implying the peer is offline).
255+
let mut features = InitFeatures::empty();
256+
features.set_onion_messages_optional();
257+
let (secp_ctx, network_graph, _, _, logger) = build_graph_with_features(features.to_context());
258+
let (_, our_id, _, node_pks) = get_nodes(&secp_ctx);
259+
260+
// Route to 1 via 2 and 3 because our channel to 1 is disabled
261+
let path = super::find_path(&our_id, &node_pks[0], &network_graph, None, Arc::clone(&logger)).unwrap();
262+
assert_eq!(path.len(), 3);
263+
assert_eq!(path[0], node_pks[1]);
264+
assert_eq!(path[1], node_pks[2]);
265+
assert_eq!(path[2], node_pks[0]);
266+
}
246267
}

0 commit comments

Comments
 (0)