@@ -7652,9 +7652,7 @@ where
7652
7652
7653
7653
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
7654
7654
Ok((payment_hash, payment_secret)) => {
7655
- let payment_paths = vec![
7656
- self.create_one_hop_blinded_payment_path(payment_secret),
7657
- ];
7655
+ let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret);
7658
7656
#[cfg(not(feature = "no-std"))]
7659
7657
let builder = refund.respond_using_derived_keys(
7660
7658
payment_paths, payment_hash, expanded_key, entropy
@@ -7831,6 +7829,18 @@ where
7831
7829
self.router.create_blinded_paths(recipient, peers, entropy_source, secp_ctx)
7832
7830
}
7833
7831
7832
+ /// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
7833
+ /// [`Router::create_blinded_payment_paths`]. If the router returns an error or no paths,
7834
+ /// creates a one-hop blinded payment path instead.
7835
+ fn create_blinded_payment_paths(
7836
+ &self, amount_msats: u64, payment_secret: PaymentSecret
7837
+ ) -> Vec<(BlindedPayInfo, BlindedPath)> {
7838
+ self.create_multi_hop_blinded_payment_paths(amount_msats, payment_secret)
7839
+ .ok()
7840
+ .and_then(|paths| (!paths.is_empty()).then(|| paths))
7841
+ .unwrap_or_else(|| vec![self.create_one_hop_blinded_payment_path(payment_secret)])
7842
+ }
7843
+
7834
7844
/// Creates a one-hop blinded payment path with [`ChannelManager::get_our_node_id`] as the
7835
7845
/// introduction node.
7836
7846
fn create_one_hop_blinded_payment_path(
@@ -7854,6 +7864,34 @@ where
7854
7864
).unwrap()
7855
7865
}
7856
7866
7867
+ /// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
7868
+ /// [`Router::create_blinded_payment_paths`].
7869
+ ///
7870
+ /// May return no paths if no peers [`support route blinding`] or whose channels don't have
7871
+ /// enough inbound liquidity.
7872
+ ///
7873
+ /// [`support route blinding`]: crate::ln::features::InitFeatures::supports_route_blinding
7874
+ fn create_multi_hop_blinded_payment_paths(
7875
+ &self, amount_msats: u64, payment_secret: PaymentSecret
7876
+ ) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
7877
+ let entropy_source = self.entropy_source.deref();
7878
+ let secp_ctx = &self.secp_ctx;
7879
+
7880
+ let first_hops = self.list_usable_channels();
7881
+ let payee_node_id = self.get_our_node_id();
7882
+ let max_cltv_expiry = self.best_block.read().unwrap().height() + LATENCY_GRACE_PERIOD_BLOCKS;
7883
+ let payee_tlvs = ReceiveTlvs {
7884
+ payment_secret,
7885
+ payment_constraints: PaymentConstraints {
7886
+ max_cltv_expiry,
7887
+ htlc_minimum_msat: 1,
7888
+ },
7889
+ };
7890
+ self.router.create_blinded_payment_paths(
7891
+ payee_node_id, first_hops, payee_tlvs, amount_msats, entropy_source, secp_ctx
7892
+ )
7893
+ }
7894
+
7857
7895
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
7858
7896
/// are used when constructing the phantom invoice's route hints.
7859
7897
///
@@ -9091,7 +9129,7 @@ where
9091
9129
let amount_msats = match InvoiceBuilder::<DerivedSigningPubkey>::amount_msats(
9092
9130
&invoice_request
9093
9131
) {
9094
- Ok(amount_msats) => Some( amount_msats) ,
9132
+ Ok(amount_msats) => amount_msats,
9095
9133
Err(error) => return Some(OffersMessage::InvoiceError(error.into())),
9096
9134
};
9097
9135
let invoice_request = match invoice_request.verify(expanded_key, secp_ctx) {
@@ -9103,11 +9141,11 @@ where
9103
9141
};
9104
9142
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9105
9143
9106
- match self.create_inbound_payment(amount_msats, relative_expiry, None) {
9144
+ match self.create_inbound_payment(Some( amount_msats) , relative_expiry, None) {
9107
9145
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
- ] ;
9146
+ let payment_paths = self.create_blinded_payment_paths(
9147
+ amount_msats, payment_secret
9148
+ ) ;
9111
9149
#[cfg(not(feature = "no-std"))]
9112
9150
let builder = invoice_request.respond_using_derived_keys(
9113
9151
payment_paths, payment_hash
@@ -9126,9 +9164,9 @@ where
9126
9164
}
9127
9165
},
9128
9166
Ok((payment_hash, payment_secret)) => {
9129
- let payment_paths = vec![
9130
- self.create_one_hop_blinded_payment_path(payment_secret),
9131
- ] ;
9167
+ let payment_paths = self.create_blinded_payment_paths(
9168
+ amount_msats, payment_secret
9169
+ ) ;
9132
9170
#[cfg(not(feature = "no-std"))]
9133
9171
let builder = invoice_request.respond_with(payment_paths, payment_hash);
9134
9172
#[cfg(feature = "no-std")]
0 commit comments