Skip to content

Commit 71c163b

Browse files
committed
Make max_total_cltv_expiry_delta include the final CLTV
This fixes an integer underflow found by the `router` fuzz target in CI.
1 parent 2bba1d4 commit 71c163b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lightning/src/routing/router.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ where L::Target: Logger {
670670
}
671671
}
672672
}
673+
if payment_params.max_total_cltv_expiry_delta <= final_cltv_expiry_delta {
674+
return Err(LightningError{err: "Can't find a route where the total CLTV expiry delta is below the final CLTV expiry.".to_owned(), action: ErrorAction::IgnoreError});
675+
}
673676

674677
// The general routing idea is the following:
675678
// 1. Fill first/last hops communicated by the caller.
@@ -866,9 +869,9 @@ where L::Target: Logger {
866869
// In order to already account for some of the privacy enhancing random CLTV
867870
// expiry delta offset we add on top later, we subtract a rough estimate
868871
// (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here.
869-
let max_total_cltv_expiry_delta = payment_params.max_total_cltv_expiry_delta
872+
let max_total_cltv_expiry_delta = (payment_params.max_total_cltv_expiry_delta - final_cltv_expiry_delta)
870873
.checked_sub(2*MEDIAN_HOP_CLTV_EXPIRY_DELTA)
871-
.unwrap_or(payment_params.max_total_cltv_expiry_delta);
874+
.unwrap_or(payment_params.max_total_cltv_expiry_delta - final_cltv_expiry_delta);
872875
let hop_total_cltv_delta = ($next_hops_cltv_delta as u32)
873876
.checked_add($candidate.cltv_expiry_delta())
874877
.unwrap_or(u32::max_value());

0 commit comments

Comments
 (0)