@@ -442,7 +442,7 @@ impl Writeable for RouteParameters {
442
442
( 2 , self . final_value_msat, required) ,
443
443
// LDK versions prior to 0.0.114 had the `final_cltv_expiry_delta` parameter in
444
444
// `RouteParameters` directly. For compatibility, we write it here.
445
- ( 4 , self . payment_params. final_cltv_expiry_delta, required ) ,
445
+ ( 4 , self . payment_params. payee . final_cltv_expiry_delta( ) , option ) ,
446
446
} ) ;
447
447
Ok ( ( ) )
448
448
}
@@ -453,11 +453,13 @@ impl Readable for RouteParameters {
453
453
_init_and_read_tlv_fields ! ( reader, {
454
454
( 0 , payment_params, ( required: ReadableArgs , 0 ) ) ,
455
455
( 2 , final_value_msat, required) ,
456
- ( 4 , final_cltv_expiry_delta , required ) ,
456
+ ( 4 , final_cltv_delta , option ) ,
457
457
} ) ;
458
458
let mut payment_params: PaymentParameters = payment_params. 0 . unwrap ( ) ;
459
- if payment_params. final_cltv_expiry_delta == 0 {
460
- payment_params. final_cltv_expiry_delta = final_cltv_expiry_delta. 0 . unwrap ( ) ;
459
+ if let Payee :: Clear { ref mut final_cltv_expiry_delta, .. } = payment_params. payee {
460
+ if final_cltv_expiry_delta == & 0 {
461
+ * final_cltv_expiry_delta = final_cltv_delta. ok_or ( DecodeError :: InvalidValue ) ?;
462
+ }
461
463
}
462
464
Ok ( Self {
463
465
payment_params,
@@ -526,9 +528,6 @@ pub struct PaymentParameters {
526
528
/// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
527
529
/// these SCIDs.
528
530
pub previously_failed_channels : Vec < u64 > ,
529
-
530
- /// The minimum CLTV delta at the end of the route. This value must not be zero.
531
- pub final_cltv_expiry_delta : u32 ,
532
531
}
533
532
534
533
impl Writeable for PaymentParameters {
@@ -549,7 +548,7 @@ impl Writeable for PaymentParameters {
549
548
( 6 , self . expiry_time, option) ,
550
549
( 7 , self . previously_failed_channels, vec_type) ,
551
550
( 8 , * blinded_hints, optional_vec) ,
552
- ( 9 , self . final_cltv_expiry_delta, required ) ,
551
+ ( 9 , self . payee . final_cltv_expiry_delta( ) , option ) ,
553
552
} ) ;
554
553
Ok ( ( ) )
555
554
}
@@ -582,6 +581,7 @@ impl ReadableArgs<u32> for PaymentParameters {
582
581
route_hints : clear_route_hints,
583
582
node_id : payee_pubkey. ok_or ( DecodeError :: InvalidValue ) ?,
584
583
features : features. map ( |f| f. bolt11 ( ) ) . flatten ( ) ,
584
+ final_cltv_expiry_delta : final_cltv_expiry_delta. 0 . unwrap ( ) ,
585
585
}
586
586
} ;
587
587
Ok ( Self {
@@ -591,7 +591,6 @@ impl ReadableArgs<u32> for PaymentParameters {
591
591
max_channel_saturation_power_of_half : _init_tlv_based_struct_field ! ( max_channel_saturation_power_of_half, ( default_value, unused) ) ,
592
592
expiry_time,
593
593
previously_failed_channels : previously_failed_channels. unwrap_or ( Vec :: new ( ) ) ,
594
- final_cltv_expiry_delta : _init_tlv_based_struct_field ! ( final_cltv_expiry_delta, ( default_value, unused) ) ,
595
594
} )
596
595
}
597
596
}
@@ -604,13 +603,12 @@ impl PaymentParameters {
604
603
/// provided.
605
604
pub fn from_node_id ( payee_pubkey : PublicKey , final_cltv_expiry_delta : u32 ) -> Self {
606
605
Self {
607
- payee : Payee :: Clear { node_id : payee_pubkey, route_hints : vec ! [ ] , features : None } ,
606
+ payee : Payee :: Clear { node_id : payee_pubkey, route_hints : vec ! [ ] , features : None , final_cltv_expiry_delta } ,
608
607
expiry_time : None ,
609
608
max_total_cltv_expiry_delta : DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
610
609
max_path_count : DEFAULT_MAX_PATH_COUNT ,
611
610
max_channel_saturation_power_of_half : 2 ,
612
611
previously_failed_channels : Vec :: new ( ) ,
613
- final_cltv_expiry_delta,
614
612
}
615
613
}
616
614
@@ -629,8 +627,12 @@ impl PaymentParameters {
629
627
pub fn with_bolt11_features ( self , features : InvoiceFeatures ) -> Result < Self , ( ) > {
630
628
match self . payee {
631
629
Payee :: Blinded { .. } => Err ( ( ) ) ,
632
- Payee :: Clear { route_hints, node_id, .. } =>
633
- Ok ( Self { payee : Payee :: Clear { route_hints, node_id, features : Some ( features) } , ..self } )
630
+ Payee :: Clear { route_hints, node_id, final_cltv_expiry_delta, .. } =>
631
+ Ok ( Self {
632
+ payee : Payee :: Clear {
633
+ route_hints, node_id, features : Some ( features) , final_cltv_expiry_delta
634
+ } , ..self
635
+ } )
634
636
}
635
637
}
636
638
@@ -641,8 +643,12 @@ impl PaymentParameters {
641
643
pub fn with_route_hints ( self , route_hints : Vec < RouteHint > ) -> Result < Self , ( ) > {
642
644
match self . payee {
643
645
Payee :: Blinded { .. } => Err ( ( ) ) ,
644
- Payee :: Clear { node_id, features, .. } =>
645
- Ok ( Self { payee : Payee :: Clear { route_hints, node_id, features } , ..self } )
646
+ Payee :: Clear { node_id, features, final_cltv_expiry_delta, .. } =>
647
+ Ok ( Self {
648
+ payee : Payee :: Clear {
649
+ route_hints, node_id, features, final_cltv_expiry_delta,
650
+ } , ..self
651
+ } )
646
652
}
647
653
}
648
654
@@ -704,6 +710,8 @@ pub enum Payee {
704
710
///
705
711
/// [`for_keysend`]: PaymentParameters::for_keysend
706
712
features : Option < InvoiceFeatures > ,
713
+ /// The minimum CLTV delta at the end of the route. This value must not be zero.
714
+ final_cltv_expiry_delta : u32 ,
707
715
} ,
708
716
}
709
717
@@ -732,6 +740,12 @@ impl Payee {
732
740
Self :: Blinded { features, .. } => features. as_ref ( ) . map ( |f| FeaturesRef :: Bolt12 ( f) ) ,
733
741
}
734
742
}
743
+ fn final_cltv_expiry_delta ( & self ) -> Option < u32 > {
744
+ match self {
745
+ Self :: Clear { final_cltv_expiry_delta, .. } => Some ( * final_cltv_expiry_delta) ,
746
+ _ => None ,
747
+ }
748
+ }
735
749
}
736
750
737
751
enum FeaturesRef < ' a > {
@@ -1238,7 +1252,8 @@ where L::Target: Logger {
1238
1252
_ => return Err ( LightningError { err : "Routing to blinded paths isn't supported yet" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ,
1239
1253
1240
1254
}
1241
- if payment_params. max_total_cltv_expiry_delta <= payment_params. final_cltv_expiry_delta {
1255
+ let final_cltv_expiry_delta = payment_params. payee . final_cltv_expiry_delta ( ) . unwrap_or ( 0 ) ;
1256
+ if payment_params. max_total_cltv_expiry_delta <= final_cltv_expiry_delta {
1242
1257
return Err ( LightningError { err : "Can't find a route where the maximum total CLTV expiry delta is below the final CLTV expiry." . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1243
1258
}
1244
1259
@@ -1470,9 +1485,9 @@ where L::Target: Logger {
1470
1485
// In order to already account for some of the privacy enhancing random CLTV
1471
1486
// expiry delta offset we add on top later, we subtract a rough estimate
1472
1487
// (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here.
1473
- let max_total_cltv_expiry_delta = ( payment_params. max_total_cltv_expiry_delta - payment_params . final_cltv_expiry_delta)
1488
+ let max_total_cltv_expiry_delta = ( payment_params. max_total_cltv_expiry_delta - final_cltv_expiry_delta)
1474
1489
. checked_sub( 2 * MEDIAN_HOP_CLTV_EXPIRY_DELTA )
1475
- . unwrap_or( payment_params. max_total_cltv_expiry_delta - payment_params . final_cltv_expiry_delta) ;
1490
+ . unwrap_or( payment_params. max_total_cltv_expiry_delta - final_cltv_expiry_delta) ;
1476
1491
let hop_total_cltv_delta = ( $next_hops_cltv_delta as u32 )
1477
1492
. saturating_add( $candidate. cltv_expiry_delta( ) ) ;
1478
1493
let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta;
@@ -2162,7 +2177,7 @@ where L::Target: Logger {
2162
2177
} ) . collect :: < Vec < _ > > ( ) ;
2163
2178
// Propagate the cltv_expiry_delta one hop backwards since the delta from the current hop is
2164
2179
// applicable for the previous hop.
2165
- path. iter_mut ( ) . rev ( ) . fold ( payment_params . final_cltv_expiry_delta , |prev_cltv_expiry_delta, hop| {
2180
+ path. iter_mut ( ) . rev ( ) . fold ( final_cltv_expiry_delta, |prev_cltv_expiry_delta, hop| {
2166
2181
core:: mem:: replace ( & mut hop. as_mut ( ) . unwrap ( ) . cltv_expiry_delta , prev_cltv_expiry_delta)
2167
2182
} ) ;
2168
2183
selected_paths. push ( path) ;
0 commit comments