Skip to content

Commit 64cfc28

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 52033e4 commit 64cfc28

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
@@ -1019,7 +1019,7 @@ pub enum CandidateRouteHop<'a> {
10191019
/// [`find_route`] validates this prior to constructing a [`CandidateRouteHop`].
10201020
details: &'a ChannelDetails,
10211021
/// The node id of the payer, which is also the source side of this candidate route hop.
1022-
node_id: NodeId,
1022+
payer_node_id: &'a NodeId,
10231023
},
10241024
/// A hop found in the [`ReadOnlyNetworkGraph`].
10251025
PublicHop {
@@ -1224,7 +1224,7 @@ impl<'a> CandidateRouteHop<'a> {
12241224
#[inline]
12251225
pub fn source(&self) -> NodeId {
12261226
match self {
1227-
CandidateRouteHop::FirstHop { node_id, .. } => *node_id,
1227+
CandidateRouteHop::FirstHop { payer_node_id, .. } => **payer_node_id,
12281228
CandidateRouteHop::PublicHop { info, .. } => *info.source(),
12291229
CandidateRouteHop::PrivateHop { hint, .. } => hint.src_node_id.into(),
12301230
CandidateRouteHop::Blinded { hint, .. } => hint.1.introduction_node_id.into(),
@@ -2197,7 +2197,9 @@ where L::Target: Logger {
21972197
if !skip_node {
21982198
if let Some(first_channels) = first_hop_targets.get(&$node_id) {
21992199
for details in first_channels {
2200-
let candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id };
2200+
let candidate = CandidateRouteHop::FirstHop {
2201+
details, payer_node_id: &our_node_id,
2202+
};
22012203
add_entry!(&candidate, $fee_to_target_msat,
22022204
$next_hops_value_contribution,
22032205
$next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
@@ -2252,7 +2254,9 @@ where L::Target: Logger {
22522254
// place where it could be added.
22532255
payee_node_id_opt.map(|payee| first_hop_targets.get(&payee).map(|first_channels| {
22542256
for details in first_channels {
2255-
let candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id };
2257+
let candidate = CandidateRouteHop::FirstHop {
2258+
details, payer_node_id: &our_node_id,
2259+
};
22562260
let added = add_entry!(&candidate, 0, path_value_msat,
22572261
0, 0u64, 0, 0).is_some();
22582262
log_trace!(logger, "{} direct route to payee via {}",
@@ -2299,7 +2303,9 @@ where L::Target: Logger {
22992303
sort_first_hop_channels(first_channels, &used_liquidities, recommended_value_msat,
23002304
our_node_pubkey);
23012305
for details in first_channels {
2302-
let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id};
2306+
let first_hop_candidate = CandidateRouteHop::FirstHop {
2307+
details, payer_node_id: &our_node_id,
2308+
};
23032309
let blinded_path_fee = match compute_fees(path_contribution_msat, candidate.fees()) {
23042310
Some(fee) => fee,
23052311
None => continue
@@ -2396,7 +2402,9 @@ where L::Target: Logger {
23962402
sort_first_hop_channels(first_channels, &used_liquidities,
23972403
recommended_value_msat, our_node_pubkey);
23982404
for details in first_channels {
2399-
let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id};
2405+
let first_hop_candidate = CandidateRouteHop::FirstHop {
2406+
details, payer_node_id: &our_node_id,
2407+
};
24002408
add_entry!(&first_hop_candidate,
24012409
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
24022410
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
@@ -2441,7 +2449,9 @@ where L::Target: Logger {
24412449
sort_first_hop_channels(first_channels, &used_liquidities,
24422450
recommended_value_msat, our_node_pubkey);
24432451
for details in first_channels {
2444-
let first_hop_candidate = CandidateRouteHop::FirstHop { details, node_id: our_node_id};
2452+
let first_hop_candidate = CandidateRouteHop::FirstHop {
2453+
details, payer_node_id: &our_node_id,
2454+
};
24452455
add_entry!(&first_hop_candidate,
24462456
aggregate_next_hops_fee_msat,
24472457
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)