Skip to content

Commit dd4f876

Browse files
committed
WIP ASYNC PAYMENTS
Checkpoint the async LSPS2 BOLT12 JIT work while debugging the offer-refresh and intercept-SCID timing issues. Co-Authored-By: HAL 9000
1 parent 26aa86e commit dd4f876

File tree

5 files changed

+384
-61
lines changed

5 files changed

+384
-61
lines changed

Cargo.toml

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ default = []
3939
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
4040
#lightning-macros = { version = "0.2.0" }
4141

42-
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["std"] }
43-
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
44-
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["std"] }
45-
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
46-
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["tokio"] }
47-
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
48-
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
49-
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["rest-client", "rpc-client", "tokio"] }
50-
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51-
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["std"] }
52-
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
42+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] }
43+
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
44+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] }
45+
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
46+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["tokio"] }
47+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
48+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
49+
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["rest-client", "rpc-client", "tokio"] }
50+
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51+
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] }
52+
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
5353

5454
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
5555
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
@@ -85,7 +85,7 @@ bitcoin-payment-instructions = { git = "https://github.com/jkczyz/bitcoin-paymen
8585
winapi = { version = "0.3", features = ["winbase"] }
8686

8787
[dev-dependencies]
88-
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["std", "_test_utils"] }
88+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std", "_test_utils"] }
8989
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
9090
proptest = "1.0.0"
9191
regex = "1.5.6"
@@ -157,30 +157,19 @@ harness = false
157157
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
158158
#lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
159159

160-
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
161-
#lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
162-
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
163-
#lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
164-
#lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
165-
#lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
166-
#lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
167-
#lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
168-
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
169-
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
170-
#lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "21e9a9c0ef80021d0669f2a366f55d08ba8d9b03" }
160+
[patch."https://github.com/lightningdevkit/rust-lightning"]
161+
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
162+
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
163+
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
164+
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
165+
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
166+
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
167+
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
168+
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
169+
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
170+
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
171+
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "fe77246afe56c80ed08221a50dfd487f2a811c9b" }
171172

