]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Rename `CandidateRouteHop::FirstHop::node_id` and make it a ref
authorMatt Corallo <git@bluematt.me>
Wed, 6 Dec 2023 01:22:21 +0000 (01:22 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 8 Dec 2023 20:45:06 +0000 (20:45 +0000)
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`.

lightning/src/routing/router.rs
lightning/src/util/test_utils.rs

index 6138b87bc9a8a72a349af84d7711681043b4c408..227d3f6fd5d21d0a042080af153fb0fef2bdec70 100644 (file)
@@ -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,
index 125ba812e78007b7b1872b2efec2c5e51af25a17..387f9df677e969def3eca8bde64186213854a3be 100644 (file)
@@ -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 {