@@ -493,14 +493,6 @@ const MAX_PATH_LENGTH_ESTIMATE: u8 = 19;
493
493
/// Information used to route a payment.
494
494
#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
495
495
pub struct PaymentParameters {
496
- /// Features supported by the payee.
497
- ///
498
- /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
499
- /// does not contain any features.
500
- ///
501
- /// [`for_keysend`]: Self::for_keysend
502
- pub features : Option < InvoiceFeatures > ,
503
-
504
496
/// Information about the payee, such as their features and route hints for their channels.
505
497
pub payee : Payee ,
506
498
@@ -550,7 +542,7 @@ impl Writeable for PaymentParameters {
550
542
write_tlv_fields ! ( writer, {
551
543
( 0 , self . payee. node_id( ) , option) ,
552
544
( 1 , self . max_total_cltv_expiry_delta, required) ,
553
- ( 2 , self . features, option) ,
545
+ ( 2 , if let Payee :: Clear { features , .. } = & self . payee { features } else { & None } , option) ,
554
546
( 3 , self . max_path_count, required) ,
555
547
( 4 , * clear_hints, vec_type) ,
556
548
( 5 , self . max_channel_saturation_power_of_half, required) ,
@@ -586,11 +578,11 @@ impl ReadableArgs<u32> for PaymentParameters {
586
578
Payee :: Clear {
587
579
route_hints : clear_route_hints,
588
580
node_id : payee_pubkey. ok_or ( DecodeError :: InvalidValue ) ?,
581
+ features,
589
582
}
590
583
} ;
591
584
Ok ( Self {
592
585
max_total_cltv_expiry_delta : _init_tlv_based_struct_field ! ( max_total_cltv_expiry_delta, ( default_value, unused) ) ,
593
- features,
594
586
max_path_count : _init_tlv_based_struct_field ! ( max_path_count, ( default_value, unused) ) ,
595
587
payee,
596
588
max_channel_saturation_power_of_half : _init_tlv_based_struct_field ! ( max_channel_saturation_power_of_half, ( default_value, unused) ) ,
@@ -609,8 +601,7 @@ impl PaymentParameters {
609
601
/// provided.
610
602
pub fn from_node_id ( payee_pubkey : PublicKey , final_cltv_expiry_delta : u32 ) -> Self {
611
603
Self {
612
- features : None ,
613
- payee : Payee :: Clear { node_id : payee_pubkey, route_hints : vec ! [ ] } ,
604
+ payee : Payee :: Clear { node_id : payee_pubkey, route_hints : vec ! [ ] , features : None } ,
614
605
expiry_time : None ,
615
606
max_total_cltv_expiry_delta : DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
616
607
max_path_count : DEFAULT_MAX_PATH_COUNT ,
@@ -633,8 +624,11 @@ impl PaymentParameters {
633
624
///
634
625
/// This is not exported to bindings users since bindings don't support move semantics
635
626
pub fn with_bolt11_features ( self , features : InvoiceFeatures ) -> Result < Self , ( ) > {
636
- if let Payee :: Blinded { .. } = self . payee { return Err ( ( ) ) }
637
- Ok ( Self { features : Some ( features) , ..self } )
627
+ match self . payee {
628
+ Payee :: Blinded { .. } => Err ( ( ) ) ,
629
+ Payee :: Clear { route_hints, node_id, .. } =>
630
+ Ok ( Self { payee : Payee :: Clear { route_hints, node_id, features : Some ( features) } , ..self } )
631
+ }
638
632
}
639
633
640
634
/// Includes hints for routing to the payee. Errors if the parameters were initialized with
@@ -644,8 +638,8 @@ impl PaymentParameters {
644
638
pub fn with_route_hints ( self , route_hints : Vec < RouteHint > ) -> Result < Self , ( ) > {
645
639
match self . payee {
646
640
Payee :: Blinded { .. } => Err ( ( ) ) ,
647
- Payee :: Clear { node_id, .. } =>
648
- Ok ( Self { payee : Payee :: Clear { route_hints, node_id } , ..self } )
641
+ Payee :: Clear { node_id, features , .. } =>
642
+ Ok ( Self { payee : Payee :: Clear { route_hints, node_id, features } , ..self } )
649
643
}
650
644
}
651
645
@@ -695,6 +689,13 @@ pub enum Payee {
695
689
node_id : PublicKey ,
696
690
/// Hints for routing to the payee, containing channels connecting the payee to public nodes.
697
691
route_hints : Vec < RouteHint > ,
692
+ /// Features supported by the payee.
693
+ ///
694
+ /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
695
+ /// does not contain any features.
696
+ ///
697
+ /// [`for_keysend`]: PaymentParameters::for_keysend
698
+ features : Option < InvoiceFeatures > ,
698
699
} ,
699
700
}
700
701
@@ -705,6 +706,18 @@ impl Payee {
705
706
_ => None ,
706
707
}
707
708
}
709
+ fn node_features ( & self ) -> Option < NodeFeatures > {
710
+ match self {
711
+ Self :: Clear { features, .. } => features. as_ref ( ) . map ( |f| f. to_context ( ) ) ,
712
+ _ => None ,
713
+ }
714
+ }
715
+ fn supports_basic_mpp ( & self ) -> bool {
716
+ match self {
717
+ Self :: Clear { features, .. } => features. as_ref ( ) . map_or ( false , |f| f. supports_basic_mpp ( ) ) ,
718
+ _ => false ,
719
+ }
720
+ }
708
721
}
709
722
710
723
/// A list of hops along a payment path terminating with a channel to the recipient.
@@ -1177,7 +1190,7 @@ where L::Target: Logger {
1177
1190
}
1178
1191
1179
1192
match & payment_params. payee {
1180
- Payee :: Clear { route_hints, node_id } => {
1193
+ Payee :: Clear { route_hints, node_id, .. } => {
1181
1194
for route in route_hints. iter ( ) {
1182
1195
for hop in & route. 0 {
1183
1196
if hop. src_node_id == * node_id {
@@ -1261,8 +1274,8 @@ where L::Target: Logger {
1261
1274
// work reliably.
1262
1275
let allow_mpp = if payment_params. max_path_count == 1 {
1263
1276
false
1264
- } else if let Some ( features ) = & payment_params. features {
1265
- features . supports_basic_mpp ( )
1277
+ } else if payment_params. payee . supports_basic_mpp ( ) {
1278
+ true
1266
1279
} else if let Some ( payee) = payee_node_id_opt {
1267
1280
network_nodes. get ( & payee) . map_or ( false , |node| node. announcement_info . as_ref ( ) . map_or ( false ,
1268
1281
|info| info. features . supports_basic_mpp ( ) ) )
@@ -2120,10 +2133,10 @@ where L::Target: Logger {
2120
2133
// Make sure we would never create a route with more paths than we allow.
2121
2134
debug_assert ! ( selected_paths. len( ) <= payment_params. max_path_count. into( ) ) ;
2122
2135
2123
- if let Some ( features ) = & payment_params. features {
2136
+ if let Some ( node_features ) = payment_params. payee . node_features ( ) {
2124
2137
for path in selected_paths. iter_mut ( ) {
2125
2138
if let Ok ( route_hop) = path. last_mut ( ) . unwrap ( ) {
2126
- route_hop. node_features = features . to_context ( ) ;
2139
+ route_hop. node_features = node_features . clone ( ) ;
2127
2140
}
2128
2141
}
2129
2142
}
0 commit comments