Skip to content

Commit 4e9cb21

Browse files
committed
Limit the maximum shadow offset, but do not fail.
1 parent 6c071c2 commit 4e9cb21

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lightning/src/routing/router.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,7 @@ where L::Target: Logger {
839839
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
840840

841841
// Do not consider candidates that exceed the maximum total cltv expiry limit.
842-
// We subtract 2*40 here in order to account for the privacy-enhancing random CLTV delta offset we add on top later
843-
let max_total_cltv_expiry_delta = payment_params.max_total_cltv_expiry_delta.checked_sub(80).unwrap_or(0);
842+
let max_total_cltv_expiry_delta = payment_params.max_total_cltv_expiry_delta;
844843
let hop_total_cltv_delta = ($next_hops_cltv_delta as u32)
845844
.checked_add($candidate.cltv_expiry_delta())
846845
.unwrap_or(u32::max_value());
@@ -1569,20 +1568,22 @@ where L::Target: Logger {
15691568
shadow_ctlv_expiry_delta_offset = random_walk_length.wrapping_mul(40);
15701569
}
15711570

1572-
// Limit the offset to reduce the payment failure probability
1571+
// Limit the total offset to reduce the worst-case locked liquidity timevalue
15731572
const MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET: u32 = 432; // 3*144
15741573
shadow_ctlv_expiry_delta_offset = cmp::min(shadow_ctlv_expiry_delta_offset, MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET);
15751574

1575+
// Limit the offset so we never exceed the max_total_cltv_expiry_delta
1576+
let max_path_offset = payment_params.max_total_cltv_expiry_delta
1577+
.checked_sub(path.iter().fold(0, |acc,b| b.as_ref().unwrap().cltv_expiry_delta.max(acc)))
1578+
.unwrap_or(shadow_ctlv_expiry_delta_offset);
1579+
shadow_ctlv_expiry_delta_offset = cmp::min(shadow_ctlv_expiry_delta_offset, max_path_offset);
1580+
15761581
// Add 'shadow' CLTV offset to all hops but the final one
15771582
for h in path {
15781583
if let Ok(hop) = h {
15791584
if hop.pubkey != payment_params.payee_pubkey {
15801585
hop.cltv_expiry_delta = hop.cltv_expiry_delta
15811586
.checked_add(shadow_ctlv_expiry_delta_offset).unwrap_or(hop.cltv_expiry_delta);
1582-
let max_total_cltv_expiry_delta = payment_params.max_total_cltv_expiry_delta;
1583-
if hop.cltv_expiry_delta > max_total_cltv_expiry_delta {
1584-
return Err(LightningError{err: "Chosen path exceeds max total CLTV delta limit".to_owned(), action: ErrorAction::IgnoreError});
1585-
}
15861587
}
15871588
}
15881589
}

0 commit comments

Comments
 (0)