@@ -1403,7 +1403,7 @@ struct RouteGraphNode {
1403
1403
// - how much value can channels following this node (up to the destination) can contribute,
1404
1404
// considering their capacity and fees
1405
1405
value_contribution_msat : u64 ,
1406
- total_cltv_delta : u32 ,
1406
+ total_cltv_delta : u16 ,
1407
1407
/// The number of hops walked up to this node.
1408
1408
path_length_to_node : u8 ,
1409
1409
}
@@ -2697,6 +2697,16 @@ where L::Target: Logger {
2697
2697
// drop the requirement by setting this to 0.
2698
2698
let mut channel_saturation_pow_half = payment_params. max_channel_saturation_power_of_half ;
2699
2699
2700
+ // In order to already account for some of the privacy enhancing random CLTV
2701
+ // expiry delta offset we add on top later, we subtract a rough estimate
2702
+ // (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here.
2703
+ let max_total_cltv_expiry_delta: u16 =
2704
+ ( payment_params. max_total_cltv_expiry_delta - final_cltv_expiry_delta)
2705
+ . checked_sub ( 2 * MEDIAN_HOP_CLTV_EXPIRY_DELTA )
2706
+ . unwrap_or ( payment_params. max_total_cltv_expiry_delta - final_cltv_expiry_delta)
2707
+ . try_into ( )
2708
+ . unwrap_or ( u16:: MAX ) ;
2709
+
2700
2710
// Keep track of how much liquidity has been used in selected channels or blinded paths. Used to
2701
2711
// determine if the channel can be used by additional MPP paths or to inform path finding
2702
2712
// decisions. It is aware of direction *only* to ensure that the correct htlc_maximum_msat value
@@ -2786,15 +2796,9 @@ where L::Target: Logger {
2786
2796
let exceeds_max_path_length = path_length_to_node > max_path_length;
2787
2797
2788
2798
// Do not consider candidates that exceed the maximum total cltv expiry limit.
2789
- // In order to already account for some of the privacy enhancing random CLTV
2790
- // expiry delta offset we add on top later, we subtract a rough estimate
2791
- // (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here.
2792
- let max_total_cltv_expiry_delta = ( payment_params. max_total_cltv_expiry_delta - final_cltv_expiry_delta)
2793
- . checked_sub( 2 * MEDIAN_HOP_CLTV_EXPIRY_DELTA )
2794
- . unwrap_or( payment_params. max_total_cltv_expiry_delta - final_cltv_expiry_delta) ;
2795
2799
let hop_total_cltv_delta = ( $next_hops_cltv_delta as u32 )
2796
2800
. saturating_add( cltv_expiry_delta) ;
2797
- let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta;
2801
+ let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta as u32 ;
2798
2802
2799
2803
let value_contribution_msat = cmp:: min( available_value_contribution_msat, $next_hops_value_contribution) ;
2800
2804
// Includes paying fees for the use of the following channels.
@@ -2999,12 +3003,13 @@ where L::Target: Logger {
2999
3003
#[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
3000
3004
{
3001
3005
assert!( !old_entry. best_path_from_hop_selected) ;
3006
+ assert!( hop_total_cltv_delta <= u16 :: MAX as u32 ) ;
3002
3007
}
3003
3008
3004
3009
let new_graph_node = RouteGraphNode {
3005
3010
node_counter: src_node_counter,
3006
3011
score: cmp:: max( total_fee_msat, path_htlc_minimum_msat) . saturating_add( path_penalty_msat) ,
3007
- total_cltv_delta: hop_total_cltv_delta,
3012
+ total_cltv_delta: hop_total_cltv_delta as u16 ,
3008
3013
value_contribution_msat,
3009
3014
path_length_to_node,
3010
3015
} ;
0 commit comments