@@ -177,6 +177,9 @@ impl_writeable_tlv_based!(RouteParameters, {
177
177
/// Maximum total CTLV difference we allow for a full payment path.
178
178
pub const DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA : u32 = 1008 ;
179
179
180
+ /// The median hop CLTV expiry delta currently seen in the network.
181
+ const MEDIAN_HOP_CLTV_EXPIRY_DELTA : u32 = 40 ;
182
+
180
183
/// The recipient of a payment.
181
184
#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
182
185
pub struct PaymentParameters {
@@ -259,7 +262,6 @@ impl PaymentParameters {
259
262
#[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
260
263
pub struct RouteHint ( pub Vec < RouteHintHop > ) ;
261
264
262
-
263
265
impl Writeable for RouteHint {
264
266
fn write < W : :: util:: ser:: Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
265
267
( self . 0 . len ( ) as u64 ) . write ( writer) ?;
@@ -861,10 +863,12 @@ where L::Target: Logger {
861
863
let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
862
864
863
865
// Do not consider candidates that exceed the maximum total cltv expiry limit.
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
+ // In order to already account for some of the privacy enhancing random CLTV
867
+ // expiry delta offset we add on top later, we subtract a rough estimate
868
+ // (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here.
866
869
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) ;
870
+ . checked_sub( 2 * MEDIAN_HOP_CLTV_EXPIRY_DELTA )
871
+ . unwrap_or( payment_params. max_total_cltv_expiry_delta) ;
868
872
let hop_total_cltv_delta = ( $next_hops_cltv_delta as u32 )
869
873
. checked_add( $candidate. cltv_expiry_delta( ) )
870
874
. unwrap_or( u32 :: max_value( ) ) ;
@@ -1592,26 +1596,27 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
1592
1596
}
1593
1597
}
1594
1598
} else {
1595
- // If the entire path is private, choose a random offset from multiples of 40,
1596
- // which is the most prevalent cltv_expiry_delta currently used in the network
1599
+ // If the entire path is private, choose a random offset from multiples of
1600
+ // MEDIAN_HOP_CLTV_EXPIRY_DELTA
1597
1601
let mut prng = ChaCha20 :: new ( random_seed_bytes, & [ 0u8 ; 8 ] ) ;
1598
1602
let mut random_bytes = [ 0u8 ; 4 ] ;
1599
1603
prng. process_in_place ( & mut random_bytes) ;
1600
1604
let random_walk_length = u32:: from_be_bytes ( random_bytes) . wrapping_rem ( 3 ) . wrapping_add ( 1 ) ;
1601
- shadow_ctlv_expiry_delta_offset = random_walk_length. wrapping_mul ( 40 ) ;
1605
+ shadow_ctlv_expiry_delta_offset = random_walk_length. wrapping_mul ( MEDIAN_HOP_CLTV_EXPIRY_DELTA ) ;
1602
1606
}
1603
1607
1604
1608
// Limit the total offset to reduce the worst-case locked liquidity timevalue
1605
1609
const MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET : u32 = 3 * 144 ;
1606
1610
shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset, MAX_SHADOW_CLTV_EXPIRY_DELTA_OFFSET ) ;
1607
1611
1608
1612
// 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 .
1613
+ // we choose the limit to be the largest possible multiple of MEDIAN_HOP_CLTV_EXPIRY_DELTA .
1610
1614
let mut max_path_offset = payment_params. max_total_cltv_expiry_delta
1611
1615
. checked_sub ( path. iter ( ) . map ( |h| h. cltv_expiry_delta ) . sum ( ) )
1612
1616
. 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 ) ) ;
1617
+ max_path_offset = max_path_offset
1618
+ . wrapping_sub ( max_path_offset. wrapping_rem ( MEDIAN_HOP_CLTV_EXPIRY_DELTA ) )
1619
+ . max ( max_path_offset. wrapping_rem ( MEDIAN_HOP_CLTV_EXPIRY_DELTA ) ) ;
1615
1620
shadow_ctlv_expiry_delta_offset = cmp:: min ( shadow_ctlv_expiry_delta_offset, max_path_offset) ;
1616
1621
1617
1622
// Add 'shadow' CLTV offset to the final hop
0 commit comments