Skip to content

Commit cc4bc1d

Browse files
committed
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`.
1 parent 57857fd commit cc4bc1d

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lightning/src/routing/router.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ pub enum CandidateRouteHop<'a> {
10201020
/// [`find_route`] validates this prior to constructing a [`CandidateRouteHop`].
10211021
details: &'a ChannelDetails,
10221022
/// The node id of the payer, which is also the source side of this candidate route hop.
1023-
node_id: NodeId,
1023+
payer_node_id: &'a NodeId,
10241024
},
10251025
/// A hop found in the [`ReadOnlyNetworkGraph`].
10261026
PublicHop {
@@ -1225,7 +1225,7 @@ impl<'a> CandidateRouteHop<'a> {
12251225
#[inline]
12261226
pub fn source(&self) -> NodeId {
12271227
match self {
1228-
CandidateRouteHop::FirstHop { node_id, .. } => *node_id,
1228+
CandidateRouteHop::FirstHop { payer_node_id, .. } => **payer_node_id,
12291229
CandidateRouteHop::PublicHop { info, .. } => *info.source(),
12301230
CandidateRouteHop::PrivateHop { hint, .. } => hint.src_node_id.into(),
12311231
CandidateRouteHop::Blinded { hint, .. } => hint.1.introduction_node_id.into(),
@@ -2198,7 +2198,9 @@ where L::Target: Logger {
21982198
if !skip_node {
21992199
if let Some(first_channels) = first_hop_targets.get(&$node_id) {
22002200
for details in first_channels {
2201-
let candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id };
2201+
let candidate = CandidateRouteHop::FirstHop {
2202+
details, payer_node_id: &our_node_id,
2203+
};
22022204
add_entry!(&candidate, $fee_to_target_msat,
22032205
$next_hops_value_contribution,
22042206
$next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
@@ -2253,7 +2255,9 @@ where L::Target: Logger {
22532255
// place where it could be added.
22542256
payee_node_id_opt.map(|payee| first_hop_targets.get(&payee).map(|first_channels| {
22552257
for details in first_channels {
2256-
let candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id };
2258+
let candidate = CandidateRouteHop::FirstHop {
2259+
details, payer_node_id: &our_node_id,
2260+
};
22572261
let added = add_entry!(&candidate, 0, path_value_msat,
22582262
0, 0u64, 0, 0).is_some();
22592263
log_trace!(logger, "{} direct route to payee via {}",
@@ -2300,7 +2304,9 @@ where L::Target: Logger {
23002304
sort_first_hop_channels(first_channels, &used_liquidities, recommended_value_msat,
23012305
our_node_pubkey);
23022306
for details in first_channels {
2303-
let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id};
2307+
let first_hop_candidate = CandidateRouteHop::FirstHop {
2308+
details, payer_node_id: &our_node_id,
2309+
};
23042310
let blinded_path_fee = match compute_fees(path_contribution_msat, candidate.fees()) {
23052311
Some(fee) => fee,
23062312
None => continue
@@ -2397,7 +2403,9 @@ where L::Target: Logger {
23972403
sort_first_hop_channels(first_channels, &used_liquidities,
23982404
recommended_value_msat, our_node_pubkey);
23992405
for details in first_channels {
2400-
let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id};
2406+
let first_hop_candidate = CandidateRouteHop::FirstHop {
2407+
details, payer_node_id: &our_node_id,
2408+
};
24012409
add_entry!(&first_hop_candidate,
24022410
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
24032411
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
@@ -2442,7 +2450,9 @@ where L::Target: Logger {
24422450
sort_first_hop_channels(first_channels, &used_liquidities,
24432451
recommended_value_msat, our_node_pubkey);
24442452
for details in first_channels {
2445-
let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id};
2453+
let first_hop_candidate = CandidateRouteHop::FirstHop {
2454+
details, payer_node_id: &our_node_id,
2455+
};
24462456
add_entry!(&first_hop_candidate,
24472457
aggregate_next_hops_fee_msat,
24482458
aggregate_path_contribution_msat,

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ impl<'a> Router for TestRouter<'a> {
148148
continue;
149149
}
150150
let idx = if first_hops.len() > 1 { route.paths.iter().position(|p| p == path).unwrap_or(0) } else { 0 };
151+
let node_id = NodeId::from_pubkey(payer);
151152
let candidate = CandidateRouteHop::FirstHop {
152153
details: first_hops[idx],
153-
node_id: NodeId::from_pubkey(payer)
154+
payer_node_id: &node_id,
154155
};
155156
scorer.channel_penalty_msat(&candidate, usage, &());
156157
} else {

0 commit comments

Comments
 (0)