Skip to content

Commit 9485304

Browse files
Persist counterparty skimmed fee in ClaimableHTLC
Used to get an accurate skimmed fee in the resulting PaymentClaimable event.
1 parent 52f2901 commit 9485304

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.
@@ -3782,7 +3784,8 @@ where
37823784
HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
37833785
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id,
37843786
forward_info: PendingHTLCInfo {
3785-
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat, ..
3787+
routing, incoming_shared_secret, payment_hash, incoming_amt_msat, outgoing_amt_msat,
3788+
skimmed_fee_msat, ..
37863789
}
37873790
}) => {
37883791
let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret, mut onion_fields) = match routing {
@@ -3823,6 +3826,7 @@ where
38233826
total_msat: if let Some(data) = &payment_data { data.total_msat } else { outgoing_amt_msat },
38243827
cltv_expiry,
38253828
onion_payload,
3829+
counterparty_skimmed_fee_msat: skimmed_fee_msat,
38263830
};
38273831

38283832
let mut committed_to_claimable = false;
@@ -7558,31 +7562,27 @@ impl Writeable for ClaimableHTLC {
75587562
(5, self.total_value_received, option),
75597563
(6, self.cltv_expiry, required),
75607564
(8, keysend_preimage, option),
7565+
(10, self.counterparty_skimmed_fee_msat, option),
75617566
});
75627567
Ok(())
75637568
}
75647569
}
75657570

75667571
impl Readable for ClaimableHTLC {
75677572
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
7568-
let mut prev_hop = crate::util::ser::RequiredWrapper(None);
7569-
let mut value = 0;
7570-
let mut sender_intended_value = None;
7571-
let mut payment_data: Option<msgs::FinalOnionHopData> = None;
7572-
let mut cltv_expiry = 0;
7573-
let mut total_value_received = None;
7574-
let mut total_msat = None;
7575-
let mut keysend_preimage: Option<PaymentPreimage> = None;
7576-
read_tlv_fields!(reader, {
7573+
_init_and_read_tlv_fields!(reader, {
75777574
(0, prev_hop, required),
75787575
(1, total_msat, option),
7579-
(2, value, required),
7576+
(2, value_ser, required),
75807577
(3, sender_intended_value, option),
7581-
(4, payment_data, option),
7578+
(4, payment_data_opt, option),
75827579
(5, total_value_received, option),
75837580
(6, cltv_expiry, required),
7584-
(8, keysend_preimage, option)
7581+
(8, keysend_preimage, option),
7582+
(10, counterparty_skimmed_fee_msat, option),
75857583
});
7584+
let payment_data: Option<msgs::FinalOnionHopData> = payment_data_opt;
7585+
let value = value_ser.0.unwrap();
75867586
let onion_payload = match keysend_preimage {
75877587
Some(p) => {
75887588
if payment_data.is_some() {
@@ -7611,7 +7611,8 @@ impl Readable for ClaimableHTLC {
76117611
total_value_received,
76127612
total_msat: total_msat.unwrap(),
76137613
onion_payload,
7614-
cltv_expiry,
7614+
cltv_expiry: cltv_expiry.0.unwrap(),
7615+
counterparty_skimmed_fee_msat,
76157616
})
76167617
}
76177618
}

0 commit comments

Comments
 (0)