Skip to content

Commit ec95e58

Browse files
committed
Add outbound flag to DirectedChannelInfo
If `outband` flag is set to true then `ChannelInfo::node_one` is forwarding a payment to target `ChannelInfo::node_two`. If `outband` flag is set to false then `ChannelInfo::node_two` is forwarding a payment to target `ChannelInfo::node_one`.
1 parent 37150b4 commit ec95e58

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lightning/src/routing/gossip.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -870,31 +870,31 @@ impl ChannelInfo {
870870
/// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a
871871
/// returned `source`, or `None` if `target` is not one of the channel's counterparties.
872872
pub fn as_directed_to(&self, target: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
873-
let (direction, source) = {
873+
let (direction, source, outbound) = {
874874
if target == &self.node_one {
875-
(self.two_to_one.as_ref(), &self.node_two)
875+
(self.two_to_one.as_ref(), &self.node_two, false)
876876
} else if target == &self.node_two {
877-
(self.one_to_two.as_ref(), &self.node_one)
877+
(self.one_to_two.as_ref(), &self.node_one, true)
878878
} else {
879879
return None;
880880
}
881881
};
882-
direction.map(|dir| (DirectedChannelInfo::new(self, dir), source))
882+
direction.map(|dir| (DirectedChannelInfo::new(self, dir, outbound), source))
883883
}
884884

885885
/// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a
886886
/// returned `target`, or `None` if `source` is not one of the channel's counterparties.
887887
pub fn as_directed_from(&self, source: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
888-
let (direction, target) = {
888+
let (direction, target, outbound) = {
889889
if source == &self.node_one {
890-
(self.one_to_two.as_ref(), &self.node_two)
890+
(self.one_to_two.as_ref(), &self.node_two, true)
891891
} else if source == &self.node_two {
892-
(self.two_to_one.as_ref(), &self.node_one)
892+
(self.two_to_one.as_ref(), &self.node_one, false)
893893
} else {
894894
return None;
895895
}
896896
};
897-
direction.map(|dir| (DirectedChannelInfo::new(self, dir), target))
897+
direction.map(|dir| (DirectedChannelInfo::new(self, dir, outbound), target))
898898
}
899899

900900
/// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
@@ -992,24 +992,32 @@ pub struct DirectedChannelInfo<'a> {
992992
direction: &'a ChannelUpdateInfo,
993993
htlc_maximum_msat: u64,
994994
effective_capacity: EffectiveCapacity,
995+
/// Outbound from the perspective of `node_one`.
996+
///
997+
/// If true, the channel is considered to be outbound from `node_one` perspective.
998+
/// If false, the channel is considered to be outbound from `node_two` perspective.
999+
///
1000+
/// [`ChannelInfo::node_one`]
1001+
/// [`ChannelInfo::node_two`]
1002+
outbound: bool,
9951003
}
9961004

9971005
impl<'a> DirectedChannelInfo<'a> {
9981006
#[inline]
999-
fn new(channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo) -> Self {
1007+
fn new(channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo, outbound: bool) -> Self {
10001008
let mut htlc_maximum_msat = direction.htlc_maximum_msat;
10011009
let capacity_msat = channel.capacity_sats.map(|capacity_sats| capacity_sats * 1000);
10021010

10031011
let effective_capacity = match capacity_msat {
10041012
Some(capacity_msat) => {
10051013
htlc_maximum_msat = cmp::min(htlc_maximum_msat, capacity_msat);
1006-
EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat: htlc_maximum_msat }
1014+
EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat }
10071015
},
10081016
None => EffectiveCapacity::AdvertisedMaxHTLC { amount_msat: htlc_maximum_msat },
10091017
};
10101018

10111019
Self {
1012-
channel, direction, htlc_maximum_msat, effective_capacity
1020+
channel, direction, htlc_maximum_msat, effective_capacity, outbound
10131021
}
10141022
}
10151023

0 commit comments

Comments
 (0)