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

Commit 51e7f90

Browse files
committed
Move client_trusts_lsp flag from event to config
Rather than exposing it to the user via an event, we move the `client_trusts_lsp` flag to `LSPS2ClientConfig`, defaulting to `true` for now. So instead of leaving it up to the user, we reject a buy response that doesn't meet our configured trust settings.
1 parent 5e0076c commit 51e7f90

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/lsps2/client.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use lightning::util::logger::Level;
2323

2424
use bitcoin::secp256k1::PublicKey;
2525

26+
use core::default::Default;
2627
use core::ops::Deref;
2728

2829
use crate::lsps2::msgs::{
@@ -32,7 +33,21 @@ use crate::lsps2::msgs::{
3233

3334
/// Client-side configuration options for JIT channels.
3435
#[derive(Clone, Debug, Copy)]
35-
pub struct LSPS2ClientConfig {}
36+
pub struct LSPS2ClientConfig {
37+
/// Trust the LSP to create a valid channel funding transaction and have it confirmed on-chain.
38+
///
39+
/// TODO: If set to `false`, we'll only release the pre-image after we see an on-chain
40+
/// confirmation of the channel's funding transaction.
41+
///
42+
/// Defaults to `true`.
43+
pub client_trusts_lsp: bool,
44+
}
45+
46+
impl Default for LSPS2ClientConfig {
47+
fn default() -> Self {
48+
Self { client_trusts_lsp: true }
49+
}
50+
}
3651

3752
struct ChannelStateError(String);
3853

@@ -167,7 +182,7 @@ where
167182
pending_messages: Arc<MessageQueue>,
168183
pending_events: Arc<EventQueue>,
169184
per_peer_state: RwLock<HashMap<PublicKey, Mutex<PeerState>>>,
170-
_config: LSPS2ClientConfig,
185+
config: LSPS2ClientConfig,
171186
}
172187

173188
impl<ES: Deref> LSPS2ClientHandler<ES>
@@ -184,7 +199,7 @@ where
184199
pending_messages,
185200
pending_events,
186201
per_peer_state: RwLock::new(HashMap::new()),
187-
_config: config,
202+
config,
188203
}
189204
}
190205

@@ -405,6 +420,18 @@ where
405420
action: ErrorAction::IgnoreAndLog(Level::Info),
406421
})?;
407422

423+
// Reject the buy response if we disallow client_trusts_lsp and the LSP requires
424+
// it.
425+
if !self.config.client_trusts_lsp && result.client_trusts_lsp {
426+
peer_state.remove_inbound_channel(jit_channel_id);
427+
return Err(LightningError {
428+
err: format!(
429+
"Aborting JIT channel flow as the LSP requires 'client_trusts_lsp' mode, which we disallow"
430+
),
431+
action: ErrorAction::IgnoreAndLog(Level::Info),
432+
});
433+
}
434+
408435
if let Err(e) = jit_channel.invoice_params_received(
409436
result.client_trusts_lsp,
410437
result.intercept_scid.clone(),
@@ -420,7 +447,6 @@ where
420447
intercept_scid,
421448
cltv_expiry_delta: result.lsp_cltv_expiry_delta,
422449
payment_size_msat: jit_channel.config.payment_size_msat,
423-
client_trusts_lsp: result.client_trusts_lsp,
424450
user_channel_id: jit_channel.config.user_id,
425451
},
426452
));

src/lsps2/event.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ pub enum LSPS2ClientEvent {
5858
cltv_expiry_delta: u32,
5959
/// The initial payment size you specified.
6060
payment_size_msat: Option<u64>,
61-
/// The trust model the LSP expects.
62-
client_trusts_lsp: bool,
6361
/// The `user_channel_id` value passed in to [`LSPS2ClientHandler::create_invoice`].
6462
///
6563
/// [`LSPS2ClientHandler::create_invoice`]: crate::lsps2::client::LSPS2ClientHandler::create_invoice

0 commit comments

Comments
 (0)