172173
#vss-client-ng = { path = "../vss-client" }
173174
#vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" }
174175
#
175-
[patch."https://github.com/lightningdevkit/rust-lightning"]
176-
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
177-
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
178-
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
179-
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
180-
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
181-
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
182-
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
183-
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
184-
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
185-
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
186-
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler};
2727
use lightning::log_trace;
2828
use lightning::routing::gossip::NodeAlias;
2929
use lightning::routing::router::DefaultRouter;
30-
use lightning_liquidity::lsps2::router::LSPS2BOLT12Router;
3130
use lightning::routing::scoring::{
3231
CombinedScorer, ProbabilisticScorer, ProbabilisticScoringDecayParameters,
3332
ProbabilisticScoringFeeParameters,
@@ -40,6 +39,7 @@ use lightning::util::persist::{
4039
};
4140
use lightning::util::ser::ReadableArgs;
4241
use lightning::util::sweep::OutputSweeper;
42+
use lightning_liquidity::lsps2::router::LSPS2BOLT12Router;
4343
use lightning_persister::fs_store::v1::FilesystemStore;
4444
use vss_client::headers::VssHeaderProvider;
4545

src/event.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,26 +1659,24 @@ where
16591659

16601660
self.bump_tx_event_handler.handle_event(&bte).await;
16611661
},
1662-
LdkEvent::OnionMessageIntercepted { next_hop, message } => {
1663-
match next_hop {
1664-
lightning::blinded_path::message::NextMessageHop::NodeId(peer_node_id) => {
1665-
if let Some(om_mailbox) = self.om_mailbox.as_ref() {
1666-
om_mailbox.onion_message_intercepted(peer_node_id, message);
1667-
} else {
1668-
log_trace!(
1669-
self.logger,
1670-
"Onion message intercepted, but no onion message mailbox available"
1671-
);
1672-
}
1673-
},
1674-
lightning::blinded_path::message::NextMessageHop::ShortChannelId(scid) => {
1662+
LdkEvent::OnionMessageIntercepted { next_hop, message } => match next_hop {
1663+
lightning::blinded_path::message::NextMessageHop::NodeId(peer_node_id) => {
1664+
if let Some(om_mailbox) = self.om_mailbox.as_ref() {
1665+
om_mailbox.onion_message_intercepted(peer_node_id, message);
1666+
} else {
16751667
log_trace!(
16761668
self.logger,
1677-
"Onion message intercepted for unknown SCID {}, ignoring",
1678-
scid
1669+
"Onion message intercepted, but no onion message mailbox available"
16791670
);
1680-
},
1681-
}
1671+
}
1672+
},
1673+
lightning::blinded_path::message::NextMessageHop::ShortChannelId(scid) => {
1674+
log_trace!(
1675+
self.logger,
1676+
"Onion message intercepted for unknown SCID {}, ignoring",
1677+
scid
1678+
);
1679+
},
16821680
},
16831681
LdkEvent::OnionMessagePeerConnected { peer_node_id } => {
16841682
if let Some(om_mailbox) = self.om_mailbox.as_ref() {

src/payment/bolt12.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,7 @@ impl Bolt12Payment {
307307
let (lsp_total_opening_fee, lsp_prop_opening_fee) = self.runtime.block_on(async move {
308308
if let Some(amount_msat) = amount_msat {
309309
liquidity_source
310-
.lsps2_register_bolt12_payment_paths(
311-
amount_msat,
312-
max_total_lsp_fee_limit_msat,
313-
)
310+
.lsps2_register_bolt12_payment_paths(amount_msat, max_total_lsp_fee_limit_msat)
314311
.await
315312
.map(|total_fee| (Some(total_fee), None))
316313
} else {
@@ -345,6 +342,39 @@ impl Bolt12Payment {
345342
Ok(offer)
346343
}
347344

345+
fn receive_async_jit_channel_inner(
346+
&self, max_proportional_lsp_fee_limit_ppm_msat: Option<u64>,
347+
) -> Result<LdkOffer, Error> {
348+
let liquidity_source =
349+
self.liquidity_source.as_ref().ok_or(Error::LiquiditySourceUnavailable)?;
350+
351+
let peer_info = self.connect_to_lsps2_peer(Arc::clone(liquidity_source))?;
352+
let liquidity_source = Arc::clone(liquidity_source);
353+
let lsp_prop_opening_fee = self.runtime.block_on(async move {
354+
liquidity_source
355+
.lsps2_register_variable_amount_bolt12_payment_paths(
356+
max_proportional_lsp_fee_limit_ppm_msat,
357+
)
358+
.await
359+
})?;
360+
361+
self.peer_store.add_peer(peer_info)?;
362+
self.channel_manager.refresh_async_receive_offers().or(Err(Error::OfferCreationFailed))?;
363+
let offer = self
364+
.channel_manager
365+
.await_async_receive_offer(Duration::from_secs(10))
366+
.or(Err(Error::OfferCreationFailed))?;
367+
368+
log_info!(
369+
self.logger,
370+
"JIT-channel async BOLT12 offer created: {} (max proportional LSP opening fee: {}ppm msat)",
371+
offer,
372+
lsp_prop_opening_fee
373+
);
374+
375+
Ok(offer)
376+
}
377+
348378
fn blinded_paths_for_async_recipient_internal(
349379
&self, recipient_id: Vec<u8>,
350380
) -> Result<Vec<BlindedMessagePath>, Error> {
@@ -684,6 +714,21 @@ impl Bolt12Payment {
684714
.map(maybe_wrap)
685715
.or(Err(Error::OfferCreationFailed))
686716
}
717+
718+
/// Retrieve an async [`Offer`] for receiving payments via an LSPS2 just-in-time (JIT) channel.
719+
///
720+
/// This requires a configured LSPS2 liquidity source as well as paths to a static invoice server
721+
/// via [`Bolt12Payment::set_paths_to_static_invoice_server`].
722+
///
723+
/// Since async offers are variable-amount, the LSP fee limit is expressed as a proportional
724+
/// limit in parts-per-million millisatoshis.
725+
pub fn receive_async_via_jit_channel(
726+
&self, max_proportional_lsp_fee_limit_ppm_msat: Option<u64>,
727+
) -> Result<Offer, Error> {
728+
let offer =
729+
self.receive_async_jit_channel_inner(max_proportional_lsp_fee_limit_ppm_msat)?;
730+
Ok(maybe_wrap(offer))
731+
}
687732
}
688733

689734
#[cfg(not(feature = "uniffi"))]

0 commit comments

Comments
 (0)