Skip to content

Commit 948d019

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

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
@@ -78,15 +78,19 @@ pub fn find_path<L: Deref, GL: Deref>(
7878
} else { continue; }
7979
for scid in &node_info.channels {
8080
if let Some(chan_info) = network_channels.get(&scid) {
81-
if let Some((_, successor)) = chan_info.as_directed_from(&node_id) {
82-
// We may push a given successor multiple times, but the heap should sort its best entry
83-
// to the top. We do this because there is no way to adjust the priority of an existing
84-
// entry in `BinaryHeap`.
85-
frontier.push(PathBuildingHop {
86-
cost: cost + 1,
87-
node_id: *successor,
88-
parent_node_id: node_id,
89-
});
81+
if let Some((directed_channel, successor)) = chan_info.as_directed_from(&node_id) {
82+
if let Some(direction) = directed_channel.direction() {
83+
if direction.enabled {
84+
// We may push a given successor multiple times, but the heap should sort its best
85+
// entry to the top. We do this because there is no way to adjust the priority of an
86+
// existing entry in `BinaryHeap`.
87+
frontier.push(PathBuildingHop {
88+
cost: cost + 1,
89+
node_id: *successor,
90+
parent_node_id: node_id,
91+
});
92+
}
93+
}
9094
}
9195
}
9296
}
@@ -236,6 +240,23 @@ mod tests {
236240
let err = super::find_path(&our_id, &node_pks[2], &network_graph, None, Arc::clone(&logger)).unwrap_err();
237241
assert_eq!(err, super::Error::PathNotFound);
238242
}
243+
244+
#[test]
245+
fn disabled_channels_test() {
246+
// Check that we won't attempt to route over nodes where the channel is disabled from their
247+
// direction (implying the peer is offline).
248+
let mut features = InitFeatures::empty();
249+
features.set_onion_messages_optional();
250+
let (secp_ctx, network_graph, _, _, logger) = build_graph_with_features(features.to_context());
251+
let (_, our_id, _, node_pks) = get_nodes(&secp_ctx);
252+
253+
// Route to 1 via 2 and 3 because our channel to 1 is disabled
254+
let path = super::find_path(&our_id, &node_pks[0], &network_graph, None, Arc::clone(&logger)).unwrap();
255+
assert_eq!(path.len(), 3);
256+
assert_eq!(path[0], node_pks[1]);
257+
assert_eq!(path[1], node_pks[2]);
258+
assert_eq!(path[2], node_pks[0]);
259+
}
239260
}
240261

241262
#[cfg(all(test, feature = "_bench_unstable", not(feature = "no-std")))]

0 commit comments

Comments
 (0)