Merge pull request #2715 from valentinewallace/2023-11-skimmed-fees
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Sun, 12 Nov 2023 20:27:25 +0000 (20:27 +0000)
committerGitHub <noreply@github.com>
Sun, 12 Nov 2023 20:27:25 +0000 (20:27 +0000)
Complete underpaying HTLCs support

lightning/src/events/mod.rs
lightning/src/ln/channelmanager.rs
lightning/src/util/config.rs

index 32192297432d1873c6898e79ccf41f8b66ada62a..5ffea4ee6485399f070b65f3e3798775c58a0693 100644 (file)
@@ -102,9 +102,15 @@ pub struct ClaimedHTLC {
        pub cltv_expiry: u32,
        /// The amount (in msats) of this part of an MPP.
        pub value_msat: u64,
+       /// The extra fee our counterparty skimmed off the top of this HTLC, if any.
+       ///
+       /// This value will always be 0 for [`ClaimedHTLC`]s serialized with LDK versions prior to
+       /// 0.0.119.
+       pub counterparty_skimmed_fee_msat: u64,
 }
 impl_writeable_tlv_based!(ClaimedHTLC, {
        (0, channel_id, required),
+       (1, counterparty_skimmed_fee_msat, (default_value, 0u64)),
        (2, user_channel_id, required),
        (4, cltv_expiry, required),
        (6, value_msat, required),
index 76b7492fdcb45fb3d5a3e6e1ecd2ba52b6006eba..ce79f25400a53645b8fccf2f71ddb7ca48f46e64 100644 (file)
@@ -238,6 +238,7 @@ impl From<&ClaimableHTLC> for events::ClaimedHTLC {
                        user_channel_id: val.prev_hop.user_channel_id.unwrap_or(0),
                        cltv_expiry: val.cltv_expiry,
                        value_msat: val.value,
+                       counterparty_skimmed_fee_msat: val.counterparty_skimmed_fee_msat.unwrap_or(0),
                }
        }
 }
index ef4111e4f82f744385fa345c610f5249b10b2d1a..13284113d2ca03469166bf959ba6607d66aaef4c 100644 (file)
@@ -462,8 +462,9 @@ pub struct ChannelConfig {
        /// - The counterparty will get an [`HTLCIntercepted`] event upon payment forward, and call
        ///   [`forward_intercepted_htlc`] with less than the amount provided in
        ///   [`HTLCIntercepted::expected_outbound_amount_msat`]. The difference between the expected and
-       ///   actual forward amounts is their fee.
-       // TODO: link to LSP JIT channel invoice generation spec when it's merged
+       ///   actual forward amounts is their fee. See
+       ///   <https://github.com/BitcoinAndLightningLayerSpecs/lsp/tree/main/LSPS2#flow-lsp-trusts-client-model>
+       ///   for how this feature may be used in the LSP use case.
        ///
        /// # Note
        /// It's important for payee wallet software to verify that [`PaymentClaimable::amount_msat`] is