@@ -7658,9 +7658,7 @@ where
7658
7658
7659
7659
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
7660
7660
Ok((payment_hash, payment_secret)) => {
7661
- let payment_paths = vec![
7662
- self.create_one_hop_blinded_payment_path(payment_secret),
7663
- ];
7661
+ let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret);
7664
7662
#[cfg(not(feature = "no-std"))]
7665
7663
let builder = refund.respond_using_derived_keys(
7666
7664
payment_paths, payment_hash, expanded_key, entropy
@@ -7821,6 +7819,18 @@ where
7821
7819
.and_then(|paths| paths.into_iter().next().ok_or(()))
7822
7820
}
7823
7821
7822
+ /// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
7823
+ /// [`Router::create_blinded_payment_paths`]. If the router returns an error or no paths,
7824
+ /// creates a one-hop blinded payment path instead.
7825
+ fn create_blinded_payment_paths(
7826
+ &self, amount_msats: u64, payment_secret: PaymentSecret
7827
+ ) -> Vec<(BlindedPayInfo, BlindedPath)> {
7828
+ self.create_multi_hop_blinded_payment_paths(amount_msats, payment_secret)
7829
+ .ok()
7830
+ .and_then(|paths| (!paths.is_empty()).then(|| paths))
7831
+ .unwrap_or_else(|| vec![self.create_one_hop_blinded_payment_path(payment_secret)])
7832
+ }
7833
+
7824
7834
/// Creates a one-hop blinded payment path with [`ChannelManager::get_our_node_id`] as the
7825
7835
/// introduction node.
7826
7836
fn create_one_hop_blinded_payment_path(
@@ -7844,6 +7854,34 @@ where
7844
7854
).unwrap()
7845
7855
}
7846
7856
7857
+ /// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
7858
+ /// [`Router::create_blinded_payment_paths`].
7859
+ ///
7860
+ /// May return no paths if no peers [support route blinding] or whose channels don't have enough
7861
+ /// inbound liquidity.
7862
+ ///
7863
+ /// [support route blinding]: crate::ln::features::InitFeatures::supports_route_blinding
7864
+ fn create_multi_hop_blinded_payment_paths(
7865
+ &self, amount_msats: u64, payment_secret: PaymentSecret
7866
+ ) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
7867
+ let entropy_source = self.entropy_source.deref();
7868
+ let secp_ctx = &self.secp_ctx;
7869
+
7870
+ let first_hops = self.list_usable_channels();
7871
+ let payee_node_id = self.get_our_node_id();
7872
+ let max_cltv_expiry = self.best_block.read().unwrap().height() + LATENCY_GRACE_PERIOD_BLOCKS;
7873
+ let payee_tlvs = ReceiveTlvs {
7874
+ payment_secret,
7875
+ payment_constraints: PaymentConstraints {
7876
+ max_cltv_expiry,
7877
+ htlc_minimum_msat: 1,
7878
+ },
7879
+ };
7880
+ self.router.create_blinded_payment_paths(
7881
+ payee_node_id, first_hops, payee_tlvs, amount_msats, entropy_source, secp_ctx
7882
+ )
7883
+ }
7884
+
7847
7885
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
7848
7886
/// are used when constructing the phantom invoice's route hints.
7849
7887
///
@@ -9081,7 +9119,7 @@ where
9081
9119
let amount_msats = match InvoiceBuilder::<DerivedSigningPubkey>::amount_msats(
9082
9120
&invoice_request
9083
9121
) {
9084
- Ok(amount_msats) => Some( amount_msats) ,
9122
+ Ok(amount_msats) => amount_msats,
9085
9123
Err(error) => return Some(OffersMessage::InvoiceError(error.into())),
9086
9124
};
9087
9125
let invoice_request = match invoice_request.verify(expanded_key, secp_ctx) {
@@ -9093,11 +9131,11 @@ where
9093
9131
};
9094
9132
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9095
9133
9096
- match self.create_inbound_payment(amount_msats, relative_expiry, None) {
9134
+ match self.create_inbound_payment(Some( amount_msats) , relative_expiry, None) {
9097
9135
Ok((payment_hash, payment_secret)) if invoice_request.keys.is_some() => {
9098
- let payment_paths = vec![
9099
- self.create_one_hop_blinded_payment_path(payment_secret),
9100
- ] ;
9136
+ let payment_paths = self.create_blinded_payment_paths(
9137
+ amount_msats, payment_secret
9138
+ ) ;
9101
9139
#[cfg(not(feature = "no-std"))]
9102
9140
let builder = invoice_request.respond_using_derived_keys(
9103
9141
payment_paths, payment_hash
@@ -9116,9 +9154,9 @@ where
9116
9154
}
9117
9155
},
9118
9156
Ok((payment_hash, payment_secret)) => {
9119
- let payment_paths = vec![
9120
- self.create_one_hop_blinded_payment_path(payment_secret),
9121
- ] ;
9157
+ let payment_paths = self.create_blinded_payment_paths(
9158
+ amount_msats, payment_secret
9159
+ ) ;
9122
9160
#[cfg(not(feature = "no-std"))]
9123
9161
let builder = invoice_request.respond_with(payment_paths, payment_hash);
9124
9162
#[cfg(feature = "no-std")]
0 commit comments