Use the new `total_cltv_expiry_delta()` in place of explicit sum
What changed, and why it matters
This is a tiny internal code cleanup: it replaces a manual loop that adds up CLTV expiry deltas with a new helper method that does the same thing. There is no functional change and no security relevance visible in the commit.
No action required. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors a single line in add_random_cltv_offset inside lightning/src/routing/router.rs. Previously the code computed path_total_cltv_expiry_delta by iterating over path.hops and summing h.cltv_expiry_delta. It now calls path.total_cltv_expiry_delta(). The arithmetic that follows (max_path_offset = payment_params.max_total_cltv_expiry_delta - path_total_cltv_expiry_delta) is unchanged. This is a pure refactor with no behavioral difference.
Changed components
lightning/src/routing/router.rsInspect captured patch +2 / −2
diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs
index 90697ad..f3b1f4e 100644
--- a/lightning/src/routing/router.rs
+++ b/lightning/src/routing/router.rs
@@ -3975,8 +3975,8 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
// Limit the offset so we never exceed the max_total_cltv_expiry_delta. To improve plausibility,
// we choose the limit to be the largest possible multiple of MEDIAN_HOP_CLTV_EXPIRY_DELTA.
- let path_total_cltv_expiry_delta: u32 = path.hops.iter().map(|h| h.cltv_expiry_delta).sum();
- let mut max_path_offset = payment_params.max_total_cltv_expiry_delta - path_total_cltv_expiry_delta;
+ let mut max_path_offset =
+ payment_params.max_total_cltv_expiry_delta - path.total_cltv_expiry_delta();
max_path_offset = cmp::max(
max_path_offset - (max_path_offset % MEDIAN_HOP_CLTV_EXPIRY_DELTA),
max_path_offset % MEDIAN_HOP_CLTV_EXPIRY_DELTA);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.