@@ -41,6 +41,8 @@ pub struct PaymentDetails {
4141 /// The kind of the payment.
4242 pub kind : PaymentKind ,
4343 /// The amount transferred.
44+ ///
45+ /// Will be `None` for variable-amount payments until we receive them.
4446 pub amount_msat : Option < u64 > ,
4547 /// The fees that were paid for this payment.
4648 ///
@@ -165,6 +167,18 @@ impl PaymentDetails {
165167 update_if_necessary ! ( self . fee_paid_msat, fee_paid_msat_opt) ;
166168 }
167169
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+
168182 if let Some ( status) = update. status {
169183 update_if_necessary ! ( self . status, status) ;
170184 }
@@ -257,7 +271,14 @@ impl Readable for PaymentDetails {
257271
258272 if secret. is_some ( ) {
259273 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+ }
261282 } else {
262283 PaymentKind :: Bolt11 { hash, preimage, secret }
263284 }
@@ -346,6 +367,12 @@ pub enum PaymentKind {
346367 preimage : Option < PaymentPreimage > ,
347368 /// The secret used by the payment.
348369 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 > ,
349376 /// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
350377 ///
351378 /// 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,
423450 } ,
424451 ( 4 , Bolt11Jit ) => {
425452 ( 0 , hash, required) ,
453+ ( 1 , counterparty_skimmed_fee_msat, option) ,
426454 ( 2 , preimage, option) ,
427455 ( 4 , secret, option) ,
428456 ( 6 , lsp_fee_limits, required) ,
@@ -501,6 +529,7 @@ pub(crate) struct PaymentDetailsUpdate {
501529 pub secret : Option < Option < PaymentSecret > > ,
502530 pub amount_msat : Option < Option < u64 > > ,
503531 pub fee_paid_msat : Option < Option < u64 > > ,
532+ pub counterparty_skimmed_fee_msat : Option < Option < u64 > > ,
504533 pub direction : Option < PaymentDirection > ,
505534 pub status : Option < PaymentStatus > ,
506535 pub confirmation_status : Option < ConfirmationStatus > ,
@@ -515,6 +544,7 @@ impl PaymentDetailsUpdate {
515544 secret : None ,
516545 amount_msat : None ,
517546 fee_paid_msat : None ,
547+ counterparty_skimmed_fee_msat : None ,
518548 direction : None ,
519549 status : None ,
520550 confirmation_status : None ,
@@ -538,13 +568,21 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
538568 _ => None ,
539569 } ;
540570
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+
541578 Self {
542579 id : value. id ,
543580 hash : Some ( hash) ,
544581 preimage : Some ( preimage) ,
545582 secret : Some ( secret) ,
546583 amount_msat : Some ( value. amount_msat ) ,
547584 fee_paid_msat : Some ( value. fee_paid_msat ) ,
585+ counterparty_skimmed_fee_msat,
548586 direction : Some ( value. direction ) ,
549587 status : Some ( value. status ) ,
550588 confirmation_status,
@@ -841,10 +879,17 @@ mod tests {
841879 ) ;
842880
843881 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+ } => {
845889 assert_eq ! ( hash, h) ;
846890 assert_eq ! ( preimage, p) ;
847891 assert_eq ! ( secret, s) ;
892+ assert_eq ! ( None , c) ;
848893 assert_eq ! ( lsp_fee_limits, Some ( l) ) ;
849894 } ,
850895 _ => {
0 commit comments