Skip to content

Commit 5d10f6b

Browse files
committed
Validate CLTV somewhat in Route::debug_assert_route_meets_params
Now that we've cleaned up trampoline CLTV building and added `Path::total_cltv_expiry_delta`, we can use both to do some basic validation of CLTV values on blinded tails in `Route::debug_assert_route_meets_params`
1 parent 0aaa56c commit 5d10f6b

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

lightning/src/routing/router.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,17 @@ impl Route {
739739
return Err(());
740740
}
741741

742+
let total_cltv_delta = path.total_cltv_expiry_delta();
743+
if total_cltv_delta > route_params.payment_params.max_total_cltv_expiry_delta {
744+
let err = format!(
745+
"Path had a total CLTV of {total_cltv_delta} which is greater than the maximum we're allowed {}",
746+
route_params.payment_params.max_total_cltv_expiry_delta,
747+
);
748+
debug_assert!(false, "{}", err);
749+
log_error!(logger, "{}", err);
750+
return Err(());
751+
}
752+
742753
if path.hops.len() > route_params.payment_params.max_path_length.into() {
743754
let err = format!(
744755
"Path had a length of {}, which is greater than the maximum we're allowed ({})",
@@ -751,6 +762,21 @@ impl Route {
751762
// This is a bug, but there's not a material safety risk to making this
752763
// payment, so we don't bother to error here.
753764
}
765+
766+
if let Some(tail) = &path.blinded_tail {
767+
let trampoline_cltv_sum =
768+
tail.trampoline_hops.iter().map(|hop| hop.cltv_expiry_delta).sum();
769+
let min_cltv =
770+
tail.excess_final_cltv_expiry_delta.saturating_add(trampoline_cltv_sum);
771+
let last_hop_cltv_delta = path.hops.last().unwrap().cltv_expiry_delta;
772+
if min_cltv > last_hop_cltv_delta {
773+
let err = format!(
774+
"Path had a total trampoline and excess blinded path CLTV of {min_cltv}, which is less than the total last-hop CLTV delta of {last_hop_cltv_delta}"
775+
);
776+
debug_assert!(false, "{}", err);
777+
log_error!(logger, "{}", err);
778+
}
779+
}
754780
}
755781
}
756782

0 commit comments

Comments
 (0)