Skip to content

Commit ab0fbf2

Browse files
Move BOLT11 features from top level PaymentParams to Payee::Clear
Since blinded payees don't have this.
1 parent 9d7475e commit ab0fbf2

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

lightning/src/routing/router.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,6 @@ const MAX_PATH_LENGTH_ESTIMATE: u8 = 19;
493493
/// The recipient of a payment.
494494
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
495495
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-
504496
/// Route hints and other information used to route to the payee.
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, self.payee.bolt11_features(), 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

@@ -691,6 +685,13 @@ pub enum Payee {
691685
node_id: PublicKey,
692686
/// Hints for routing to the payee, containing channels connecting the payee to public nodes.
693687
route_hints: Vec<RouteHint>,
688+
/// Features supported by the payee.
689+
///
690+
/// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
691+
/// does not contain any features.
692+
///
693+
/// [`for_keysend`]: PaymentParameters::for_keysend
694+
features: Option<InvoiceFeatures>,
694695
},
695696
}
696697

@@ -701,6 +702,12 @@ impl Payee {
701702
_ => None,
702703
}
703704
}
705+
fn bolt11_features(&self) -> &Option<InvoiceFeatures> {
706+
match self {
707+
Self::Clear { features, .. } => features,
708+
_ => &None,
709+
}
710+
}
704711
}
705712

706713
/// A list of hops along a payment path terminating with a channel to the recipient.
@@ -1155,7 +1162,7 @@ where L::Target: Logger {
11551162
}
11561163

11571164
match &payment_params.payee {
1158-
Payee::Clear { route_hints, node_id } => {
1165+
Payee::Clear { route_hints, node_id, .. } => {
11591166
for route in route_hints.iter() {
11601167
for hop in &route.0 {
11611168
if hop.src_node_id == *node_id {
@@ -1239,7 +1246,7 @@ where L::Target: Logger {
12391246
// work reliably.
12401247
let allow_mpp = if payment_params.max_path_count == 1 {
12411248
false
1242-
} else if let Some(features) = &payment_params.features {
1249+
} else if let Some(features) = payment_params.payee.bolt11_features() {
12431250
features.supports_basic_mpp()
12441251
} else if let Some(payee) = payee_node_id {
12451252
network_nodes.get(&payee).map_or(false, |node| node.announcement_info.as_ref().map_or(false,
@@ -2099,7 +2106,7 @@ where L::Target: Logger {
20992106
// Make sure we would never create a route with more paths than we allow.
21002107
debug_assert!(selected_paths.len() <= payment_params.max_path_count.into());
21012108

2102-
if let Some(features) = &payment_params.features {
2109+
if let Some(features) = payment_params.payee.bolt11_features() {
21032110
for path in selected_paths.iter_mut() {
21042111
if let Ok(route_hop) = path.last_mut().unwrap() {
21052112
route_hop.node_features = features.to_context();

0 commit comments

Comments
 (0)