Skip to content

Commit 322aee8

Browse files
committed
Add and use ChannelInfo::as_coming_from.
1 parent ba52ad8 commit 322aee8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lightning/src/routing/network_graph.rs

+15
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,21 @@ impl ChannelInfo {
674674
};
675675
Some((DirectedChannelInfo { channel: self, direction }, source))
676676
}
677+
678+
/// Returns a [`DirectedChannelInfo`] for the channel coming from the given `source` to a
679+
/// returned `target`, or `None` if `source` is not one of the channel's counterparties.
680+
pub fn as_coming_from(&self, source: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
681+
let (direction, target) = {
682+
if source == &self.node_one {
683+
(self.one_to_two.as_ref(), &self.node_two)
684+
} else if source == &self.node_two {
685+
(self.two_to_one.as_ref(), &self.node_one)
686+
} else {
687+
return None;
688+
}
689+
};
690+
Some((DirectedChannelInfo { channel: self, direction }, target))
691+
}
677692
}
678693

679694
impl fmt::Display for ChannelInfo {

lightning/src/routing/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
15781578
if let Some(random_channel) = usize::from_be_bytes(random_path_bytes).checked_rem(cur_node.channels.len())
15791579
.and_then(|index| cur_node.channels.get(index))
15801580
.and_then(|id| network_channels.get(id)) {
1581-
random_channel.as_directed_to(&cur_node_id).map(|(dir_info, next_id)| {
1581+
random_channel.as_coming_from(&cur_node_id).map(|(dir_info, next_id)| {
15821582
dir_info.direction().map(|channel_update_info|
15831583
shadow_ctlv_expiry_delta_offset = shadow_ctlv_expiry_delta_offset
15841584
.checked_add(channel_update_info.cltv_expiry_delta.into())

0 commit comments

Comments
 (0)