Skip to content

Commit 4ec420b

Browse files
Groundwork for refactoring PaymentParams::Hints to ::Payee
Minor changes in preparation for supporting route blinding in PaymentParameters. In the next commit, we'll be moving more unblinded-payee-specific fields from the top level parameters into the clear enum variant.
1 parent 2cae6f0 commit 4ec420b

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

lightning/src/routing/router.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ pub struct PaymentParameters {
504504
/// [`for_keysend`]: Self::for_keysend
505505
pub features: Option<InvoiceFeatures>,
506506

507-
/// Hints for routing to the payee, containing channels connecting the payee to public nodes.
508-
pub route_hints: Hints,
507+
/// Route hints and other information used to route to the payee.
508+
pub payee: Payee,
509509

510510
/// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
511511
pub expiry_time: Option<u64>,
@@ -546,9 +546,9 @@ impl Writeable for PaymentParameters {
546546
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
547547
let mut clear_hints = &vec![];
548548
let mut blinded_hints = &vec![];
549-
match &self.route_hints {
550-
Hints::Clear(hints) => clear_hints = hints,
551-
Hints::Blinded(hints) => blinded_hints = hints,
549+
match &self.payee {
550+
Payee::Clear { route_hints } => clear_hints = route_hints,
551+
Payee::Blinded(hints) => blinded_hints = hints,
552552
}
553553
write_tlv_fields!(writer, {
554554
(0, self.payee_pubkey, required),
@@ -582,18 +582,18 @@ impl ReadableArgs<u32> for PaymentParameters {
582582
});
583583
let clear_route_hints = route_hints.unwrap_or(vec![]);
584584
let blinded_route_hints = blinded_route_hints.unwrap_or(vec![]);
585-
let route_hints = if blinded_route_hints.len() != 0 {
585+
let payee = if blinded_route_hints.len() != 0 {
586586
if clear_route_hints.len() != 0 { return Err(DecodeError::InvalidValue) }
587-
Hints::Blinded(blinded_route_hints)
587+
Payee::Blinded(blinded_route_hints)
588588
} else {
589-
Hints::Clear(clear_route_hints)
589+
Payee::Clear { route_hints: clear_route_hints }
590590
};
591591
Ok(Self {
592592
payee_pubkey: _init_tlv_based_struct_field!(payee_pubkey, required),
593593
max_total_cltv_expiry_delta: _init_tlv_based_struct_field!(max_total_cltv_expiry_delta, (default_value, unused)),
594594
features,
595595
max_path_count: _init_tlv_based_struct_field!(max_path_count, (default_value, unused)),
596-
route_hints,
596+
payee,
597597
max_channel_saturation_power_of_half: _init_tlv_based_struct_field!(max_channel_saturation_power_of_half, (default_value, unused)),
598598
expiry_time,
599599
previously_failed_channels: previously_failed_channels.unwrap_or(Vec::new()),
@@ -612,7 +612,7 @@ impl PaymentParameters {
612612
Self {
613613
payee_pubkey,
614614
features: None,
615-
route_hints: Hints::Clear(vec![]),
615+
payee: Payee::Clear { route_hints: vec![] },
616616
expiry_time: None,
617617
max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
618618
max_path_count: DEFAULT_MAX_PATH_COUNT,
@@ -641,7 +641,7 @@ impl PaymentParameters {
641641
///
642642
/// This is not exported to bindings users since bindings don't support move semantics
643643
pub fn with_route_hints(self, route_hints: Vec<RouteHint>) -> Self {
644-
Self { route_hints: Hints::Clear(route_hints), ..self }
644+
Self { payee: Payee::Clear { route_hints }, ..self }
645645
}
646646

647647
/// Includes a payment expiration in seconds relative to the UNIX epoch.
@@ -673,14 +673,18 @@ impl PaymentParameters {
673673
}
674674
}
675675

676-
/// Routing hints for the tail of the route.
676+
/// Information used to route to a recipient, differing based on whether they've hidden their
677+
/// identity with route blinding.
677678
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
678-
pub enum Hints {
679+
pub enum Payee {
679680
/// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
680681
/// will be included in the final [`Route`].
681682
Blinded(Vec<(BlindedPayInfo, BlindedPath)>),
682683
/// The recipient included these route hints in their BOLT11 invoice.
683-
Clear(Vec<RouteHint>),
684+
Clear {
685+
/// Hints for routing to the payee, containing channels connecting the payee to public nodes.
686+
route_hints: Vec<RouteHint>,
687+
},
684688
}
685689

686690
/// A list of hops along a payment path terminating with a channel to the recipient.
@@ -1131,9 +1135,9 @@ where L::Target: Logger {
11311135
return Err(LightningError{err: "Cannot send a payment of 0 msat".to_owned(), action: ErrorAction::IgnoreError});
11321136
}
11331137

1134-
match &payment_params.route_hints {
1135-
Hints::Clear(hints) => {
1136-
for route in hints.iter() {
1138+
match &payment_params.payee {
1139+
Payee::Clear { route_hints } => {
1140+
for route in route_hints.iter() {
11371141
for hop in &route.0 {
11381142
if hop.src_node_id == payment_params.payee_pubkey {
11391143
return Err(LightningError{err: "Route hint cannot have the payee as the source.".to_owned(), action: ErrorAction::IgnoreError});
@@ -1664,8 +1668,8 @@ where L::Target: Logger {
16641668
// If a caller provided us with last hops, add them to routing targets. Since this happens
16651669
// earlier than general path finding, they will be somewhat prioritized, although currently
16661670
// it matters only if the fees are exactly the same.
1667-
let route_hints = match &payment_params.route_hints {
1668-
Hints::Clear(hints) => hints,
1671+
let route_hints = match &payment_params.payee {
1672+
Payee::Clear { route_hints } => route_hints,
16691673
_ => return Err(LightningError{err: "Routing to blinded paths isn't supported yet".to_owned(), action: ErrorAction::IgnoreError}),
16701674
};
16711675
for route in route_hints.iter().filter(|route| !route.0.is_empty()) {

0 commit comments

Comments
 (0)