f - Remove node_id from ProbabilisticScorer
[rust-lightning] / lightning / src / routing / network_graph.rs
index ee0ca48a1647230fbe04606c87bef400e00c5926..fb90c9386dc3aa2bd6783a0993ea08bd7d2bd48d 100644 (file)
@@ -660,19 +660,19 @@ pub struct ChannelInfo {
 }
 
 impl ChannelInfo {
-       /// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target`, or `None`
-       /// if `target` is not one of the channel's counterparties.
-       pub fn as_directed_to(&self, target: &NodeId) -> Option<DirectedChannelInfo> {
-               let (direction, source, target) = {
+       /// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a
+       /// returned `source`, or `None` if `target` is not one of the channel's counterparties.
+       pub fn as_directed_to(&self, target: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
+               let (direction, source) = {
                        if target == &self.node_one {
-                               (self.two_to_one.as_ref(), &self.node_two, &self.node_one)
+                               (self.two_to_one.as_ref(), &self.node_two)
                        } else if target == &self.node_two {
-                               (self.one_to_two.as_ref(), &self.node_one, &self.node_two)
+                               (self.one_to_two.as_ref(), &self.node_one)
                        } else {
                                return None;
                        }
                };
-               Some(DirectedChannelInfo { channel: self, direction, source, target })
+               Some((DirectedChannelInfo { channel: self, direction }, source))
        }
 }
 
@@ -697,26 +697,18 @@ impl_writeable_tlv_based!(ChannelInfo, {
 
 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
 /// source node to a target node.
-#[derive(Clone, Debug)]
-pub struct DirectedChannelInfo<'a: 'b, 'b> {
+#[derive(Clone)]
+pub struct DirectedChannelInfo<'a> {
        channel: &'a ChannelInfo,
-       direction: Option<&'b ChannelUpdateInfo>,
-       source: &'b NodeId,
-       target: &'b NodeId,
+       direction: Option<&'a ChannelUpdateInfo>,
 }
 
-impl<'a: 'b, 'b> DirectedChannelInfo<'a, 'b> {
+impl<'a> DirectedChannelInfo<'a> {
        /// Returns information for the channel.
        pub fn channel(&self) -> &'a ChannelInfo { self.channel }
 
        /// Returns information for the direction.
-       pub fn direction(&self) -> Option<&'b ChannelUpdateInfo> { self.direction }
-
-       /// Returns the node id for the source.
-       pub fn source(&self) -> &'b NodeId { self.source }
-
-       /// Returns the node id for the target.
-       pub fn target(&self) -> &'b NodeId { self.target }
+       pub fn direction(&self) -> Option<&'a ChannelUpdateInfo> { self.direction }
 
        /// Returns the [`EffectiveCapacity`] of the channel in the direction.
        ///
@@ -741,7 +733,7 @@ impl<'a: 'b, 'b> DirectedChannelInfo<'a, 'b> {
        }
 
        /// Returns `Some` if [`ChannelUpdateInfo`] is available in the direction.
-       pub(super) fn with_update(self) -> Option<DirectedChannelInfoWithUpdate<'a, 'b>> {
+       pub(super) fn with_update(self) -> Option<DirectedChannelInfoWithUpdate<'a>> {
                match self.direction {
                        Some(_) => Some(DirectedChannelInfoWithUpdate { inner: self }),
                        None => None,
@@ -749,16 +741,37 @@ impl<'a: 'b, 'b> DirectedChannelInfo<'a, 'b> {
        }
 }
 
+impl<'a> fmt::Debug for DirectedChannelInfo<'a> {
+       fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+               f.debug_struct("DirectedChannelInfo")
+                       .field("channel", &self.channel)
+                       .finish()
+       }
+}
+
 /// A [`DirectedChannelInfo`] with [`ChannelUpdateInfo`] available in its the direction.
-#[derive(Clone, Debug)]
-pub(super) struct DirectedChannelInfoWithUpdate<'a: 'b, 'b> {
-       inner: DirectedChannelInfo<'a, 'b>,
+#[derive(Clone)]
+pub(super) struct DirectedChannelInfoWithUpdate<'a> {
+       inner: DirectedChannelInfo<'a>,
+}
+
+impl<'a> DirectedChannelInfoWithUpdate<'a> {
+       /// Returns information for the channel.
+       #[inline]
+       pub(super) fn channel(&self) -> &'a ChannelInfo { &self.inner.channel }
+
+       /// Returns information for the direction.
+       #[inline]
+       pub(super) fn direction(&self) -> &'a ChannelUpdateInfo { self.inner.direction.unwrap() }
+
+       /// Returns the [`EffectiveCapacity`] of the channel in the direction.
+       #[inline]
+       pub(super) fn effective_capacity(&self) -> EffectiveCapacity { self.inner.effective_capacity() }
 }
 
-impl<'a: 'b, 'b> DirectedChannelInfoWithUpdate<'a, 'b> {
-       /// Returns the underlying [`DirectedChannelInfo`].
-       pub(super) fn inner(&self) -> &DirectedChannelInfo<'a, 'b> {
-               &self.inner
+impl<'a> fmt::Debug for DirectedChannelInfoWithUpdate<'a> {
+       fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+               self.inner.fmt(f)
        }
 }
 
@@ -785,7 +798,7 @@ pub enum EffectiveCapacity {
                capacity_msat: u64,
        },
        /// A capacity sufficient to route any payment, typically used for private channels provided by
-       /// an invoice, though may not be the case for zero-amount invoices.
+       /// an invoice.
        Infinite,
        /// A capacity that is unknown possibly because either the chain state is unavailable to know
        /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.