Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Merge pull request #959 from johncantrell97/latest-liquidity
Browse files Browse the repository at this point in the history
update to latest liquidity lib
  • Loading branch information
AnthonyRonning authored Jan 19, 2024
2 parents 47ce818 + 4a78276 commit 9990697
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mutiny-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
46 changes: 26 additions & 20 deletions mutiny-core/src/lsp/lsps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -111,9 +112,9 @@ impl<S: MutinyStorage> LspsClient<S> {
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,
Expand All @@ -140,15 +141,15 @@ impl<S: MutinyStorage> LspsClient<S> {
}
}
}
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();

Expand Down Expand Up @@ -197,7 +198,7 @@ impl<S: MutinyStorage> LspsClient<S> {

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,
Expand Down Expand Up @@ -369,17 +370,17 @@ impl<S: MutinyStorage> Lsp for LspsClient<S> {
&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);
Expand Down Expand Up @@ -447,7 +448,12 @@ impl<S: MutinyStorage> Lsp for LspsClient<S> {
(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)?;

Expand Down
28 changes: 16 additions & 12 deletions mutiny-core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,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::*;
Expand Down Expand Up @@ -114,7 +113,6 @@ pub(crate) type OnionMessenger<S: MutinyStorage> = LdkOnionMessenger<
pub type LiquidityManager<S> = LDKLSPLiquidityManager<
Arc<PhantomKeysManager<S>>,
Arc<PhantomChannelManager<S>>,
Arc<PeerManagerImpl<S>>,
Arc<dyn Filter + Send + Sync>,
>;

Expand Down Expand Up @@ -437,16 +435,13 @@ impl<S: MutinyStorage> NodeBuilder<S> {
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 {}),
}),
));

(
Expand Down Expand Up @@ -488,7 +483,9 @@ impl<S: MutinyStorage> NodeBuilder<S> {
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(
Expand Down Expand Up @@ -516,6 +513,13 @@ impl<S: MutinyStorage> NodeBuilder<S> {
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();
Expand Down

0 comments on commit 9990697

Please sign in to comment.