@@ -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
}
@@ -579,6 +578,7 @@ impl ReadableArgs<u32> for PaymentParameters {
579
578
route_hints : clear_route_hints,
580
579
node_id : payee_pubkey. ok_or ( DecodeError :: InvalidValue ) ?,
581
580
features,
581
+ final_cltv_expiry_delta : final_cltv_expiry_delta. 0 . unwrap ( ) ,
582
582
}
583
583
} ;
584
584
Ok ( Self {
@@ -588,7 +588,6 @@ impl ReadableArgs<u32> for PaymentParameters {
588
588
max_channel_saturation_power_of_half : _init_tlv_based_struct_field ! ( max_channel_saturation_power_of_half, ( default_value, unused) ) ,
589
589
expiry_time,
590
590
previously_failed_channels : previously_failed_channels. unwrap_or ( Vec :: new ( ) ) ,
591
- final_cltv_expiry_delta : _init_tlv_based_struct_field ! ( final_cltv_expiry_delta, ( default_value, unused) ) ,
592
591
} )
593
592
}
594
593
}
@@ -601,13 +600,12 @@ impl PaymentParameters {
601
600
/// provided.
602
601
pub fn from_node_id ( payee_pubkey : PublicKey , final_cltv_expiry_delta : u32 ) -> Self {
603
602
Self {
604
- payee : Payee :: Clear { node_id : payee_pubkey, route_hints : vec ! [ ] , features : None } ,
603
+ payee : Payee :: Clear { node_id : payee_pubkey, route_hints : vec ! [ ] , features : None , final_cltv_expiry_delta } ,
605
604
expiry_time : None ,
606
605
max_total_cltv_expiry_delta : DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
607
606
max_path_count : DEFAULT_MAX_PATH_COUNT ,
608
607
max_channel_saturation_power_of_half : 2 ,
609
608
previously_failed_channels : Vec :: new ( ) ,
610
- final_cltv_expiry_delta,
611
609
}
612
610
}
613
611
@@ -626,8 +624,12 @@ impl PaymentParameters {
626
624
pub fn with_bolt11_features ( self , features : InvoiceFeatures ) -> Result < Self , ( ) > {
627
625
match self . payee {
628
626
Payee :: Blinded ( _) => Err ( ( ) ) ,
629
- Payee :: Clear { route_hints, node_id, .. } =>
630
- Ok ( Self { payee : Payee :: Clear { route_hints, node_id, features : Some ( features) } , ..self } )
627
+ Payee :: Clear { route_hints, node_id, final_cltv_expiry_delta, .. } =>
628
+ Ok ( Self {
629
+ payee : Payee :: Clear {
630
+ route_hints, node_id, features : Some ( features) , final_cltv_expiry_delta
631
+ } , ..self
632
+ } )
631
633
}
632
634
}
633
635
@@ -638,8 +640,12 @@ impl PaymentParameters {
638
640
pub fn with_route_hints ( self , route_hints : Vec < RouteHint > ) -> Result < Self , ( ) > {
639
641
match self . payee {
640
642
Payee :: Blinded ( _) => Err ( ( ) ) ,
641
- Payee :: Clear { node_id, features, .. } =>
642
- Ok ( Self { payee : Payee :: Clear { route_hints, node_id, features } , ..self } )
643
+ Payee :: Clear { node_id, features, final_cltv_expiry_delta, .. } =>
644
+ Ok ( Self {
645
+ payee : Payee :: Clear {
646
+ route_hints, node_id, features, final_cltv_expiry_delta,
647
+ } , ..self
648
+ } )
643
649
}
644
650
}
645
651
@@ -692,6 +698,8 @@ pub enum Payee {
692
698
///
693
699
/// [`for_keysend`]: PaymentParameters::for_keysend
694
700
features : Option < InvoiceFeatures > ,
701
+ /// The minimum CLTV delta at the end of the route. This value must not be zero.
702
+ final_cltv_expiry_delta : u32 ,
695
703
} ,
696
704
}
697
705
@@ -708,6 +716,12 @@ impl Payee {
708
716
_ => & None ,
709
717
}
710
718
}
719
+ fn final_cltv_expiry_delta ( & self ) -> Option < u32 > {
720
+ match self {
721
+ Self :: Clear { final_cltv_expiry_delta, .. } => Some ( * final_cltv_expiry_delta) ,
722
+ _ => None ,
723
+ }
724
+ }
711
725
}
712
726
713
727
/// A list of hops along a payment path terminating with a channel to the recipient.
@@ -1174,7 +1188,8 @@ where L::Target: Logger {
1174
1188
_ => return Err ( LightningError { err : "Routing to blinded paths isn't supported yet" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ,
1175
1189
1176
1190
}
1177
- if payment_params. max_total_cltv_expiry_delta <= payment_params. final_cltv_expiry_delta {
1191
+ let final_cltv_expiry_delta = payment_params. payee . final_cltv_expiry_delta ( ) . unwrap_or ( 0 ) ;
1192
+ if payment_params. max_total_cltv_expiry_delta <= final_cltv_expiry_delta {
1178
1193
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 } ) ;
1179
1194
}
1180
1195
@@ -1406,9 +1421,9 @@ where L::Target: Logger {
1406
1421
// In order to already account for some of the privacy enhancing random CLTV
1407
1422
// expiry delta offset we add on top later, we subtract a rough estimate
1408
1423
// (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here.
1409
- let max_total_cltv_expiry_delta = ( payment_params. max_total_cltv_expiry_delta - payment_params . final_cltv_expiry_delta)
1424
+ let max_total_cltv_expiry_delta = ( payment_params. max_total_cltv_expiry_delta - final_cltv_expiry_delta)
1410
1425
. checked_sub( 2 * MEDIAN_HOP_CLTV_EXPIRY_DELTA )
1411
- . unwrap_or( payment_params. max_total_cltv_expiry_delta - payment_params . final_cltv_expiry_delta) ;
1426
+ . unwrap_or( payment_params. max_total_cltv_expiry_delta - final_cltv_expiry_delta) ;
1412
1427
let hop_total_cltv_delta = ( $next_hops_cltv_delta as u32 )
1413
1428
. saturating_add( $candidate. cltv_expiry_delta( ) ) ;
1414
1429
let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta;
@@ -2098,7 +2113,7 @@ where L::Target: Logger {
2098
2113
} ) . collect :: < Vec < _ > > ( ) ;
2099
2114
// Propagate the cltv_expiry_delta one hop backwards since the delta from the current hop is
2100
2115
// applicable for the previous hop.
2101
- path. iter_mut ( ) . rev ( ) . fold ( payment_params . final_cltv_expiry_delta , |prev_cltv_expiry_delta, hop| {
2116
+ path. iter_mut ( ) . rev ( ) . fold ( final_cltv_expiry_delta, |prev_cltv_expiry_delta, hop| {
2102
2117
core:: mem:: replace ( & mut hop. as_mut ( ) . unwrap ( ) . cltv_expiry_delta , prev_cltv_expiry_delta)
2103
2118
} ) ;
2104
2119
selected_paths. push ( path) ;
0 commit comments