@@ -1403,7 +1403,7 @@ struct RouteGraphNode {
14031403 // - how much value can channels following this node (up to the destination) can contribute,
14041404 // considering their capacity and fees
14051405 value_contribution_msat : u64 ,
1406- total_cltv_delta : u32 ,
1406+ total_cltv_delta : u16 ,
14071407 /// The number of hops walked up to this node.
14081408 path_length_to_node : u8 ,
14091409}
@@ -2697,6 +2697,16 @@ where L::Target: Logger {
26972697 // drop the requirement by setting this to 0.
26982698 let mut channel_saturation_pow_half = payment_params. max_channel_saturation_power_of_half ;
26992699
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+
27002710 // Keep track of how much liquidity has been used in selected channels or blinded paths. Used to
27012711 // determine if the channel can be used by additional MPP paths or to inform path finding
27022712 // decisions. It is aware of direction *only* to ensure that the correct htlc_maximum_msat value
@@ -2786,15 +2796,9 @@ where L::Target: Logger {
27862796 let exceeds_max_path_length = path_length_to_node > max_path_length;
27872797
27882798 // 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) ;
27952799 let hop_total_cltv_delta = ( $next_hops_cltv_delta as u32 )
27962800 . 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 ;
27982802
27992803 let value_contribution_msat = cmp:: min( available_value_contribution_msat, $next_hops_value_contribution) ;
28002804 // Includes paying fees for the use of the following channels.
@@ -2999,12 +3003,13 @@ where L::Target: Logger {
29993003 #[ cfg( all( not( ldk_bench) , any( test, fuzzing) ) ) ]
30003004 {
30013005 assert!( !old_entry. best_path_from_hop_selected) ;
3006+ assert!( hop_total_cltv_delta <= u16 :: MAX as u32 ) ;
30023007 }
30033008
30043009 let new_graph_node = RouteGraphNode {
30053010 node_counter: src_node_counter,
30063011 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 ,
30083013 value_contribution_msat,
30093014 path_length_to_node,
30103015 } ;
0 commit comments