-
Notifications
You must be signed in to change notification settings - Fork 27
LSPS2 client support #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tnull
wants to merge
3
commits into
lightningdevkit:main
Choose a base branch
from
tnull:2026-03-lsps2-client-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+411
−19
Open
LSPS2 client support #143
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,9 @@ use ldk_server_client::error::LdkServerErrorCode::{ | |
| AuthError, InternalError, InternalServerError, InvalidRequestError, LightningError, | ||
| }; | ||
| use ldk_server_client::ldk_server_protos::api::{ | ||
| Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse, | ||
| Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11ReceiveVariableAmountViaJitChannelRequest, | ||
| Bolt11ReceiveVariableAmountViaJitChannelResponse, Bolt11ReceiveViaJitChannelRequest, | ||
| Bolt11ReceiveViaJitChannelResponse, Bolt11SendRequest, Bolt11SendResponse, | ||
| Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse, | ||
| CloseChannelRequest, CloseChannelResponse, ConnectPeerRequest, ConnectPeerResponse, | ||
| DisconnectPeerRequest, DisconnectPeerResponse, ExportPathfindingScoresRequest, | ||
|
|
@@ -133,6 +135,41 @@ enum Commands { | |
| #[arg(short, long, help = "Invoice expiry time in seconds (default: 86400)")] | ||
| expiry_secs: Option<u32>, | ||
| }, | ||
| #[command(about = "Create a fixed-amount BOLT11 invoice to receive via an LSPS2 JIT channel")] | ||
| Bolt11ReceiveViaJitChannel { | ||
| #[arg(help = "Amount to request, e.g. 50sat or 50000msat")] | ||
| amount: Amount, | ||
| #[arg(short, long, help = "Description to attach along with the invoice")] | ||
| description: Option<String>, | ||
| #[arg( | ||
| long, | ||
| help = "SHA-256 hash of the description (hex). Use instead of description for longer text" | ||
| )] | ||
| description_hash: Option<String>, | ||
| #[arg(short, long, help = "Invoice expiry time in seconds (default: 86400)")] | ||
| expiry_secs: Option<u32>, | ||
| #[arg( | ||
| long, | ||
| help = "Maximum total fee an LSP may deduct for opening the JIT channel, e.g. 50sat or 50000msat" | ||
| )] | ||
| max_total_lsp_fee_limit: Option<Amount>, | ||
| }, | ||
| #[command( | ||
| about = "Create a variable-amount BOLT11 invoice to receive via an LSPS2 JIT channel" | ||
| )] | ||
| Bolt11ReceiveVariableAmountViaJitChannel { | ||
| #[arg(short, long, help = "Description to attach along with the invoice")] | ||
| description: Option<String>, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| #[arg( | ||
| long, | ||
| help = "SHA-256 hash of the description (hex). Use instead of description for longer text" | ||
| )] | ||
| description_hash: Option<String>, | ||
| #[arg(short, long, help = "Invoice expiry time in seconds (default: 86400)")] | ||
| expiry_secs: Option<u32>, | ||
| #[arg(long, help = "Maximum proportional fee the LSP may deduct in ppm-msat")] | ||
| max_proportional_lsp_fee_limit_ppm_msat: Option<u64>, | ||
| }, | ||
| #[command(about = "Pay a BOLT11 invoice")] | ||
| Bolt11Send { | ||
| #[arg(help = "A BOLT11 invoice for a payment within the Lightning Network")] | ||
|
|
@@ -510,21 +547,8 @@ async fn main() { | |
| }, | ||
| Commands::Bolt11Receive { description, description_hash, expiry_secs, amount } => { | ||
| let amount_msat = amount.map(|a| a.to_msat()); | ||
| let invoice_description = match (description, description_hash) { | ||
| (Some(desc), None) => Some(Bolt11InvoiceDescription { | ||
| kind: Some(bolt11_invoice_description::Kind::Direct(desc)), | ||
| }), | ||
| (None, Some(hash)) => Some(Bolt11InvoiceDescription { | ||
| kind: Some(bolt11_invoice_description::Kind::Hash(hash)), | ||
| }), | ||
| (Some(_), Some(_)) => { | ||
| handle_error(LdkServerError::new( | ||
| InternalError, | ||
| "Only one of description or description_hash can be set.".to_string(), | ||
| )); | ||
| }, | ||
| (None, None) => None, | ||
| }; | ||
| let invoice_description = | ||
| parse_bolt11_invoice_description(description, description_hash); | ||
|
|
||
| let expiry_secs = expiry_secs.unwrap_or(DEFAULT_EXPIRY_SECS); | ||
| let request = | ||
|
|
@@ -534,6 +558,40 @@ async fn main() { | |
| client.bolt11_receive(request).await, | ||
| ); | ||
| }, | ||
| Commands::Bolt11ReceiveViaJitChannel { | ||
| amount, | ||
| description, | ||
| description_hash, | ||
| expiry_secs, | ||
| max_total_lsp_fee_limit, | ||
| } => { | ||
| let request = Bolt11ReceiveViaJitChannelRequest { | ||
| amount_msat: amount.to_msat(), | ||
| description: parse_bolt11_invoice_description(description, description_hash), | ||
| expiry_secs: expiry_secs.unwrap_or(DEFAULT_EXPIRY_SECS), | ||
| max_total_lsp_fee_limit_msat: max_total_lsp_fee_limit.map(|a| a.to_msat()), | ||
| }; | ||
|
|
||
| handle_response_result::<_, Bolt11ReceiveViaJitChannelResponse>( | ||
| client.bolt11_receive_via_jit_channel(request).await, | ||
| ); | ||
| }, | ||
| Commands::Bolt11ReceiveVariableAmountViaJitChannel { | ||
| description, | ||
| description_hash, | ||
| expiry_secs, | ||
| max_proportional_lsp_fee_limit_ppm_msat, | ||
| } => { | ||
| let request = Bolt11ReceiveVariableAmountViaJitChannelRequest { | ||
| description: parse_bolt11_invoice_description(description, description_hash), | ||
| expiry_secs: expiry_secs.unwrap_or(DEFAULT_EXPIRY_SECS), | ||
| max_proportional_lsp_fee_limit_ppm_msat, | ||
| }; | ||
|
|
||
| handle_response_result::<_, Bolt11ReceiveVariableAmountViaJitChannelResponse>( | ||
| client.bolt11_receive_variable_amount_via_jit_channel(request).await, | ||
| ); | ||
| }, | ||
| Commands::Bolt11Send { | ||
| invoice, | ||
| amount, | ||
|
|
@@ -928,6 +986,26 @@ where | |
| } | ||
| } | ||
|
|
||
| fn parse_bolt11_invoice_description( | ||
| description: Option<String>, description_hash: Option<String>, | ||
| ) -> Option<Bolt11InvoiceDescription> { | ||
| match (description, description_hash) { | ||
| (Some(desc), None) => Some(Bolt11InvoiceDescription { | ||
| kind: Some(bolt11_invoice_description::Kind::Direct(desc)), | ||
| }), | ||
| (None, Some(hash)) => Some(Bolt11InvoiceDescription { | ||
| kind: Some(bolt11_invoice_description::Kind::Hash(hash)), | ||
| }), | ||
| (Some(_), Some(_)) => { | ||
| handle_error(LdkServerError::new( | ||
| InternalError, | ||
| "Only one of description or description_hash can be set.".to_string(), | ||
| )); | ||
| }, | ||
| (None, None) => None, | ||
| } | ||
| } | ||
|
|
||
| fn parse_page_token(token_str: &str) -> Result<PageToken, LdkServerError> { | ||
| let parts: Vec<&str> = token_str.split(':').collect(); | ||
| if parts.len() != 2 { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,15 @@ server_url = "https://mempool.space/api" # Esplora endpoint | |
| connection_string = "" # RabbitMQ connection string | ||
| exchange_name = "" | ||
|
|
||
| # LSPS2 Client Support | ||
| [liquidity.lsps2_client] | ||
| # The public key of the LSPS2 LSP we source just-in-time liquidity from. | ||
| node_pubkey = "<lsp node pubkey>" | ||
| # Address to connect to the LSPS2 LSP (IPv4:port, IPv6:port, OnionV3:port, or hostname:port). | ||
| address = "127.0.0.1:9735" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make this not a local host ip, that might confused people thinking its something they are supposed to run |
||
| # Optional token for authenticating to the LSP. | ||
| # token = "" | ||
|
|
||
| # Experimental LSPS2 Service Support | ||
| # CAUTION: LSPS2 support is highly experimental and for testing purposes only. | ||
| [liquidity.lsps2_service] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // This file is Copyright its original authors, visible in version control | ||
| // history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| use ldk_server_protos::api::{ | ||
| Bolt11ReceiveVariableAmountViaJitChannelRequest, | ||
| Bolt11ReceiveVariableAmountViaJitChannelResponse, Bolt11ReceiveViaJitChannelRequest, | ||
| Bolt11ReceiveViaJitChannelResponse, | ||
| }; | ||
|
|
||
| use crate::api::error::LdkServerError; | ||
| use crate::service::Context; | ||
| use crate::util::proto_adapter::proto_to_bolt11_description; | ||
|
|
||
| pub(crate) fn handle_bolt11_receive_via_jit_channel_request( | ||
| context: Context, request: Bolt11ReceiveViaJitChannelRequest, | ||
| ) -> Result<Bolt11ReceiveViaJitChannelResponse, LdkServerError> { | ||
| let description = proto_to_bolt11_description(request.description)?; | ||
| let invoice = context.node.bolt11_payment().receive_via_jit_channel( | ||
| request.amount_msat, | ||
| &description, | ||
| request.expiry_secs, | ||
| request.max_total_lsp_fee_limit_msat, | ||
| )?; | ||
|
|
||
| Ok(Bolt11ReceiveViaJitChannelResponse { invoice: invoice.to_string() }) | ||
| } | ||
|
|
||
| pub(crate) fn handle_bolt11_receive_variable_amount_via_jit_channel_request( | ||
| context: Context, request: Bolt11ReceiveVariableAmountViaJitChannelRequest, | ||
| ) -> Result<Bolt11ReceiveVariableAmountViaJitChannelResponse, LdkServerError> { | ||
| let description = proto_to_bolt11_description(request.description)?; | ||
| let invoice = context.node.bolt11_payment().receive_variable_amount_via_jit_channel( | ||
| &description, | ||
| request.expiry_secs, | ||
| request.max_proportional_lsp_fee_limit_ppm_msat, | ||
| )?; | ||
|
|
||
| Ok(Bolt11ReceiveVariableAmountViaJitChannelResponse { invoice: invoice.to_string() }) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we drop
short, longhere so you can just feed the description directly