Skip to content

Commit 85da1a1

Browse files
committed
Avoid adding duplicate hint candidates if they are first hops
If we have a direct channel to a node generating an invoice with route hints, we'd previously happily add multiple candidates that all refer to the same channel. To keep our candidate set small and unify our tracking where possible, we now check if its `short_channel_id` is an `outbound_scid_alias` of any of our first hops and refrain from adding another candidate if it's the case.
1 parent 3fa018a commit 85da1a1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lightning/src/routing/router.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,7 @@ where L::Target: Logger {
21262126
for (idx, (hop, prev_hop_id)) in hop_iter.zip(prev_hop_iter).enumerate() {
21272127
let source = NodeId::from_pubkey(&hop.src_node_id);
21282128
let target = NodeId::from_pubkey(&prev_hop_id);
2129+
21292130
let candidate = network_channels
21302131
.get(&hop.short_channel_id)
21312132
.and_then(|channel| channel.as_directed_to(&target))
@@ -2135,6 +2136,14 @@ where L::Target: Logger {
21352136
})
21362137
.unwrap_or_else(|| CandidateRouteHop::PrivateHop { hint: hop });
21372138

2139+
if let Some(first_channels) = first_hop_targets.get(&target) {
2140+
if first_channels.iter().any(|d| d.outbound_scid_alias == Some(hop.short_channel_id)) {
2141+
log_trace!(logger, "Ignoring route hint hop {} (and any following) due to it being a direct channel of ours.",
2142+
LoggedCandidateHop(&candidate));
2143+
break;
2144+
}
2145+
}
2146+
21382147
if let Some(hop_used_msat) = add_entry!(candidate, source, target,
21392148
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
21402149
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
@@ -2169,12 +2178,12 @@ where L::Target: Logger {
21692178
.saturating_add(1);
21702179

21712180
// Searching for a direct channel between last checked hop and first_hop_targets
2172-
if let Some(first_channels) = first_hop_targets.get_mut(&NodeId::from_pubkey(&prev_hop_id)) {
2181+
if let Some(first_channels) = first_hop_targets.get_mut(&target) {
21732182
sort_first_hop_channels(first_channels, &used_liquidities,
21742183
recommended_value_msat, our_node_pubkey);
21752184
for details in first_channels {
21762185
let first_hop_candidate = CandidateRouteHop::FirstHop { details };
2177-
add_entry!(first_hop_candidate, our_node_id, NodeId::from_pubkey(&prev_hop_id),
2186+
add_entry!(first_hop_candidate, our_node_id, target,
21782187
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
21792188
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
21802189
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length);

0 commit comments

Comments
 (0)