Skip to content

Commit 435a325

Browse files
committed
Use correct penalty and CLTV delta in route hints
For route hints, the aggregate next hops path penalty and CLTV delta should be computed after considering each hop rather than before. Otherwise, these aggregate values will include values from the current hop, too.
1 parent a190aed commit 435a325

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lightning/src/routing/router.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,16 +1295,6 @@ where L::Target: Logger {
12951295
short_channel_id: hop.short_channel_id,
12961296
})
12971297
.unwrap_or_else(|| CandidateRouteHop::PrivateHop { hint: hop });
1298-
let amount_to_transfer_msat = final_value_msat + aggregate_next_hops_fee_msat;
1299-
let capacity_msat = candidate.effective_capacity().as_msat();
1300-
aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
1301-
.saturating_add(scorer.channel_penalty_msat(hop.short_channel_id, amount_to_transfer_msat, capacity_msat, &source, &target));
1302-
1303-
aggregate_next_hops_cltv_delta = aggregate_next_hops_cltv_delta
1304-
.saturating_add(hop.cltv_expiry_delta as u32);
1305-
1306-
aggregate_next_hops_path_length = aggregate_next_hops_path_length
1307-
.saturating_add(1);
13081298

13091299
if !add_entry!(candidate, source, target, aggregate_next_hops_fee_msat,
13101300
path_value_msat, aggregate_next_hops_path_htlc_minimum_msat,
@@ -1316,6 +1306,17 @@ where L::Target: Logger {
13161306
hop_used = false;
13171307
}
13181308

1309+
let amount_to_transfer_msat = final_value_msat + aggregate_next_hops_fee_msat;
1310+
let capacity_msat = candidate.effective_capacity().as_msat();
1311+
aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
1312+
.saturating_add(scorer.channel_penalty_msat(hop.short_channel_id, amount_to_transfer_msat, capacity_msat, &source, &target));
1313+
1314+
aggregate_next_hops_cltv_delta = aggregate_next_hops_cltv_delta
1315+
.saturating_add(hop.cltv_expiry_delta as u32);
1316+
1317+
aggregate_next_hops_path_length = aggregate_next_hops_path_length
1318+
.saturating_add(1);
1319+
13191320
// Searching for a direct channel between last checked hop and first_hop_targets
13201321
if let Some(first_channels) = first_hop_targets.get(&NodeId::from_pubkey(&prev_hop_id)) {
13211322
for details in first_channels {

0 commit comments

Comments
 (0)