Skip to content

Commit 6d0e36e

Browse files
committed
WIP: Add create_blinded_payment_paths to Router
1 parent 05cf1af commit 6d0e36e

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

lightning/src/routing/router.rs

+44-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ use bitcoin::hashes::Hash;
1414
use bitcoin::hashes::sha256::Hash as Sha256;
1515

1616
use crate::blinded_path::{BlindedHop, BlindedPath};
17+
use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs};
1718
use crate::ln::PaymentHash;
1819
use crate::ln::channelmanager::{ChannelDetails, PaymentId};
19-
use crate::ln::features::{Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
20+
use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
2021
use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
2122
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
2223
use crate::onion_message::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
@@ -129,6 +130,48 @@ pub trait Router: MessageRouter {
129130
) -> Result<Route, LightningError> {
130131
self.find_route(payer, route_params, first_hops, inflight_htlcs)
131132
}
133+
134+
/// Creates [`BlindedPath`]s for payment to the `recipient` node. The channels in `first_hops`
135+
/// are assumed to be with the `recipient`'s peers. The payment secret and any constraints are
136+
/// given in `tlvs`.
137+
///
138+
/// The default implementation returns two-hop payment paths for each channel in `first_hops`
139+
/// with the `recipient` node (i.e., the channel counterparty is the introduction point).
140+
fn create_blinded_payment_paths<
141+
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
142+
>(
143+
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
144+
amount_msats: u64, count: usize, entropy_source: &ES, secp_ctx: &Secp256k1<T>
145+
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
146+
first_hops.into_iter()
147+
.filter(|details| details.counterparty.features.supports_route_blinding())
148+
.filter(|details| amount_msats >= details.inbound_htlc_minimum_msat.unwrap_or(0))
149+
.filter(|details| amount_msats <= details.inbound_htlc_maximum_msat.unwrap_or(0))
150+
.map(|details| {
151+
let short_channel_id = details.get_inbound_payment_scid().unwrap();
152+
let payment_relay: PaymentRelay = details.counterparty.forwarding_info.unwrap().into();
153+
let payment_constraints = PaymentConstraints {
154+
max_cltv_expiry: tlvs.payment_constraints.max_cltv_expiry
155+
+ payment_relay.cltv_expiry_delta as u32,
156+
htlc_minimum_msat: details.inbound_htlc_minimum_msat.unwrap_or(0),
157+
};
158+
let forward_node = ForwardNode {
159+
tlvs: ForwardTlvs {
160+
short_channel_id,
161+
payment_relay,
162+
payment_constraints,
163+
features: BlindedHopFeatures::empty(),
164+
},
165+
node_id: details.counterparty.node_id,
166+
htlc_maximum_msat: details.inbound_htlc_maximum_msat.unwrap_or(0),
167+
};
168+
BlindedPath::new_for_payment(
169+
&[forward_node], recipient, tlvs.clone(), u64::MAX, entropy_source, secp_ctx
170+
)
171+
})
172+
.take(count)
173+
.collect()
174+
}
132175
}
133176

134177
/// [`ScoreLookUp`] implementation that factors in in-flight HTLC liquidity.

0 commit comments

Comments
 (0)