From: Matt Corallo Date: Wed, 6 Dec 2023 01:22:21 +0000 (+0000) Subject: Rename `CandidateRouteHop::FirstHop::node_id` and make it a ref X-Git-Tag: v0.0.119~18^2~7 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=cc4bc1df5a1ab6c363fac3c1b7eddce362e167c0;p=rust-lightning Rename `CandidateRouteHop::FirstHop::node_id` and make it a ref Rather than calling `CandidateRouteHop::FirstHop::node_id` just `node_id`, we should call it `payer_node_id` to provide more context. We also take this opportunity to make it a reference, avoiding bloating `CandidateRouteHop`. --- diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 6138b87bc..227d3f6fd 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1020,7 +1020,7 @@ pub enum CandidateRouteHop<'a> { /// [`find_route`] validates this prior to constructing a [`CandidateRouteHop`]. details: &'a ChannelDetails, /// The node id of the payer, which is also the source side of this candidate route hop. - node_id: NodeId, + payer_node_id: &'a NodeId, }, /// A hop found in the [`ReadOnlyNetworkGraph`]. PublicHop { @@ -1225,7 +1225,7 @@ impl<'a> CandidateRouteHop<'a> { #[inline] pub fn source(&self) -> NodeId { match self { - CandidateRouteHop::FirstHop { node_id, .. } => *node_id, + CandidateRouteHop::FirstHop { payer_node_id, .. } => **payer_node_id, CandidateRouteHop::PublicHop { info, .. } => *info.source(), CandidateRouteHop::PrivateHop { hint, .. } => hint.src_node_id.into(), CandidateRouteHop::Blinded { hint, .. } => hint.1.introduction_node_id.into(), @@ -2198,7 +2198,9 @@ where L::Target: Logger { if !skip_node { if let Some(first_channels) = first_hop_targets.get(&$node_id) { for details in first_channels { - let candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id }; + let candidate = CandidateRouteHop::FirstHop { + details, payer_node_id: &our_node_id, + }; add_entry!(&candidate, $fee_to_target_msat, $next_hops_value_contribution, $next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat, @@ -2253,7 +2255,9 @@ where L::Target: Logger { // place where it could be added. payee_node_id_opt.map(|payee| first_hop_targets.get(&payee).map(|first_channels| { for details in first_channels { - let candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id }; + let candidate = CandidateRouteHop::FirstHop { + details, payer_node_id: &our_node_id, + }; let added = add_entry!(&candidate, 0, path_value_msat, 0, 0u64, 0, 0).is_some(); log_trace!(logger, "{} direct route to payee via {}", @@ -2300,7 +2304,9 @@ where L::Target: Logger { sort_first_hop_channels(first_channels, &used_liquidities, recommended_value_msat, our_node_pubkey); for details in first_channels { - let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id}; + let first_hop_candidate = CandidateRouteHop::FirstHop { + details, payer_node_id: &our_node_id, + }; let blinded_path_fee = match compute_fees(path_contribution_msat, candidate.fees()) { Some(fee) => fee, None => continue @@ -2397,7 +2403,9 @@ where L::Target: Logger { sort_first_hop_channels(first_channels, &used_liquidities, recommended_value_msat, our_node_pubkey); for details in first_channels { - let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id}; + let first_hop_candidate = CandidateRouteHop::FirstHop { + details, payer_node_id: &our_node_id, + }; add_entry!(&first_hop_candidate, aggregate_next_hops_fee_msat, aggregate_path_contribution_msat, aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat, @@ -2442,7 +2450,9 @@ where L::Target: Logger { sort_first_hop_channels(first_channels, &used_liquidities, recommended_value_msat, our_node_pubkey); for details in first_channels { - let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id}; + let first_hop_candidate = CandidateRouteHop::FirstHop { + details, payer_node_id: &our_node_id, + }; add_entry!(&first_hop_candidate, aggregate_next_hops_fee_msat, aggregate_path_contribution_msat, diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 125ba812e..387f9df67 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -148,9 +148,10 @@ impl<'a> Router for TestRouter<'a> { continue; } let idx = if first_hops.len() > 1 { route.paths.iter().position(|p| p == path).unwrap_or(0) } else { 0 }; + let node_id = NodeId::from_pubkey(payer); let candidate = CandidateRouteHop::FirstHop { details: first_hops[idx], - node_id: NodeId::from_pubkey(payer) + payer_node_id: &node_id, }; scorer.channel_penalty_msat(&candidate, usage, &()); } else {