Skip to content

Commit 3865bbe

Browse files
committed
bolt12: Address JIT offers by node ID
Keep JIT offers independent of ephemeral LSPS2 leases and available when the receiver does not yet have any channels. Negotiate payment paths only after an invoice request arrives. Co-Authored-By: HAL 9000
1 parent cd4ba0d commit 3865bbe

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/payment/bolt12.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use lightning::ln::channelmanager::{OptionalOfferPaymentParams, PaymentId};
1818
use lightning::ln::outbound_payment::Retry;
1919
use lightning::offers::offer::{Amount, Offer as LdkOffer, OfferFromHrn, Quantity};
2020
use lightning::offers::parse::Bolt12SemanticError;
21+
use lightning::onion_message::messenger::NullMessageRouter;
2122
use lightning::routing::router::RouteParametersConfig;
2223
use lightning::sign::EntropySource;
2324
#[cfg(feature = "uniffi")]
@@ -207,9 +208,15 @@ impl Bolt12Payment {
207208
}
208209

209210
pub(crate) fn receive_inner(
210-
&self, amount_msat: u64, description: &str, expiry_secs: Option<u32>, quantity: Option<u64>,
211+
&self, amount_msat: u64, description: &str, expiry_secs: Option<u32>,
212+
quantity: Option<u64>, address_by_node_id: bool,
211213
) -> Result<LdkOffer, Error> {
212-
let mut offer_builder = self.channel_manager.create_offer_builder().map_err(|e| {
214+
let offer_builder = if address_by_node_id {
215+
self.channel_manager.create_offer_builder_using_router(NullMessageRouter {})
216+
} else {
217+
self.channel_manager.create_offer_builder()
218+
};
219+
let mut offer_builder = offer_builder.map_err(|e| {
213220
log_error!(self.logger, "Failed to create offer builder: {:?}", e);
214221
Error::OfferCreationFailed
215222
})?;
@@ -244,9 +251,14 @@ impl Bolt12Payment {
244251
}
245252

246253
fn receive_variable_amount_inner(
247-
&self, description: &str, expiry_secs: Option<u32>,
254+
&self, description: &str, expiry_secs: Option<u32>, address_by_node_id: bool,
248255
) -> Result<LdkOffer, Error> {
249-
let mut offer_builder = self.channel_manager.create_offer_builder().map_err(|e| {
256+
let offer_builder = if address_by_node_id {
257+
self.channel_manager.create_offer_builder_using_router(NullMessageRouter {})
258+
} else {
259+
self.channel_manager.create_offer_builder()
260+
};
261+
let mut offer_builder = offer_builder.map_err(|e| {
250262
log_error!(self.logger, "Failed to create offer builder: {:?}", e);
251263
Error::OfferCreationFailed
252264
})?;
@@ -480,7 +492,7 @@ impl Bolt12Payment {
480492
pub fn receive(
481493
&self, amount_msat: u64, description: &str, expiry_secs: Option<u32>, quantity: Option<u64>,
482494
) -> Result<Offer, Error> {
483-
let offer = self.receive_inner(amount_msat, description, expiry_secs, quantity)?;
495+
let offer = self.receive_inner(amount_msat, description, expiry_secs, quantity, false)?;
484496
Ok(maybe_wrap(offer))
485497
}
486498

@@ -489,7 +501,7 @@ impl Bolt12Payment {
489501
pub fn receive_variable_amount(
490502
&self, description: &str, expiry_secs: Option<u32>,
491503
) -> Result<Offer, Error> {
492-
let offer = self.receive_variable_amount_inner(description, expiry_secs)?;
504+
let offer = self.receive_variable_amount_inner(description, expiry_secs, false)?;
493505
Ok(maybe_wrap(offer))
494506
}
495507

@@ -498,13 +510,14 @@ impl Bolt12Payment {
498510
///
499511
/// Creating the offer does not contact an LSP. LSPS2 payment parameters are selected only when
500512
/// an invoice request for the offer is received, allowing the offer to outlive those parameters.
513+
/// The offer contains no blinded message paths and is addressed directly to this node's ID.
501514
/// If sufficient inbound liquidity is available over pre-existing channels, the payment may be
502515
/// received over those channels without opening a new JIT channel.
503516
pub fn receive_via_jit_channel(
504517
&self, amount_msat: u64, description: &str, expiry_secs: Option<u32>,
505518
quantity: Option<u64>, max_total_lsp_fee_limit_msat: Option<u64>,
506519
) -> Result<Offer, Error> {
507-
let offer = self.receive_inner(amount_msat, description, expiry_secs, quantity)?;
520+
let offer = self.receive_inner(amount_msat, description, expiry_secs, quantity, true)?;
508521
self.register_jit_offer(
509522
&offer,
510523
PendingOfferAmount::Fixed {
@@ -520,13 +533,14 @@ impl Bolt12Payment {
520533
///
521534
/// Creating the offer does not contact an LSP. LSPS2 payment parameters are selected only when
522535
/// an invoice request for the offer is received, allowing the offer to outlive those parameters.
536+
/// The offer contains no blinded message paths and is addressed directly to this node's ID.
523537
/// If sufficient inbound liquidity is available over pre-existing channels, the payment may be
524538
/// received over those channels without opening a new JIT channel.
525539
pub fn receive_variable_amount_via_jit_channel(
526540
&self, description: &str, expiry_secs: Option<u32>,
527541
max_proportional_lsp_fee_limit_ppm_msat: Option<u64>,
528542
) -> Result<Offer, Error> {
529-
let offer = self.receive_variable_amount_inner(description, expiry_secs)?;
543+
let offer = self.receive_variable_amount_inner(description, expiry_secs, true)?;
530544
self.register_jit_offer(
531545
&offer,
532546
PendingOfferAmount::Variable {

src/payment/unified.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl UnifiedPayment {
134134
let onchain_address = self.onchain_payment.new_address()?;
135135

136136
let bolt12_offer =
137-
match self.bolt12_payment.receive_inner(amount_msats, description, None, None) {
137+
match self.bolt12_payment.receive_inner(amount_msats, description, None, None, false) {
138138
Ok(offer) => Some(maybe_wrap(offer)),
139139
Err(e) => {
140140
log_error!(self.logger, "Failed to create offer: {}", e);

0 commit comments

Comments
 (0)