@@ -41,6 +41,8 @@ pub struct PaymentDetails {
41
41
/// The kind of the payment.
42
42
pub kind : PaymentKind ,
43
43
/// The amount transferred.
44
+ ///
45
+ /// Will be `None` for variable-amount payments until we receive them.
44
46
pub amount_msat : Option < u64 > ,
45
47
/// The fees that were paid for this payment.
46
48
///
@@ -165,6 +167,18 @@ impl PaymentDetails {
165
167
update_if_necessary ! ( self . fee_paid_msat, fee_paid_msat_opt) ;
166
168
}
167
169
170
+ if let Some ( skimmed_fee_msat) = update. counterparty_skimmed_fee_msat {
171
+ match self . kind {
172
+ PaymentKind :: Bolt11Jit { ref mut counterparty_skimmed_fee_msat, .. } => {
173
+ update_if_necessary ! ( * counterparty_skimmed_fee_msat, skimmed_fee_msat) ;
174
+ } ,
175
+ _ => debug_assert ! (
176
+ false ,
177
+ "We should only ever override counterparty_skimmed_fee_msat for JIT payments"
178
+ ) ,
179
+ }
180
+ }
181
+
168
182
if let Some ( status) = update. status {
169
183
update_if_necessary ! ( self . status, status) ;
170
184
}
@@ -257,7 +271,14 @@ impl Readable for PaymentDetails {
257
271
258
272
if secret. is_some ( ) {
259
273
if let Some ( lsp_fee_limits) = lsp_fee_limits {
260
- PaymentKind :: Bolt11Jit { hash, preimage, secret, lsp_fee_limits }
274
+ let counterparty_skimmed_fee_msat = None ;
275
+ PaymentKind :: Bolt11Jit {
276
+ hash,
277
+ preimage,
278
+ secret,
279
+ counterparty_skimmed_fee_msat,
280
+ lsp_fee_limits,
281
+ }
261
282
} else {
262
283
PaymentKind :: Bolt11 { hash, preimage, secret }
263
284
}
@@ -346,6 +367,12 @@ pub enum PaymentKind {
346
367
preimage : Option < PaymentPreimage > ,
347
368
/// The secret used by the payment.
348
369
secret : Option < PaymentSecret > ,
370
+ /// The value, in thousands of a satoshi, that was deducted from this payment as an extra
371
+ /// fee taken by our channel counterparty.
372
+ ///
373
+ /// Will only be `Some` once we received the payment. Will always be `None` for LDK Node
374
+ /// v0.4 and prior.
375
+ counterparty_skimmed_fee_msat : Option < u64 > ,
349
376
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
350
377
///
351
378
/// Allowing them to deduct this fee from the first inbound payment will pay for the LSP's
@@ -423,6 +450,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
423
450
} ,
424
451
( 4 , Bolt11Jit ) => {
425
452
( 0 , hash, required) ,
453
+ ( 1 , counterparty_skimmed_fee_msat, option) ,
426
454
( 2 , preimage, option) ,
427
455
( 4 , secret, option) ,
428
456
( 6 , lsp_fee_limits, required) ,
@@ -501,6 +529,7 @@ pub(crate) struct PaymentDetailsUpdate {
501
529
pub secret : Option < Option < PaymentSecret > > ,
502
530
pub amount_msat : Option < Option < u64 > > ,
503
531
pub fee_paid_msat : Option < Option < u64 > > ,
532
+ pub counterparty_skimmed_fee_msat : Option < Option < u64 > > ,
504
533
pub direction : Option < PaymentDirection > ,
505
534
pub status : Option < PaymentStatus > ,
506
535
pub confirmation_status : Option < ConfirmationStatus > ,
@@ -515,6 +544,7 @@ impl PaymentDetailsUpdate {
515
544
secret : None ,
516
545
amount_msat : None ,
517
546
fee_paid_msat : None ,
547
+ counterparty_skimmed_fee_msat : None ,
518
548
direction : None ,
519
549
status : None ,
520
550
confirmation_status : None ,
@@ -538,13 +568,21 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
538
568
_ => None ,
539
569
} ;
540
570
571
+ let counterparty_skimmed_fee_msat = match value. kind {
572
+ PaymentKind :: Bolt11Jit { counterparty_skimmed_fee_msat, .. } => {
573
+ Some ( counterparty_skimmed_fee_msat)
574
+ } ,
575
+ _ => None ,
576
+ } ;
577
+
541
578
Self {
542
579
id : value. id ,
543
580
hash : Some ( hash) ,
544
581
preimage : Some ( preimage) ,
545
582
secret : Some ( secret) ,
546
583
amount_msat : Some ( value. amount_msat ) ,
547
584
fee_paid_msat : Some ( value. fee_paid_msat ) ,
585
+ counterparty_skimmed_fee_msat,
548
586
direction : Some ( value. direction ) ,
549
587
status : Some ( value. status ) ,
550
588
confirmation_status,
@@ -841,10 +879,17 @@ mod tests {
841
879
) ;
842
880
843
881
match bolt11_jit_decoded. kind {
844
- PaymentKind :: Bolt11Jit { hash : h, preimage : p, secret : s, lsp_fee_limits : l } => {
882
+ PaymentKind :: Bolt11Jit {
883
+ hash : h,
884
+ preimage : p,
885
+ secret : s,
886
+ counterparty_skimmed_fee_msat : c,
887
+ lsp_fee_limits : l,
888
+ } => {
845
889
assert_eq ! ( hash, h) ;
846
890
assert_eq ! ( preimage, p) ;
847
891
assert_eq ! ( secret, s) ;
892
+ assert_eq ! ( None , c) ;
848
893
assert_eq ! ( lsp_fee_limits, Some ( l) ) ;
849
894
} ,
850
895
_ => {
0 commit comments