Skip to content

Commit c480b0c

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 7a6d309 commit c480b0c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lightning/src/routing/router.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,15 @@ where L::Target: Logger {
21672167
for (idx, (hop, prev_hop_id)) in hop_iter.zip(prev_hop_iter).enumerate() {
21682168
let source = NodeId::from_pubkey(&hop.src_node_id);
21692169
let target = NodeId::from_pubkey(&prev_hop_id);
2170+
2171+
if let Some(first_channels) = first_hop_targets.get(&target) {
2172+
if first_channels.iter().any(|d| d.outbound_scid_alias == Some(hop.short_channel_id)) {
2173+
log_trace!(logger, "Ignoring route hint with SCID {} (and any previous) due to it being a direct channel of ours.",
2174+
hop.short_channel_id);
2175+
break;
2176+
}
2177+
}
2178+
21702179
let candidate = network_channels
21712180
.get(&hop.short_channel_id)
21722181
.and_then(|channel| channel.as_directed_to(&target))
@@ -2210,12 +2219,12 @@ where L::Target: Logger {
22102219
.saturating_add(1);
22112220

22122221
// Searching for a direct channel between last checked hop and first_hop_targets
2213-
if let Some(first_channels) = first_hop_targets.get_mut(&NodeId::from_pubkey(&prev_hop_id)) {
2222+
if let Some(first_channels) = first_hop_targets.get_mut(&target) {
22142223
sort_first_hop_channels(first_channels, &used_liquidities,
22152224
recommended_value_msat, our_node_pubkey);
22162225
for details in first_channels {
22172226
let first_hop_candidate = CandidateRouteHop::FirstHop { details };
2218-
add_entry!(first_hop_candidate, our_node_id, NodeId::from_pubkey(&prev_hop_id),
2227+
add_entry!(first_hop_candidate, our_node_id, target,
22192228
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
22202229
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
22212230
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length);

0 commit comments

Comments
 (0)