Skip to content

Commit 507b809

Browse files
Router: track whether candidate hops target blinded paths.
Will be useful to determine whether these hops should count towards our intermediate hop count.
1 parent 5bc7bfe commit 507b809

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

lightning/src/routing/router.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,7 @@ struct RouteGraphNode {
11211121
total_cltv_delta: u32,
11221122
/// The number of hops walked up to this node.
11231123
path_length_to_node: u8,
1124+
is_intro_node: bool,
11241125
}
11251126

11261127
impl cmp::Ord for RouteGraphNode {
@@ -1161,6 +1162,9 @@ pub struct FirstHopCandidate<'a> {
11611162
///
11621163
/// This is not exported to bindings users as lifetimes are not expressible in most languages.
11631164
pub payer_node_id: &'a NodeId,
1165+
1166+
/// Whether the target of this hop is the introduction node of a payee-supplied blinded path.
1167+
pub(crate) targets_blinded_path: bool,
11641168
}
11651169

11661170
/// A [`CandidateRouteHop::PublicHop`] entry.
@@ -1174,12 +1178,14 @@ pub struct PublicHopCandidate<'a> {
11741178
/// The short channel ID of the channel, i.e. the identifier by which we refer to this
11751179
/// channel.
11761180
pub short_channel_id: u64,
1181+
/// Whether the target of this hop is the introduction node of a payee-supplied blinded path.
1182+
pub(crate) targets_blinded_path: bool,
11771183
}
11781184

11791185
impl<'a> PublicHopCandidate<'a> {
11801186
#[cfg(test)]
11811187
pub(super) fn new(info: DirectedChannelInfo<'a>, short_channel_id: u64) -> Self {
1182-
Self { info, short_channel_id }
1188+
Self { info, short_channel_id, targets_blinded_path: false }
11831189
}
11841190
}
11851191

