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