@@ -1555,6 +1555,9 @@ const MAX_UNFUNDED_CHANNEL_PEERS: usize = 50;
1555
1555
/// many peers we reject new (inbound) connections.
1556
1556
const MAX_NO_CHANNEL_PEERS: usize = 250;
1557
1557
1558
+ /// The maximum number of blinded payment paths to use in BOLT 12 invoices.
1559
+ const MAX_BLINDED_PAYMENT_PATHS: usize = 3;
1560
+
1558
1561
/// Information needed for constructing an invoice route hint for this channel.
1559
1562
#[derive(Clone, Debug, PartialEq)]
1560
1563
pub struct CounterpartyForwardingInfo {
@@ -7652,9 +7655,9 @@ where
7652
7655
7653
7656
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
7654
7657
Ok((payment_hash, payment_secret)) => {
7655
- let payment_paths = vec![
7656
- self.create_one_hop_blinded_payment_path( payment_secret),
7657
- ] ;
7658
+ let payment_paths = self.create_blinded_payment_paths(
7659
+ amount_msats, payment_secret, MAX_BLINDED_PAYMENT_PATHS
7660
+ ) ;
7658
7661
#[cfg(not(feature = "no-std"))]
7659
7662
let builder = refund.respond_using_derived_keys(
7660
7663
payment_paths, payment_hash, expanded_key, entropy
@@ -7831,6 +7834,18 @@ where
7831
7834
self.router.create_blinded_paths(recipient, peers, count, entropy_source, secp_ctx)
7832
7835
}
7833
7836
7837
+ /// Creates `count` multi-hop blinded payment paths for the given `amount_msats` by delegating
7838
+ /// to [`Router::create_blinded_payment_paths`]. If the router returns an error or no paths,
7839
+ /// creates a one-hop blinded payment path instead.
7840
+ fn create_blinded_payment_paths(
7841
+ &self, amount_msats: u64, payment_secret: PaymentSecret, count: usize
7842
+ ) -> Vec<(BlindedPayInfo, BlindedPath)> {
7843
+ self.create_multi_hop_blinded_payment_paths(amount_msats, payment_secret, count)
7844
+ .ok()
7845
+ .and_then(|paths| (!paths.is_empty()).then(|| paths))
7846
+ .unwrap_or_else(|| vec![self.create_one_hop_blinded_payment_path(payment_secret)])
7847
+ }
7848
+
7834
7849
/// Creates a one-hop blinded payment path with [`ChannelManager::get_our_node_id`] as the
7835
7850
/// introduction node.
7836
7851
fn create_one_hop_blinded_payment_path(
@@ -7854,6 +7869,34 @@ where
7854
7869
).unwrap()
7855
7870
}
7856
7871
7872
+ /// Creates `count` multi-hop blinded payment paths for the given `amount_msats` by delegating
7873
+ /// to [`Router::create_blinded_payment_paths`].
7874
+ ///
7875
+ /// May return fewer paths if not enough peers [`support route blinding`] or whose channels
7876
+ /// don't have enough inbound liquidity.
7877
+ ///
7878
+ /// [`support route blinding`]: crate::ln::features::InitFeatures::supports_route_blinding
7879
+ fn create_multi_hop_blinded_payment_paths(
7880
+ &self, amount_msats: u64, payment_secret: PaymentSecret, count: usize
7881
+ ) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
7882
+ let entropy_source = self.entropy_source.deref();
7883
+ let secp_ctx = &self.secp_ctx;
7884
+
7885
+ let first_hops = self.list_usable_channels();
7886
+ let payee_node_id = self.get_our_node_id();
7887
+ let max_cltv_expiry = self.best_block.read().unwrap().height() + LATENCY_GRACE_PERIOD_BLOCKS;
7888
+ let payee_tlvs = ReceiveTlvs {
7889
+ payment_secret,
7890
+ payment_constraints: PaymentConstraints {
7891
+ max_cltv_expiry,
7892
+ htlc_minimum_msat: 1,
7893
+ },
7894
+ };
7895
+ self.router.create_blinded_payment_paths(
7896
+ payee_node_id, first_hops, payee_tlvs, amount_msats, count, entropy_source, secp_ctx
7897
+ )
7898
+ }
7899
+
7857
7900
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
7858
7901
/// are used when constructing the phantom invoice's route hints.
7859
7902
///
@@ -9091,7 +9134,7 @@ where
9091
9134
let amount_msats = match InvoiceBuilder::<DerivedSigningPubkey>::amount_msats(
9092
9135
&invoice_request
9093
9136
) {
9094
- Ok(amount_msats) => Some( amount_msats) ,
9137
+ Ok(amount_msats) => amount_msats,
9095
9138
Err(error) => return Some(OffersMessage::InvoiceError(error.into())),
9096
9139
};
9097
9140
let invoice_request = match invoice_request.verify(expanded_key, secp_ctx) {
@@ -9103,11 +9146,11 @@ where
9103
9146
};
9104
9147
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9105
9148
9106
- match self.create_inbound_payment(amount_msats, relative_expiry, None) {
9149
+ match self.create_inbound_payment(Some( amount_msats) , relative_expiry, None) {
9107
9150
Ok((payment_hash, payment_secret)) if invoice_request.keys.is_some() => {
9108
- let payment_paths = vec![
9109
- self.create_one_hop_blinded_payment_path( payment_secret),
9110
- ] ;
9151
+ let payment_paths = self.create_blinded_payment_paths(
9152
+ amount_msats, payment_secret, MAX_BLINDED_PAYMENT_PATHS
9153
+ ) ;
9111
9154
#[cfg(not(feature = "no-std"))]
9112
9155
let builder = invoice_request.respond_using_derived_keys(
9113
9156
payment_paths, payment_hash
@@ -9126,9 +9169,9 @@ where
9126
9169
}
9127
9170
},
9128
9171
Ok((payment_hash, payment_secret)) => {
9129
- let payment_paths = vec![
9130
- self.create_one_hop_blinded_payment_path( payment_secret),
9131
- ] ;
9172
+ let payment_paths = self.create_blinded_payment_paths(
9173
+ amount_msats, payment_secret, MAX_BLINDED_PAYMENT_PATHS
9174
+ ) ;
9132
9175
#[cfg(not(feature = "no-std"))]
9133
9176
let builder = invoice_request.respond_with(payment_paths, payment_hash);
9134
9177
#[cfg(feature = "no-std")]
0 commit comments