Skip to content

Commit 4263c86

Browse files
Persist counterparty skimmed fee in ClaimableHTLC
Used to get an accurate skimmed fee in the resulting PaymentClaimable event.
1 parent 05b69a0 commit 4263c86

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ struct ClaimableHTLC {
213213
total_value_received: Option<u64>,
214214
/// The sender intended sum total of all MPP parts specified in the onion
215215
total_msat: u64,
216+
/// The extra fee our counterparty skimmed off the top of this HTLC.
217+
counterparty_skimmed_fee_msat: Option<u64>,
216218
}
217219

218220
/// A payment identifier used to uniquely identify a payment to LDK.
@@ -3776,7 +3778,8 @@ where
37763778
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
37773779
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
37783780
forward_info: PendingHTLCInfo {
3779-
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat, ..
3781+
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat,
3782+
skimmed_fee_msat, ..
37803783
}
37813784
}) => {
37823785
let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret, mut onion_fields) = match routing {
@@ -3817,6 +3820,7 @@ where
38173820
total_msat: if let Some(data) = &payment_data { data.total_msat } else { outgoing_amt_msat },
38183821
cltv_expiry,
38193822
onion_payload,
3823+
counterparty_skimmed_fee_msat: skimmed_fee_msat,
38203824
};
38213825

38223826
let mut committed_to_claimable = false;
@@ -7615,31 +7619,27 @@ impl Writeable for ClaimableHTLC {
76157619
(5, self.total_value_received, option),
76167620
(6, self.cltv_expiry, required),
76177621
(8, keysend_preimage, option),
7622+
(10, self.counterparty_skimmed_fee_msat, option),
76187623
});
76197624
Ok(())
76207625
}
76217626
}
76227627

76237628
impl Readable for ClaimableHTLC {
76247629
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
7625-
let mut prev_hop = crate::util::ser::RequiredWrapper(None);
7626-
let mut value = 0;
7627-
let mut sender_intended_value = None;
7628-
let mut payment_data: Option<msgs::FinalOnionHopData> = None;
7629-
let mut cltv_expiry = 0;
7630-
let mut total_value_received = None;
7631-
let mut total_msat = None;
7632-
let mut keysend_preimage: Option<PaymentPreimage> = None;
7633-
read_tlv_fields!(reader, {
7630+
_init_and_read_tlv_fields!(reader, {
76347631
(0, prev_hop, required),
76357632
(1, total_msat, option),
7636-
(2, value, required),
7633+
(2, value_ser, required),
76377634
(3, sender_intended_value, option),
7638-
(4, payment_data, option),
7635+
(4, payment_data_opt, option),
76397636
(5, total_value_received, option),
76407637
(6, cltv_expiry, required),
7641-
(8, keysend_preimage, option)
7638+
(8, keysend_preimage, option),
7639+
(10, counterparty_skimmed_fee_msat, option),
76427640
});
7641+
let payment_data: Option<msgs::FinalOnionHopData> = payment_data_opt;
7642+
let value = value_ser.0.unwrap();
76437643
let onion_payload = match keysend_preimage {
76447644
Some(p) => {
76457645
if payment_data.is_some() {
@@ -7668,7 +7668,8 @@ impl Readable for ClaimableHTLC {
76687668
total_value_received,
76697669
total_msat: total_msat.unwrap(),
76707670
onion_payload,
7671-
cltv_expiry,
7671+
cltv_expiry: cltv_expiry.0.unwrap(),
7672+
counterparty_skimmed_fee_msat,
76727673
})
76737674
}
76747675
}

0 commit comments

Comments
 (0)