@@ -2375,6 +2381,7 @@ where L::Target: Logger {
23752381
total_cltv_delta: hop_total_cltv_delta,
23762382
value_contribution_msat,
23772383
path_length_to_node,
2384+
is_intro_node: $candidate.blinded_hint_idx().is_some(),
23782385
};
23792386
targets.push(new_graph_node);
23802387
old_entry.next_hops_fee_msat = $next_hops_fee_msat;
@@ -2450,7 +2457,7 @@ where L::Target: Logger {
24502457
// This data can later be helpful to optimize routing (pay lower fees).
24512458
macro_rules! add_entries_to_cheapest_to_target_node {
24522459
( $node: expr, $node_id: expr, $next_hops_value_contribution: expr,
2453-
$next_hops_cltv_delta: expr, $next_hops_path_length: expr ) => {
2460+
$next_hops_cltv_delta: expr, $next_hops_path_length: expr, $is_intro_node: expr ) => {
24542461
let fee_to_target_msat;
24552462
let next_hops_path_htlc_minimum_msat;
24562463
let next_hops_path_penalty_msat;
@@ -2476,7 +2483,7 @@ where L::Target: Logger {
24762483
if let Some(first_channels) = first_hop_targets.get(&$node_id) {
24772484
for details in first_channels {
24782485
let candidate = CandidateRouteHop::FirstHop(FirstHopCandidate {
2479-
details, payer_node_id: &our_node_id,
2486+
details, payer_node_id: &our_node_id, targets_blinded_path: false,
24802487
});
24812488
add_entry!(&candidate, fee_to_target_msat,
24822489
$next_hops_value_contribution,
@@ -2501,6 +2508,7 @@ where L::Target: Logger {
25012508
let candidate = CandidateRouteHop::PublicHop(PublicHopCandidate {
25022509
info: directed_channel,
25032510
short_channel_id: *chan_id,
2511+
targets_blinded_path: $is_intro_node,
25042512
});
25052513
add_entry!(&candidate,
25062514
fee_to_target_msat,
@@ -2533,7 +2541,7 @@ where L::Target: Logger {
25332541
payee_node_id_opt.map(|payee| first_hop_targets.get(&payee).map(|first_channels| {
25342542
for details in first_channels {
25352543
let candidate = CandidateRouteHop::FirstHop(FirstHopCandidate {
2536-
details, payer_node_id: &our_node_id,
2544+
details, payer_node_id: &our_node_id, targets_blinded_path: false,
25372545
});
25382546
let added = add_entry!(&candidate, 0, path_value_msat,
25392547
0, 0u64, 0, 0).is_some();
@@ -2551,7 +2559,7 @@ where L::Target: Logger {
25512559
// If not, targets.pop() will not even let us enter the loop in step 2.
25522560
None => {},
25532561
Some(node) => {
2554-
add_entries_to_cheapest_to_target_node!(node, payee, path_value_msat, 0, 0);
2562+
add_entries_to_cheapest_to_target_node!(node, payee, path_value_msat, 0, 0, false);
25552563
},
25562564
});
25572565

@@ -2609,7 +2617,7 @@ where L::Target: Logger {
26092617
);
26102618
for details in first_channels {
26112619
let first_hop_candidate = CandidateRouteHop::FirstHop(FirstHopCandidate {
2612-
details, payer_node_id: &our_node_id,
2620+
details, payer_node_id: &our_node_id, targets_blinded_path: true,
26132621
});
26142622
let blinded_path_fee = match compute_fees(path_contribution_msat, candidate.fees()) {
26152623
Some(fee) => fee,
@@ -2665,6 +2673,7 @@ where L::Target: Logger {
26652673
.map(|(info, _)| CandidateRouteHop::PublicHop(PublicHopCandidate {
26662674
info,
26672675
short_channel_id: hop.short_channel_id,
2676+
targets_blinded_path: false
26682677
}))
26692678
.unwrap_or_else(|| CandidateRouteHop::PrivateHop(PrivateHopCandidate { hint: hop, target_node_id: target }));
26702679

@@ -2709,7 +2718,7 @@ where L::Target: Logger {
27092718
);
27102719
for details in first_channels {
27112720
let first_hop_candidate = CandidateRouteHop::FirstHop(FirstHopCandidate {
2712-
details, payer_node_id: &our_node_id,
2721+
details, payer_node_id: &our_node_id, targets_blinded_path: false
27132722
});
27142723
add_entry!(&first_hop_candidate,
27152724
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
@@ -2758,7 +2767,7 @@ where L::Target: Logger {
27582767
);
27592768
for details in first_channels {
27602769
let first_hop_candidate = CandidateRouteHop::FirstHop(FirstHopCandidate {
2761-
details, payer_node_id: &our_node_id,
2770+
details, payer_node_id: &our_node_id, targets_blinded_path: false
27622771
});
27632772
add_entry!(&first_hop_candidate,
27642773
aggregate_next_hops_fee_msat,
@@ -2789,7 +2798,9 @@ where L::Target: Logger {
27892798
// Both these cases (and other cases except reaching recommended_value_msat) mean that
27902799
// paths_collection will be stopped because found_new_path==false.
27912800
// This is not necessarily a routing failure.
2792-
'path_construction: while let Some(RouteGraphNode { node_id, total_cltv_delta, mut value_contribution_msat, path_length_to_node, .. }) = targets.pop() {
2801+
'path_construction: while let Some(RouteGraphNode {
2802+
node_id, total_cltv_delta, mut value_contribution_msat, path_length_to_node, is_intro_node, ..
2803+
}) = targets.pop() {
27932804

27942805
// Since we're going payee-to-payer, hitting our node as a target means we should stop
27952806
// traversing the graph and arrange the path out of what we found.
@@ -2926,7 +2937,7 @@ where L::Target: Logger {
29262937
Some(node) => {
29272938
add_entries_to_cheapest_to_target_node!(node, node_id,
29282939
value_contribution_msat,
2929-
total_cltv_delta, path_length_to_node);
2940+
total_cltv_delta, path_length_to_node, is_intro_node);
29302941
},
29312942
}
29322943
}

lightning/src/routing/scoring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ScoreLookUp for Probabilistic
13231323
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &ProbabilisticScoringFeeParameters
13241324
) -> u64 {
13251325
let (scid, target) = match candidate {
1326-
CandidateRouteHop::PublicHop(PublicHopCandidate { info, short_channel_id }) => {
1326+
CandidateRouteHop::PublicHop(PublicHopCandidate { info, short_channel_id, .. }) => {
13271327
(short_channel_id, info.target())
13281328
},
13291329
_ => return 0,

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ impl<'a> Router for TestRouter<'a> {
174174
let candidate = CandidateRouteHop::FirstHop(FirstHopCandidate {
175175
details: first_hops[idx],
176176
payer_node_id: &node_id,
177+
targets_blinded_path: false,
177178
});
178179
scorer.channel_penalty_msat(&candidate, usage, &Default::default());
179180
continue;
@@ -186,6 +187,7 @@ impl<'a> Router for TestRouter<'a> {
186187
let candidate = CandidateRouteHop::PublicHop(PublicHopCandidate {
187188
info: directed,
188189
short_channel_id: hop.short_channel_id,
190+
targets_blinded_path: false,
189191
});
190192
scorer.channel_penalty_msat(&candidate, usage, &Default::default());
191193
} else {

0 commit comments

Comments
 (0)