Skip to content

Commit 773e76b

Browse files
committed
Consider offset in pathfinding. Revisit max_path_offset limit.
1 parent 322aee8 commit 773e76b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lightning/src/routing/router.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,10 @@ where L::Target: Logger {
861861
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
862862

863863
// Do not consider candidates that exceed the maximum total cltv expiry limit.
864-
let max_total_cltv_expiry_delta = payment_params.max_total_cltv_expiry_delta;
864+
// We subtract 2*40 here in order to account for some of the privacy-enhancing
865+
// random CLTV expiry delta offset we add on top later.
866+
let max_total_cltv_expiry_delta = payment_params.max_total_cltv_expiry_delta
867+
.checked_sub(2*40).unwrap_or(payment_params.max_total_cltv_expiry_delta);
865868
let hop_total_cltv_delta = ($next_hops_cltv_delta as u32)
866869
.checked_add($candidate.cltv_expiry_delta())
867870
.unwrap_or(u32::max_value());
@@ -1602,12 +1605,14 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
16021605
const MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET: u32 = 3*144;
16031606
shadow_ctlv_expiry_delta_offset = cmp::min(shadow_ctlv_expiry_delta_offset, MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET);
16041607

1605-
// Limit the offset so we never exceed the max_total_cltv_expiry_delta
1606-
let max_path_offset = payment_params.max_total_cltv_expiry_delta
1608+
// Limit the offset so we never exceed the max_total_cltv_expiry_delta. To improve plausibility,
1609+
// we choose the limit to be the largest possible multiple of 40.
1610+
let mut max_path_offset = payment_params.max_total_cltv_expiry_delta
16071611
.checked_sub(path.iter().map(|h| h.cltv_expiry_delta).sum())
1608-
.unwrap_or(shadow_ctlv_expiry_delta_offset);
1609-
shadow_ctlv_expiry_delta_offset = cmp::min(shadow_ctlv_expiry_delta_offset,
1610-
max_path_offset.checked_sub(max_path_offset.wrapping_rem(40)).unwrap_or(max_path_offset));
1612+
.unwrap_or(0);
1613+
max_path_offset = max_path_offset.wrapping_sub(max_path_offset.wrapping_rem(40))
1614+
.max(max_path_offset.wrapping_rem(40));
1615+
shadow_ctlv_expiry_delta_offset = cmp::min(shadow_ctlv_expiry_delta_offset, max_path_offset);
16111616

16121617
// Add 'shadow' CLTV offset to the final hop
16131618
if let Some(last_hop) = path.last_mut() {

0 commit comments

Comments
 (0)