@@ -493,14 +493,6 @@ const MAX_PATH_LENGTH_ESTIMATE: u8 = 19;
493493/// Information used to route a payment.
494494#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
495495pub 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-
504496 /// Information about the payee, such as their features and route hints for their channels.
505497 pub payee : Payee ,
506498
@@ -550,7 +542,7 @@ impl Writeable for PaymentParameters {
550542 write_tlv_fields ! ( writer, {
551543 ( 0 , self . payee. node_id( ) , option) ,
552544 ( 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) ,
554546 ( 3 , self . max_path_count, required) ,
555547 ( 4 , * clear_hints, vec_type) ,
556548 ( 5 , self . max_channel_saturation_power_of_half, required) ,
@@ -586,11 +578,11 @@ impl ReadableArgs<u32> for PaymentParameters {
586578 Payee :: Clear {
587579 route_hints : clear_route_hints,
588580 node_id : payee_pubkey. ok_or ( DecodeError :: InvalidValue ) ?,
581+ features,
589582 }
590583 } ;
591584 Ok ( Self {
592585 max_total_cltv_expiry_delta : _init_tlv_based_struct_field ! ( max_total_cltv_expiry_delta, ( default_value, unused) ) ,
593- features,
594586 max_path_count : _init_tlv_based_struct_field ! ( max_path_count, ( default_value, unused) ) ,
595587 payee,
596588 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 {
609601 /// provided.
610602 pub fn from_node_id ( payee_pubkey : PublicKey , final_cltv_expiry_delta : u32 ) -> Self {
611603 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 } ,
614605 expiry_time : None ,
615606 max_total_cltv_expiry_delta : DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
616607 max_path_count : DEFAULT_MAX_PATH_COUNT ,
@@ -633,8 +624,11 @@ impl PaymentParameters {
633624 ///
634625 /// This is not exported to bindings users since bindings don't support move semantics
635626 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+ }
638632 }
639633
640634 /// Includes hints for routing to the payee. Errors if the parameters were initialized with
@@ -644,8 +638,8 @@ impl PaymentParameters {
644638 pub fn with_route_hints ( self , route_hints : Vec < RouteHint > ) -> Result < Self , ( ) > {
645639 match self . payee {
646640 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 } )
649643 }
650644 }
651645
@@ -695,6 +689,13 @@ pub enum Payee {
695689 node_id : PublicKey ,
696690 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
697691 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 > ,
698699 } ,
699700}
700701
@@ -705,6 +706,18 @@ impl Payee {
705706 _ => None ,
706707 }
707708 }
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+ }
708721}
709722
710723/// A list of hops along a payment path terminating with a channel to the recipient.
@@ -1177,7 +1190,7 @@ where L::Target: Logger {
11771190 }
11781191
11791192 match & payment_params. payee {
1180- Payee :: Clear { route_hints, node_id } => {
1193+ Payee :: Clear { route_hints, node_id, .. } => {
11811194 for route in route_hints. iter ( ) {
11821195 for hop in & route. 0 {
11831196 if hop. src_node_id == * node_id {
@@ -1261,8 +1274,8 @@ where L::Target: Logger {
12611274 // work reliably.
12621275 let allow_mpp = if payment_params. max_path_count == 1 {
12631276 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
12661279 } else if let Some ( payee) = payee_node_id_opt {
12671280 network_nodes. get ( & payee) . map_or ( false , |node| node. announcement_info . as_ref ( ) . map_or ( false ,
12681281 |info| info. features . supports_basic_mpp ( ) ) )
@@ -2120,10 +2133,10 @@ where L::Target: Logger {
21202133 // Make sure we would never create a route with more paths than we allow.
21212134 debug_assert ! ( selected_paths. len( ) <= payment_params. max_path_count. into( ) ) ;
21222135
2123- if let Some ( features ) = & payment_params. features {
2136+ if let Some ( node_features ) = payment_params. payee . node_features ( ) {
21242137 for path in selected_paths. iter_mut ( ) {
21252138 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 ( ) ;
21272140 }
21282141 }
21292142 }
0 commit comments