From d40402d93c0419dc14c20873b75456796801aec1 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 2 Feb 2022 10:25:08 -0600 Subject: [PATCH] f - Remove source and target from DirectedChannelInfo --- lightning/src/routing/network_graph.rs | 24 +++++++----------------- lightning/src/routing/router.rs | 8 +++----- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index 632754eae..fb90c9386 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -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 { - 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)) } } @@ -701,8 +701,6 @@ impl_writeable_tlv_based!(ChannelInfo, { pub struct DirectedChannelInfo<'a> { channel: &'a ChannelInfo, direction: Option<&'a ChannelUpdateInfo>, - source: &'a NodeId, - target: &'a NodeId, } impl<'a> DirectedChannelInfo<'a> { @@ -712,12 +710,6 @@ impl<'a> DirectedChannelInfo<'a> { /// Returns information for the direction. pub fn direction(&self) -> Option<&'a ChannelUpdateInfo> { self.direction } - /// Returns the node id for the source. - pub fn source(&self) -> &'a NodeId { self.source } - - /// Returns the node id for the target. - pub fn target(&self) -> &'a NodeId { self.target } - /// Returns the [`EffectiveCapacity`] of the channel in the direction. /// /// This is either the total capacity from the funding transaction, if known, or the @@ -752,8 +744,6 @@ impl<'a> DirectedChannelInfo<'a> { impl<'a> fmt::Debug for DirectedChannelInfo<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { f.debug_struct("DirectedChannelInfo") - .field("source", &self.source) - .field("target", &self.target) .field("channel", &self.channel) .finish() } diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 08f499fb7..ed40f4641 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1072,10 +1072,8 @@ where L::Target: Logger { for chan_id in $node.channels.iter() { let chan = network_channels.get(chan_id).unwrap(); if !chan.features.requires_unknown_bits() { - let directed_channel = + let (directed_channel, source) = chan.as_directed_to(&$node_id).expect("inconsistent NetworkGraph"); - let source = directed_channel.source(); - let target = directed_channel.target(); if first_hops.is_none() || *source != our_node_id { if let Some(direction) = directed_channel.direction() { if direction.enabled { @@ -1083,7 +1081,7 @@ where L::Target: Logger { info: directed_channel.with_update().unwrap(), short_channel_id: *chan_id, }; - add_entry!(candidate, *source, *target, $fee_to_target_msat, $next_hops_value_contribution, $next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat, $next_hops_cltv_delta); + add_entry!(candidate, *source, $node_id, $fee_to_target_msat, $next_hops_value_contribution, $next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat, $next_hops_cltv_delta); } } } @@ -1158,7 +1156,7 @@ where L::Target: Logger { let candidate = network_channels .get(&hop.short_channel_id) .and_then(|channel| channel.as_directed_to(&target)) - .and_then(|channel| channel.with_update()) + .and_then(|(channel, _)| channel.with_update()) .map(|info| CandidateRouteHop::PublicHop { info, short_channel_id: hop.short_channel_id, -- 2.39.5