Skip to content

Commit 2ecff45

Browse files
Persist counterparty skimmed fee in ClaimableHTLC
Used to get an accurate skimmed fee in the resulting PaymentClaimable event.
1 parent 684afcc commit 2ecff45

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.
@@ -3772,7 +3774,8 @@ where
37723774
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
37733775
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
37743776
forward_info: PendingHTLCInfo {
3775-
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat, ..
3777+
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat,
3778+
skimmed_fee_msat, ..
37763779
}
37773780
}) => {
37783781
let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret, mut onion_fields) = match routing {
@@ -3813,6 +3816,7 @@ where
38133816
total_msat: if let Some(data) = &payment_data { data.total_msat } else { outgoing_amt_msat },
38143817
cltv_expiry,
38153818
onion_payload,
3819+
counterparty_skimmed_fee_msat: skimmed_fee_msat,
38163820
};
38173821

38183822
let mut committed_to_claimable = false;
@@ -7548,31 +7552,27 @@ impl Writeable for ClaimableHTLC {
75487552
(5, self.total_value_received, option),
75497553
(6, self.cltv_expiry, required),
75507554
(8, keysend_preimage, option),
7555+
(10, self.counterparty_skimmed_fee_msat, option),
75517556
});
75527557
Ok(())
75537558
}
75547559
}
75557560

75567561
impl Readable for ClaimableHTLC {
75577562
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
7558-
let mut prev_hop = crate::util::ser::RequiredWrapper(None);
7559-
let mut value = 0;
7560-
let mut sender_intended_value = None;
7561-
let mut payment_data: Option<msgs::FinalOnionHopData> = None;
7562-
let mut cltv_expiry = 0;
7563-
let mut total_value_received = None;
7564-
let mut total_msat = None;
7565-
let mut keysend_preimage: Option<PaymentPreimage> = None;
7566-
read_tlv_fields!(reader, {
7563+
_init_and_read_tlv_fields!(reader, {
75677564
(0, prev_hop, required),
75687565
(1, total_msat, option),
7569-
(2, value, required),
7566+
(2, value_ser, required),
75707567
(3, sender_intended_value, option),
7571-
(4, payment_data, option),
7568+
(4, payment_data_opt, option),
75727569
(5, total_value_received, option),
75737570
(6, cltv_expiry, required),
7574-
(8, keysend_preimage, option)
7571+
(8, keysend_preimage, option),
7572+
(10, counterparty_skimmed_fee_msat, option),
75757573
});
7574+
let payment_data: Option<msgs::FinalOnionHopData> = payment_data_opt;
7575+
let value = value_ser.0.unwrap();
75767576
let onion_payload = match keysend_preimage {
75777577
Some(p) => {
75787578
if payment_data.is_some() {
@@ -7601,7 +7601,8 @@ impl Readable for ClaimableHTLC {
76017601
total_value_received,
76027602
total_msat: total_msat.unwrap(),
76037603
onion_payload,
7604-
cltv_expiry,
7604+
cltv_expiry: cltv_expiry.0.unwrap(),
7605+
counterparty_skimmed_fee_msat,
76057606
})
76067607
}
76077608
}

0 commit comments

Comments
 (0)