Skip to content

Commit 532fb4a

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 816ef4b commit 532fb4a

File tree

3 files changed

+365
-35
lines changed

3 files changed

+365
-35
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/payment/bolt12.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,39 @@ impl Bolt12Payment {
342342
Ok(offer)
343343
}
344344

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+
345378
fn blinded_paths_for_async_recipient_internal(
346379
&self, recipient_id: Vec<u8>,
347380
) -> Result<Vec<BlindedMessagePath>, Error> {
@@ -681,6 +714,21 @@ impl Bolt12Payment {
681714
.map(maybe_wrap)
682715
.or(Err(Error::OfferCreationFailed))
683716
}
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+
}
684732
}
685733

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

0 commit comments

Comments
 (0)