@@ -839,8 +839,7 @@ where L::Target: Logger {
839
839
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
840
840
841
841
// Do not consider candidates that exceed the maximum total cltv expiry limit.
842
- // We subtract 2*40 here in order to account for the privacy-enhancing random CLTV delta offset we add on top later
843
- let max_total_cltv_expiry_delta = payment_params. max_total_cltv_expiry_delta. checked_sub( 80 ) . unwrap_or( 0 ) ;
842
+ let max_total_cltv_expiry_delta = payment_params. max_total_cltv_expiry_delta;
844
843
let hop_total_cltv_delta = ( $next_hops_cltv_delta as u32 )
845
844
. checked_add( $candidate. cltv_expiry_delta( ) )
846
845
. unwrap_or( u32 :: max_value( ) ) ;
@@ -1569,20 +1568,22 @@ where L::Target: Logger {
1569
1568
shadow_ctlv_expiry_delta_offset = random_walk_length. wrapping_mul ( 40 ) ;
1570
1569
}
1571
1570
1572
- // Limit the offset to reduce the payment failure probability
1571
+ // Limit the total offset to reduce the worst-case locked liquidity timevalue
1573
1572
const MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET : u32 = 432 ; // 3*144
1574
1573
shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset, MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET ) ;
1575
1574
1575
+ // Limit the offset so we never exceed the max_total_cltv_expiry_delta
1576
+ let max_path_offset = payment_params. max_total_cltv_expiry_delta
1577
+ . checked_sub ( path. iter ( ) . fold ( 0 , |acc, b| b. as_ref ( ) . unwrap ( ) . cltv_expiry_delta . max ( acc) ) )
1578
+ . unwrap_or ( shadow_ctlv_expiry_delta_offset) ;
1579
+ shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset, max_path_offset) ;
1580
+
1576
1581
// Add 'shadow' CLTV offset to all hops but the final one
1577
1582
for h in path {
1578
1583
if let Ok ( hop) = h {
1579
1584
if hop. pubkey != payment_params. payee_pubkey {
1580
1585
hop. cltv_expiry_delta = hop. cltv_expiry_delta
1581
1586
. checked_add ( shadow_ctlv_expiry_delta_offset) . unwrap_or ( hop. cltv_expiry_delta ) ;
1582
- let max_total_cltv_expiry_delta = payment_params. max_total_cltv_expiry_delta ;
1583
- if hop. cltv_expiry_delta > max_total_cltv_expiry_delta {
1584
- return Err ( LightningError { err : "Chosen path exceeds max total CLTV delta limit" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1585
- }
1586
1587
}
1587
1588
}
1588
1589
}
0 commit comments