@@ -839,7 +839,8 @@ 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
- let max_total_cltv_expiry_delta = payment_params. max_total_cltv_expiry_delta;
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 ) ;
843
844
let hop_total_cltv_delta = ( $next_hops_cltv_delta as u32 )
844
845
. checked_add( $candidate. cltv_expiry_delta( ) )
845
846
. unwrap_or( u32 :: max_value( ) ) ;
@@ -1560,13 +1561,12 @@ where L::Target: Logger {
1560
1561
}
1561
1562
}
1562
1563
} else {
1563
- // If the entire path is private, choose a random offset from multiples of 144, i.e., our
1564
- // default cltv_expiry_delta
1564
+ // If the entire path is private, choose a random offset from multiples of 40, i.e., the most used cltv_expiry_delta
1565
1565
let mut prng = ChaCha20 :: new ( random_seed_bytes, & [ 0u8 ; 8 ] ) ;
1566
1566
let mut random_bytes = [ 0u8 ; 4 ] ;
1567
1567
prng. process_in_place ( & mut random_bytes) ;
1568
1568
let random_walk_length = u32:: from_be_bytes ( random_bytes) . wrapping_rem ( 3 ) . wrapping_add ( 1 ) ;
1569
- shadow_ctlv_expiry_delta_offset = random_walk_length. wrapping_mul ( 144 ) ;
1569
+ shadow_ctlv_expiry_delta_offset = random_walk_length. wrapping_mul ( 40 ) ;
1570
1570
}
1571
1571
1572
1572
// Limit the offset to reduce the payment failure probability
@@ -1579,6 +1579,10 @@ where L::Target: Logger {
1579
1579
if hop. pubkey != payment_params. payee_pubkey {
1580
1580
hop. cltv_expiry_delta = hop. cltv_expiry_delta
1581
1581
. 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
+ }
1582
1586
}
1583
1587
}
1584
1588
}
0 commit comments