@@ -1623,12 +1623,38 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
16231623 description,
16241624 expiry_secs,
16251625 max_total_lsp_fee_limit_msat,
1626+ None ,
1627+ )
1628+ }
1629+
1630+ /// Returns a payable invoice that can be used to request a variable amount payment (also known
1631+ /// as "zero-amount" invoice) and receive it via a newly created just-in-time (JIT) channel.
1632+ ///
1633+ /// When the returned invoice is paid, the configured [LSPS2]-compliant LSP will open a channel
1634+ /// to us, supplying just-in-time inbound liquidity.
1635+ ///
1636+ /// If set, `max_proportional_lsp_fee_limit_ppm_msat` will limit how much proportional fee, in
1637+ /// parts-per-million millisatoshis, we allow the LSP to take for opening the channel to us.
1638+ /// We'll use its cheapest offer otherwise.
1639+ ///
1640+ /// [LSPS2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
1641+ pub fn receive_variable_amount_payment_via_jit_channel (
1642+ & self , description : & str , expiry_secs : u32 ,
1643+ max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
1644+ ) -> Result < Bolt11Invoice , Error > {
1645+ self . receive_payment_via_jit_channel_inner (
1646+ None ,
1647+ description,
1648+ expiry_secs,
1649+ None ,
1650+ max_proportional_lsp_fee_limit_ppm_msat,
16261651 )
16271652 }
16281653
16291654 fn receive_payment_via_jit_channel_inner (
16301655 & self , amount_msat : Option < u64 > , description : & str , expiry_secs : u32 ,
16311656 max_total_lsp_fee_limit_msat : Option < u64 > ,
1657+ max_proportional_lsp_fee_limit_ppm_msat : Option < u64 > ,
16321658 ) -> Result < Bolt11Invoice , Error > {
16331659 let liquidity_source =
16341660 self . liquidity_source . as_ref ( ) . ok_or ( Error :: LiquiditySourceUnavailable ) ?;
@@ -1658,29 +1684,38 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
16581684 log_info ! ( self . logger, "Connected to LSP {}@{}. " , peer_info. node_id, peer_info. address) ;
16591685
16601686 let liquidity_source = Arc :: clone ( & liquidity_source) ;
1661- let ( invoice, lsp_total_opening_fee) = tokio:: task:: block_in_place ( move || {
1662- runtime. block_on ( async move {
1663- if let Some ( amount_msat) = amount_msat {
1664- liquidity_source
1665- . lsps2_receive_to_jit_channel (
1666- amount_msat,
1667- description,
1668- expiry_secs,
1669- max_total_lsp_fee_limit_msat,
1670- )
1671- . await
1672- . map ( |( invoice, total_fee) | ( invoice, Some ( total_fee) ) )
1673- } else {
1674- // TODO: will be implemented in the next commit
1675- Err ( Error :: LiquidityRequestFailed )
1676- }
1677- } )
1678- } ) ?;
1687+ let ( invoice, lsp_total_opening_fee, lsp_prop_opening_fee) =
1688+ tokio:: task:: block_in_place ( move || {
1689+ runtime. block_on ( async move {
1690+ if let Some ( amount_msat) = amount_msat {
1691+ liquidity_source
1692+ . lsps2_receive_to_jit_channel (
1693+ amount_msat,
1694+ description,
1695+ expiry_secs,
1696+ max_total_lsp_fee_limit_msat,
1697+ )
1698+ . await
1699+ . map ( |( invoice, total_fee) | ( invoice, Some ( total_fee) , None ) )
1700+ } else {
1701+ liquidity_source
1702+ . lsps2_receive_variable_amount_to_jit_channel (
1703+ description,
1704+ expiry_secs,
1705+ max_proportional_lsp_fee_limit_ppm_msat,
1706+ )
1707+ . await
1708+ . map ( |( invoice, prop_fee) | ( invoice, None , Some ( prop_fee) ) )
1709+ }
1710+ } )
1711+ } ) ?;
16791712
16801713 // Register payment in payment store.
16811714 let payment_hash = PaymentHash ( invoice. payment_hash ( ) . to_byte_array ( ) ) ;
1682- let lsp_fee_limits =
1683- Some ( LSPFeeLimits { max_total_opening_fee_msat : lsp_total_opening_fee } ) ;
1715+ let lsp_fee_limits = Some ( LSPFeeLimits {
1716+ max_total_opening_fee_msat : lsp_total_opening_fee,
1717+ max_proportional_opening_fee_ppm_msat : lsp_prop_opening_fee,
1718+ } ) ;
16841719 let payment = PaymentDetails {
16851720 hash : payment_hash,
16861721 preimage : None ,
0 commit comments