Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 161
Support client_trusts_lsp=true on ldk-node#687
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -491,7 +491,7 @@ where | ||
| counterparty_node_id, | ||
| channel_value_satoshis, | ||
| output_script, | ||
| .. | ||
| user_channel_id, | ||
| } => { | ||
| // Construct the raw transaction with the output that is paid the amount of the | ||
| // channel. | ||
| @@ -510,16 +510,44 @@ where | ||
| locktime, | ||
| ) { | ||
| Ok(final_tx) => { | ||
| // Give the funding transaction back to LDK for opening the channel. | ||
| match self.channel_manager.funding_transaction_generated( | ||
| temporary_channel_id, | ||
| counterparty_node_id, | ||
| final_tx, | ||
| ) { | ||
| let needs_manual_broadcast = | ||
| self.liquidity_source.as_ref().map_or(false, |ls| { | ||
joostjager marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ls.as_ref().lsps2_channel_needs_manual_broadcast( | ||
| counterparty_node_id, | ||
| user_channel_id, | ||
| ) | ||
| }); | ||
| let result = if needs_manual_broadcast { | ||
| self.liquidity_source.as_ref().map(|ls| { | ||
| ls.lsps2_store_funding_transaction( | ||
| user_channel_id, | ||
| counterparty_node_id, | ||
| final_tx.clone(), | ||
| ); | ||
| }); | ||
| self.channel_manager.funding_transaction_generated_manual_broadcast( | ||
| temporary_channel_id, | ||
| counterparty_node_id, | ||
| final_tx, | ||
| ) | ||
| } else { | ||
| self.channel_manager.funding_transaction_generated( | ||
| temporary_channel_id, | ||
| counterparty_node_id, | ||
| final_tx, | ||
| ) | ||
| }; | ||
| match result { | ||
| Ok(()) => {}, | ||
| Err(APIError::APIMisuseError { err }) => { | ||
| log_error!(self.logger, "Panicking due to APIMisuseError: {}", err); | ||
| panic!("APIMisuseError: {}", err); | ||
| log_error!( | ||
| self.logger, | ||
| "Encountered APIMisuseError, this should never happen: {}", | ||
| err | ||
| ); | ||
| debug_assert!(false, "APIMisuseError: {}", err); | ||
| }, | ||
| Err(APIError::ChannelUnavailable { err }) => { | ||
| log_error!( | ||
| @@ -547,15 +575,17 @@ where | ||
| ) | ||
| .unwrap_or_else(|e| { | ||
| log_error!(self.logger, "Failed to force close channel after funding generation failed: {:?}", e); | ||
| panic!( | ||
| debug_assert!(false, | ||
| "Failed to force close channel after funding generation failed" | ||
| ); | ||
| }); | ||
| }, | ||
| } | ||
| }, | ||
| LdkEvent::FundingTxBroadcastSafe { .. } => { | ||
| debug_assert!(false, "We currently only support safe funding, so this event should never be emitted."); | ||
| LdkEvent::FundingTxBroadcastSafe { user_channel_id, counterparty_node_id, .. } => { | ||
| self.liquidity_source.as_ref().map(|ls| { | ||
| ls.lsps2_funding_tx_broadcast_safe(user_channel_id, counterparty_node_id); | ||
| }); | ||
| }, | ||
| LdkEvent::PaymentClaimable { | ||
| payment_hash, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -14,6 +14,7 @@ use std::time::Duration; | ||
| use bitcoin::hashes::{sha256, Hash}; | ||
| use bitcoin::secp256k1::{PublicKey, Secp256k1}; | ||
| use bitcoin::Transaction; | ||
| use chrono::Utc; | ||
| use lightning::events::HTLCHandlingFailureType; | ||
| use lightning::ln::channelmanager::{InterceptId, MIN_FINAL_CLTV_EXPIRY_DELTA}; | ||
| @@ -51,7 +52,6 @@ use crate::{total_anchor_channels_reserve_sats, Config, Error}; | ||
| const LIQUIDITY_REQUEST_TIMEOUT_SECS: u64 = 5; | ||
| const LSPS2_GETINFO_REQUEST_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24); | ||
| const LSPS2_CLIENT_TRUSTS_LSP_MODE: bool = true; | ||
| const LSPS2_CHANNEL_CLTV_EXPIRY_DELTA: u32 = 72; | ||
| struct LSPS1Client { | ||
| @@ -130,6 +130,8 @@ pub struct LSPS2ServiceConfig { | ||
| pub min_payment_size_msat: u64, | ||
| /// The maximum payment size that we will accept when opening a channel. | ||
| pub max_payment_size_msat: u64, | ||
| /// Use the client trusts lsp model | ||
| pub client_trusts_lsp: bool, | ||
| } | ||
| pub(crate) struct LiquiditySourceBuilder<L: Deref> | ||
| @@ -305,6 +307,73 @@ where | ||
| self.lsps2_client.as_ref().map(|s| (s.lsp_node_id, s.lsp_address.clone())) | ||
| } | ||
| pub(crate) fn lsps2_channel_needs_manual_broadcast( | ||
| &self, counterparty_node_id: PublicKey, user_channel_id: u128, | ||
| ) -> bool { | ||
| self.lsps2_service.as_ref().map_or(false, |lsps2_service| { | ||
Contributor 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 q about error logging. 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. See above, I think continuing and just logging on the manual-broadcast step is preferable. | ||
| lsps2_service.service_config.client_trusts_lsp | ||
| && self | ||
| .liquidity_manager() | ||
| .lsps2_service_handler() | ||
| .and_then(|handler| { | ||
| handler | ||
| .channel_needs_manual_broadcast(user_channel_id, &counterparty_node_id) | ||
| .ok() | ||
| }) | ||
| .unwrap_or(false) | ||
| }) | ||
| } | ||
| pub(crate) fn lsps2_store_funding_transaction( | ||
tnull marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| &self, user_channel_id: u128, counterparty_node_id: PublicKey, funding_tx: Transaction, | ||
| ) { | ||
| if self.lsps2_service.as_ref().map_or(false, |svc| !svc.service_config.client_trusts_lsp) { | ||
| // Only necessary for client-trusts-LSP flow | ||
| return; | ||
| } | ||
| let lsps2_service_handler = self.liquidity_manager.lsps2_service_handler(); | ||
| if let Some(handler) = lsps2_service_handler { | ||
| handler | ||
| .store_funding_transaction(user_channel_id, &counterparty_node_id, funding_tx) | ||
| .unwrap_or_else(|e| { | ||
| debug_assert!(false, "Failed to store funding transaction: {:?}", e); | ||
| log_error!(self.logger, "Failed to store funding transaction: {:?}", e); | ||
| }); | ||
| } else { | ||
| log_error!(self.logger, "LSPS2 service handler is not available."); | ||
| } | ||
| } | ||
| pub(crate) fn lsps2_funding_tx_broadcast_safe( | ||
| &self, user_channel_id: u128, counterparty_node_id: PublicKey, | ||
| ) { | ||
| if self.lsps2_service.as_ref().map_or(false, |svc| !svc.service_config.client_trusts_lsp) { | ||
| // Only necessary for client-trusts-LSP flow | ||
| return; | ||
| } | ||
| let lsps2_service_handler = self.liquidity_manager.lsps2_service_handler(); | ||
| if let Some(handler) = lsps2_service_handler { | ||
| handler | ||
| .set_funding_tx_broadcast_safe(user_channel_id, &counterparty_node_id) | ||
| .unwrap_or_else(|e| { | ||
| debug_assert!( | ||
| false, | ||
| "Failed to mark funding transaction safe to broadcast: {:?}", | ||
| e | ||
| ); | ||
| log_error!( | ||
| self.logger, | ||
| "Failed to mark funding transaction safe to broadcast: {:?}", | ||
| e | ||
| ); | ||
| }); | ||
| } else { | ||
| log_error!(self.logger, "LSPS2 service handler is not available."); | ||
| } | ||
| } | ||
| pub(crate) async fn handle_next_event(&self) { | ||
| match self.liquidity_manager.next_event_async().await { | ||
| LiquidityEvent::LSPS1Client(LSPS1ClientEvent::SupportedOptionsReady { | ||
| @@ -594,7 +663,7 @@ where | ||
| request_id, | ||
| intercept_scid, | ||
| LSPS2_CHANNEL_CLTV_EXPIRY_DELTA, | ||
| LSPS2_CLIENT_TRUSTS_LSP_MODE, | ||
| service_config.client_trusts_lsp, | ||
| user_channel_id, | ||
| ) | ||
| .await | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.