Skip to content

Commit d01fc0d

Browse files
committed
Move lsp_fee_limits to PaymentKind::Bolt11Jit variant
1 parent 1e74787 commit d01fc0d

File tree

6 files changed

+43
-39
lines changed

6 files changed

+43
-39
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ interface ClosureReason {
222222
interface PaymentKind {
223223
Onchain();
224224
Bolt11();
225+
Bolt11Jit(LSPFeeLimits? lsp_fee_limits);
225226
Bolt12();
226227
Spontaneous();
227228
};
@@ -250,7 +251,6 @@ dictionary PaymentDetails {
250251
u64? amount_msat;
251252
PaymentDirection direction;
252253
PaymentStatus status;
253-
LSPFeeLimits? lsp_fee_limits;
254254
};
255255

256256
[NonExhaustive]

src/event.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,23 @@ where
432432
return;
433433
}
434434

435-
let max_total_opening_fee_msat = info
436-
.lsp_fee_limits
437-
.and_then(|l| {
438-
l.max_total_opening_fee_msat.or_else(|| {
439-
l.max_proportional_opening_fee_ppm_msat.and_then(|max_prop_fee| {
440-
// If it's a variable amount payment, compute the actual fee.
441-
compute_opening_fee(amount_msat, 0, max_prop_fee)
435+
let max_total_opening_fee_msat = match info.kind {
436+
Some(PaymentKind::Bolt11Jit { lsp_fee_limits }) => {
437+
lsp_fee_limits
438+
.and_then(|l| {
439+
l.max_total_opening_fee_msat.or_else(|| {
440+
l.max_proportional_opening_fee_ppm_msat.and_then(
441+
|max_prop_fee| {
442+
// If it's a variable amount payment, compute the actual fee.
443+
compute_opening_fee(amount_msat, 0, max_prop_fee)
444+
},
445+
)
446+
})
442447
})
443-
})
444-
})
445-
.unwrap_or(0);
448+
.unwrap_or(0)
449+
},
450+
_ => 0,
451+
};
446452

447453
if counterparty_skimmed_fee_msat > max_total_opening_fee_msat {
448454
log_info!(
@@ -558,7 +564,6 @@ where
558564
amount_msat: Some(amount_msat),
559565
direction: PaymentDirection::Inbound,
560566
status: PaymentStatus::Succeeded,
561-
lsp_fee_limits: None,
562567
};
563568

564569
match self.payment_store.insert(payment) {

src/payment/bolt11.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ impl Bolt11Payment {
110110
amount_msat: invoice.amount_milli_satoshis(),
111111
direction: PaymentDirection::Outbound,
112112
status: PaymentStatus::Pending,
113-
lsp_fee_limits: None,
114113
};
115114
self.payment_store.insert(payment)?;
116115

@@ -129,7 +128,6 @@ impl Bolt11Payment {
129128
amount_msat: invoice.amount_milli_satoshis(),
130129
direction: PaymentDirection::Outbound,
131130
status: PaymentStatus::Failed,
132-
lsp_fee_limits: None,
133131
};
134132

135133
self.payment_store.insert(payment)?;
@@ -218,7 +216,6 @@ impl Bolt11Payment {
218216
amount_msat: Some(amount_msat),
219217
direction: PaymentDirection::Outbound,
220218
status: PaymentStatus::Pending,
221-
lsp_fee_limits: None,
222219
};
223220
self.payment_store.insert(payment)?;
224221

@@ -238,7 +235,6 @@ impl Bolt11Payment {
238235
amount_msat: Some(amount_msat),
239236
direction: PaymentDirection::Outbound,
240237
status: PaymentStatus::Failed,
241-
lsp_fee_limits: None,
242238
};
243239
self.payment_store.insert(payment)?;
244240

@@ -299,7 +295,6 @@ impl Bolt11Payment {
299295
amount_msat,
300296
direction: PaymentDirection::Inbound,
301297
status: PaymentStatus::Pending,
302-
lsp_fee_limits: None,
303298
};
304299

305300
self.payment_store.insert(payment)?;
@@ -418,15 +413,15 @@ impl Bolt11Payment {
418413
max_total_opening_fee_msat: lsp_total_opening_fee,
419414
max_proportional_opening_fee_ppm_msat: lsp_prop_opening_fee,
420415
});
416+
let kind = Some(PaymentKind::Bolt11Jit { lsp_fee_limits });
421417
let payment = PaymentDetails {
422-
kind: Some(PaymentKind::Bolt11),
418+
kind,
423419
hash: payment_hash,
424420
preimage: None,
425421
secret: Some(invoice.payment_secret().clone()),
426422
amount_msat,
427423
direction: PaymentDirection::Inbound,
428424
status: PaymentStatus::Pending,
429-
lsp_fee_limits,
430425
};
431426

432427
self.payment_store.insert(payment)?;

src/payment/payment_store.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,11 @@ pub struct PaymentDetails {
3434
pub direction: PaymentDirection,
3535
/// The status of the payment.
3636
pub status: PaymentStatus,
37-
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
38-
///
39-
/// This is only `Some` for payments received via a JIT-channel, in which case the first
40-
/// inbound payment will pay for the LSP's channel opening fees.
41-
///
42-
/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.
43-
///
44-
/// [`LdkChannelConfig::accept_underpaying_htlcs`]: lightning::util::config::ChannelConfig::accept_underpaying_htlcs
45-
pub lsp_fee_limits: Option<LSPFeeLimits>,
4637
}
4738

4839
impl_writeable_tlv_based!(PaymentDetails, {
4940
(0, hash, required),
50-
(1, lsp_fee_limits, option),
41+
// 1 briefly used to be lsp_fee_limits, could probably be reused at some point in the future.
5142
(2, preimage, required),
5243
(3, kind, option),
5344
(4, secret, required),
@@ -97,6 +88,22 @@ pub enum PaymentKind {
9788
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
9889
// TODO: Bolt11 { invoice: Option<Bolt11Invoice> },
9990
Bolt11,
91+
/// A [BOLT 11] payment intended to open an [LSPS 2] just-in-time channel.
92+
///
93+
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
94+
/// [LSPS 2]: https://github.com/BitcoinAndLightningLayerSpecs/lsp/blob/main/LSPS2/README.md
95+
// TODO: Bolt11Jit { invoice: Option<Bolt11Invoice> },
96+
Bolt11Jit {
97+
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
98+
///
99+
/// This is only `Some` for payments received via a JIT-channel, in which case the first
100+
/// inbound payment will pay for the LSP's channel opening fees.
101+
///
102+
/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.
103+
///
104+
/// [`LdkChannelConfig::accept_underpaying_htlcs`]: lightning::util::config::ChannelConfig::accept_underpaying_htlcs
105+
lsp_fee_limits: Option<LSPFeeLimits>,
106+
},
100107
/// A spontaneous ("keysend") payment.
101108
Spontaneous,
102109
}
@@ -106,7 +113,10 @@ impl_writeable_tlv_based_enum!(PaymentKind,
106113
(2, Bolt11) => {
107114
// TODO: (0, invoice, option),
108115
},
109-
(6, Spontaneous) => {};
116+
(4, Bolt11Jit) => {
117+
(1, lsp_fee_limits, option),
118+
},
119+
(8, Spontaneous) => {};
110120
);
111121

112122
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
@@ -137,7 +147,6 @@ pub(crate) struct PaymentDetailsUpdate {
137147
pub amount_msat: Option<Option<u64>>,
138148
pub direction: Option<PaymentDirection>,
139149
pub status: Option<PaymentStatus>,
140-
pub lsp_fee_limits: Option<Option<LSPFeeLimits>>,
141150
}
142151

143152
impl PaymentDetailsUpdate {
@@ -149,7 +158,6 @@ impl PaymentDetailsUpdate {
149158
amount_msat: None,
150159
direction: None,
151160
status: None,
152-
lsp_fee_limits: None,
153161
}
154162
}
155163
}
@@ -230,10 +238,6 @@ where
230238
payment.status = status;
231239
}
232240

233-
if let Some(lsp_fee_limits) = update.lsp_fee_limits {
234-
payment.lsp_fee_limits = lsp_fee_limits
235-
}
236-
237241
self.persist_info(&update.hash, payment)?;
238242
updated = true;
239243
}

src/payment/spontaneous.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ impl SpontaneousPayment {
8484
status: PaymentStatus::Pending,
8585
direction: PaymentDirection::Outbound,
8686
amount_msat: Some(amount_msat),
87-
lsp_fee_limits: None,
8887
};
8988
self.payment_store.insert(payment)?;
9089

@@ -104,7 +103,6 @@ impl SpontaneousPayment {
104103
status: PaymentStatus::Failed,
105104
direction: PaymentDirection::Outbound,
106105
amount_msat: Some(amount_msat),
107-
lsp_fee_limits: None,
108106
};
109107

110108
self.payment_store.insert(payment)?;

src/uniffi_types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
pub use crate::payment::payment_store::{LSPFeeLimits, PaymentDirection, PaymentStatus, PaymentKind};
1+
pub use crate::payment::payment_store::{
2+
LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus,
3+
};
24

35
pub use lightning::events::{ClosureReason, PaymentFailureReason};
46
pub use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};

0 commit comments

Comments
 (0)