@@ -861,7 +861,10 @@ where L::Target: Logger {
861
861
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
862
862
863
863
// Do not consider candidates that exceed the maximum total cltv expiry limit.
864
- let max_total_cltv_expiry_delta = payment_params. max_total_cltv_expiry_delta;
864
+ // We subtract 2*40 here in order to account for some of the privacy-enhancing
865
+ // random CLTV expiry delta offset we add on top later.
866
+ let max_total_cltv_expiry_delta = payment_params. max_total_cltv_expiry_delta
867
+ . checked_sub( 2 * 40 ) . unwrap_or( payment_params. max_total_cltv_expiry_delta) ;
865
868
let hop_total_cltv_delta = ( $next_hops_cltv_delta as u32 )
866
869
. checked_add( $candidate. cltv_expiry_delta( ) )
867
870
. unwrap_or( u32 :: max_value( ) ) ;
@@ -1602,12 +1605,14 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
1602
1605
const MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET : u32 = 3 * 144 ;
1603
1606
shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset, MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET ) ;
1604
1607
1605
- // Limit the offset so we never exceed the max_total_cltv_expiry_delta
1606
- let max_path_offset = payment_params. max_total_cltv_expiry_delta
1608
+ // Limit the offset so we never exceed the max_total_cltv_expiry_delta. To improve plausibility,
1609
+ // we choose the limit to be the largest possible multiple of 40.
1610
+ let mut max_path_offset = payment_params. max_total_cltv_expiry_delta
1607
1611
. checked_sub ( path. iter ( ) . map ( |h| h. cltv_expiry_delta ) . sum ( ) )
1608
- . unwrap_or ( shadow_ctlv_expiry_delta_offset) ;
1609
- shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset,
1610
- max_path_offset. checked_sub ( max_path_offset. wrapping_rem ( 40 ) ) . unwrap_or ( max_path_offset) ) ;
1612
+ . unwrap_or ( 0 ) ;
1613
+ max_path_offset = max_path_offset. wrapping_sub ( max_path_offset. wrapping_rem ( 40 ) )
1614
+ . max ( max_path_offset. wrapping_rem ( 40 ) ) ;
1615
+ shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset, max_path_offset) ;
1611
1616
1612
1617
// Add 'shadow' CLTV offset to the final hop
1613
1618
if let Some ( last_hop) = path. last_mut ( ) {
0 commit comments