Skip to content

Commit 7bb7683

Browse files
Persist counterparty skimmed fee in ClaimableHTLC
Used to get an accurate skimmed fee in the resulting PaymentClaimable event.
1 parent 15854a4 commit 7bb7683

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.
@@ -3777,7 +3779,8 @@ where
37773779
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
37783780
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
37793781
forward_info: PendingHTLCInfo {
3780-
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat, ..
3782+
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat,
3783+
skimmed_fee_msat, ..
37813784
}
37823785
}) => {
37833786
let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret, mut onion_fields) = match routing {
@@ -3818,6 +3821,7 @@ where
38183821
total_msat: if let Some(data) = &payment_data { data.total_msat } else { outgoing_amt_msat },
38193822
cltv_expiry,
38203823
onion_payload,
3824+
counterparty_skimmed_fee_msat: skimmed_fee_msat,
38213825
};
38223826

38233827
let mut committed_to_claimable = false;
@@ -7553,31 +7557,27 @@ impl Writeable for ClaimableHTLC {
75537557
(5, self.total_value_received, option),
75547558
(6, self.cltv_expiry, required),
75557559
(8, keysend_preimage, option),
7560+
(10, self.counterparty_skimmed_fee_msat, option),
75567561
});
75577562
Ok(())
75587563
}
75597564
}
75607565

75617566
impl Readable for ClaimableHTLC {
75627567
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
7563-
let mut prev_hop = crate::util::ser::RequiredWrapper(None);
7564-
let mut value = 0;
7565-
let mut sender_intended_value = None;
7566-
let mut payment_data: Option<msgs::FinalOnionHopData> = None;
7567-
let mut cltv_expiry = 0;
7568-
let mut total_value_received = None;
7569-
let mut total_msat = None;
7570-
let mut keysend_preimage: Option<PaymentPreimage> = None;
7571-
read_tlv_fields!(reader, {
7568+
_init_and_read_tlv_fields!(reader, {
75727569
(0, prev_hop, required),
75737570
(1, total_msat, option),
7574-
(2, value, required),
7571+
(2, value_ser, required),
75757572
(3, sender_intended_value, option),
7576-
(4, payment_data, option),
7573+
(4, payment_data_opt, option),
75777574
(5, total_value_received, option),
75787575
(6, cltv_expiry, required),
7579-
(8, keysend_preimage, option)
7576+
(8, keysend_preimage, option),
7577+
(10, counterparty_skimmed_fee_msat, option),
75807578
});
7579+
let payment_data: Option<msgs::FinalOnionHopData> = payment_data_opt;
7580+
let value = value_ser.0.unwrap();
75817581
let onion_payload = match keysend_preimage {
75827582
Some(p) => {
75837583
if payment_data.is_some() {
@@ -7606,7 +7606,8 @@ impl Readable for ClaimableHTLC {
76067606
total_value_received,
76077607
total_msat: total_msat.unwrap(),
76087608
onion_payload,
7609-
cltv_expiry,
7609+
cltv_expiry: cltv_expiry.0.unwrap(),
7610+
counterparty_skimmed_fee_msat,
76107611
})
76117612
}
76127613
}

0 commit comments

Comments
 (0)