+
+ fn create_blinded_payment_paths<
+ ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
+ >(
+ &self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
+ amount_msats: u64, entropy_source: &ES, secp_ctx: &Secp256k1<T>
+ ) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
+ // Limit the number of blinded paths that are computed.
+ const MAX_PAYMENT_PATHS: usize = 3;
+
+ // Ensure peers have at least three channels so that it is more difficult to infer the
+ // recipient's node_id.
+ const MIN_PEER_CHANNELS: usize = 3;
+
+ let network_graph = self.network_graph.deref().read_only();
+ let paths = first_hops.into_iter()
+ .filter(|details| details.counterparty.features.supports_route_blinding())
+ .filter(|details| amount_msats <= details.inbound_capacity_msat)
+ .filter(|details| amount_msats >= details.inbound_htlc_minimum_msat.unwrap_or(0))
+ .filter(|details| amount_msats <= details.inbound_htlc_maximum_msat.unwrap_or(u64::MAX))
+ .filter(|details| network_graph
+ .node(&NodeId::from_pubkey(&details.counterparty.node_id))
+ .map(|node_info| node_info.channels.len() >= MIN_PEER_CHANNELS)
+ .unwrap_or(false)
+ )
+ .filter_map(|details| {
+ let short_channel_id = match details.get_inbound_payment_scid() {
+ Some(short_channel_id) => short_channel_id,
+ None => return None,
+ };
+ let payment_relay: PaymentRelay = match details.counterparty.forwarding_info {
+ Some(forwarding_info) => match forwarding_info.try_into() {
+ Ok(payment_relay) => payment_relay,
+ Err(()) => return None,
+ },
+ None => return None,
+ };
+
+ let cltv_expiry_delta = payment_relay.cltv_expiry_delta as u32;
+ let payment_constraints = PaymentConstraints {
+ max_cltv_expiry: tlvs.payment_constraints.max_cltv_expiry + cltv_expiry_delta,
+ htlc_minimum_msat: details.inbound_htlc_minimum_msat.unwrap_or(0),
+ };
+ Some(ForwardNode {
+ tlvs: ForwardTlvs {
+ short_channel_id,
+ payment_relay,
+ payment_constraints,
+ features: BlindedHopFeatures::empty(),
+ },
+ node_id: details.counterparty.node_id,
+ htlc_maximum_msat: details.inbound_htlc_maximum_msat.unwrap_or(u64::MAX),
+ })
+ })
+ .map(|forward_node| {
+ BlindedPath::new_for_payment(
+ &[forward_node], recipient, tlvs.clone(), u64::MAX, entropy_source, secp_ctx
+ )
+ })
+ .take(MAX_PAYMENT_PATHS)
+ .collect::<Result<Vec<_>, _>>();
+
+ match paths {
+ Ok(paths) if !paths.is_empty() => Ok(paths),
+ _ => {
+ if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
+ BlindedPath::one_hop_for_payment(recipient, tlvs, entropy_source, secp_ctx)
+ .map(|path| vec![path])
+ } else {
+ Err(())
+ }
+ },
+ }
+ }