diff --git a/Cargo.lock b/Cargo.lock index efc583c6a..d0d9cc15b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2339,7 +2339,7 @@ dependencies = [ [[package]] name = "lightning-liquidity" version = "0.1.0" -source = "git+https://github.com/lightningdevkit/lightning-liquidity.git?rev=e00d917a8bb17e29493497538c7a4dda00bef151#e00d917a8bb17e29493497538c7a4dda00bef151" +source = "git+https://github.com/johncantrell97/ldk-lsp-client.git?rev=9e01757d20c04aa31c28de8c4ffab5442d547edc#9e01757d20c04aa31c28de8c4ffab5442d547edc" dependencies = [ "bitcoin 0.29.2", "chrono", diff --git a/mutiny-core/Cargo.toml b/mutiny-core/Cargo.toml index 043ec94ed..ad4bc57a0 100644 --- a/mutiny-core/Cargo.toml +++ b/mutiny-core/Cargo.toml @@ -32,7 +32,7 @@ lightning-invoice = { version = "0.26.0", features = ["serde"] } lightning-rapid-gossip-sync = { version = "0.0.118" } lightning-background-processor = { version = "0.0.118", features = ["futures"] } lightning-transaction-sync = { version = "0.0.118", features = ["esplora-async-https"] } -lightning-liquidity = { git = "https://github.com/lightningdevkit/lightning-liquidity.git", rev = "e00d917a8bb17e29493497538c7a4dda00bef151" } +lightning-liquidity = { git = "https://github.com/johncantrell97/ldk-lsp-client.git", rev = "9e01757d20c04aa31c28de8c4ffab5442d547edc" } chrono = "0.4.22" futures-util = { version = "0.3", default-features = false } reqwest = { version = "0.11", default-features = false, features = ["json"] } diff --git a/mutiny-core/src/lsp/lsps.rs b/mutiny-core/src/lsp/lsps.rs index b8a4d7f5a..a3509514b 100644 --- a/mutiny-core/src/lsp/lsps.rs +++ b/mutiny-core/src/lsp/lsps.rs @@ -10,8 +10,9 @@ use lightning::routing::router::{RouteHint, RouteHintHop}; use lightning::util::logger::Logger; use lightning::{log_debug, log_error, log_info}; use lightning_invoice::{Bolt11Invoice, InvoiceBuilder}; -use lightning_liquidity::events; -use lightning_liquidity::lsps2::{LSPS2Event, OpeningFeeParams}; +use lightning_liquidity::events::Event; +use lightning_liquidity::lsps2::event::LSPS2ClientEvent; +use lightning_liquidity::lsps2::msgs::OpeningFeeParams; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::sync::atomic::{AtomicBool, Ordering}; @@ -111,9 +112,9 @@ impl LspsClient { Ok(client) } - pub(crate) async fn handle_event(&self, event: events::Event) { + pub(crate) async fn handle_event(&self, event: Event) { match event { - events::Event::LSPS2(LSPS2Event::GetInfoResponse { + Event::LSPS2Client(LSPS2ClientEvent::GetInfoResponse { jit_channel_id, opening_fee_params_menu, user_channel_id, @@ -140,15 +141,15 @@ impl LspsClient { } } } - events::Event::LSPS2(LSPS2Event::InvoiceGenerationReady { - scid, + Event::LSPS2Client(LSPS2ClientEvent::InvoiceGenerationReady { + intercept_scid, cltv_expiry_delta, user_channel_id, counterparty_node_id, payment_size_msat, .. }) => { - log_debug!(self.logger, "received InvoiceGenerationReady with scid {}, cltv_expiry_delta {}, user_channel_id {}, counterparty_node_id {}, payment_size_msat {:?}", scid, cltv_expiry_delta, user_channel_id, counterparty_node_id, payment_size_msat); + log_debug!(self.logger, "received InvoiceGenerationReady with intercept_scid {}, cltv_expiry_delta {}, user_channel_id {}, counterparty_node_id {}, payment_size_msat {:?}", intercept_scid, cltv_expiry_delta, user_channel_id, counterparty_node_id, payment_size_msat); let mut pending_buy_requests = self.pending_buy_requests.lock().unwrap(); @@ -197,7 +198,7 @@ impl LspsClient { let lsp_route_hint = RouteHint(vec![RouteHintHop { src_node_id: counterparty_node_id, - short_channel_id: scid, + short_channel_id: intercept_scid, fees: RoutingFees { base_msat: 0, proportional_millionths: 0, @@ -369,17 +370,17 @@ impl Lsp for LspsClient { &self.token ); - self.liquidity_manager - .lsps2_create_invoice( - self.pubkey, - Some(fee_request.amount_msat), - self.token.clone(), - user_channel_id, - ) - .map_err(|e| { - log_debug!(self.logger, "error creating lsps2 invoice: {:?}", e); - MutinyError::LspGenericError - })?; + let lsps2_client_handler = self + .liquidity_manager + .lsps2_client_handler() + .expect("to be configured with lsps2 client config"); + + lsps2_client_handler.create_invoice( + self.pubkey, + Some(fee_request.amount_msat), + self.token.clone(), + user_channel_id, + ); let get_info_response = pending_fee_request_receiver.await.map_err(|e| { log_debug!(self.logger, "error receiving get info response: {:?}", e); @@ -447,7 +448,12 @@ impl Lsp for LspsClient { (channel_info.channel_id, channel_info.fee_params.clone()) }; - self.liquidity_manager + let lsps2_client_handler = self + .liquidity_manager + .lsps2_client_handler() + .expect("to be configured with lsps2 client config"); + + lsps2_client_handler .opening_fee_params_selected(self.pubkey, channel_id, fee_params.clone()) .map_err(|_| MutinyError::LspGenericError)?; diff --git a/mutiny-core/src/node.rs b/mutiny-core/src/node.rs index 65d633384..9cda2f845 100644 --- a/mutiny-core/src/node.rs +++ b/mutiny-core/src/node.rs @@ -68,9 +68,8 @@ use lightning_invoice::{ utils::{create_invoice_from_channelmanager_and_duration_since_epoch, create_phantom_invoice}, Bolt11Invoice, }; -use lightning_liquidity::{ - JITChannelsConfig, LiquidityManager as LDKLSPLiquidityManager, LiquidityProviderConfig, -}; +use lightning_liquidity::lsps2::client::LSPS2ClientConfig; +use lightning_liquidity::{LiquidityClientConfig, LiquidityManager as LDKLSPLiquidityManager}; #[cfg(test)] use mockall::predicate::*; @@ -110,7 +109,6 @@ pub(crate) type OnionMessenger = LdkOnionMessenger< pub type LiquidityManager = LDKLSPLiquidityManager< Arc>, Arc>, - Arc>, Arc, >; @@ -433,16 +431,13 @@ impl NodeBuilder { Some(LspConfig::Lsps(lsps_config)) => { let liquidity_manager = Arc::new(LiquidityManager::new( keys_manager.clone(), - Some(LiquidityProviderConfig { - lsps2_config: Some(JITChannelsConfig { - promise_secret: [0; 32], - min_payment_size_msat: 0, - max_payment_size_msat: 9999999999, - }), - }), channel_manager.clone(), None, None, + None, + Some(LiquidityClientConfig { + lsps2_client_config: Some(LSPS2ClientConfig {}), + }), )); ( @@ -484,7 +479,9 @@ impl NodeBuilder { chan_handler: channel_manager.clone(), route_handler, onion_message_handler, - custom_message_handler: Arc::new(MutinyMessageHandler { liquidity }), + custom_message_handler: Arc::new(MutinyMessageHandler { + liquidity: liquidity.clone(), + }), }; let bump_tx_event_handler = Arc::new(BumpTransactionEventHandler::new( @@ -512,6 +509,13 @@ impl NodeBuilder { logger.clone(), )); + if let Some(liquidity) = liquidity { + let process_msgs_pm = peer_man.clone(); + liquidity.set_process_msgs_callback(move || { + process_msgs_pm.process_events(); + }); + } + // sync to chain tip if read_channel_manager.is_restarting { let mut chain_listener_channel_monitors = Vec::new();