Skip to content

Commit 06eeefc

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 06eeefc

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

lightning/src/routing/router.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ const MEDIAN_HOP_CLTV_EXPIRY_DELTA: u32 = 40;
490490
// down from (1300-93) / 61 = 19.78... to arrive at a conservative estimate of 19.
491491
const MAX_PATH_LENGTH_ESTIMATE: u8 = 19;
492492

493-
/// The recipient of a payment.
493+
/// Information used to route a payment.
494494
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
495495
pub struct PaymentParameters {
496496
/// The node id of the payee.
@@ -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+
/// Information about the payee, such as their features and route hints for their channels.
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 { route_hints } => blinded_hints = route_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 { route_hints: 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,22 @@ impl PaymentParameters {
673673
}
674674
}
675675

676-
/// Routing hints for the tail of the route.
676+
/// The recipient of a payment, differing based on whether they've hidden their identity with route
677+
/// 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`].
681-
Blinded(Vec<(BlindedPayInfo, BlindedPath)>),
682+
Blinded {
683+
/// Aggregated routing info and blinded paths, for routing to the payee without knowing their
684+
/// node id.
685+
route_hints: Vec<(BlindedPayInfo, BlindedPath)>,
686+
},
682687
/// The recipient included these route hints in their BOLT11 invoice.
683-
Clear(Vec<RouteHint>),
688+
Clear {
689+
/// Hints for routing to the payee, containing channels connecting the payee to public nodes.
690+
route_hints: Vec<RouteHint>,
691+
},
684692
}
685693

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

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

0 commit comments

Comments
 (0)