Skip to content

Commit f857e6e

Browse files
committed
Track dummy-hop skimmed fees through receive handling
Propagate dummy-hop skimmed fees through HTLC peeling, channel persistence, and receive-side payment tracking. Expose the accumulated value on `PaymentClaimable` and `PaymentClaimed`. This keeps `amount_msat` focused on the amount delivered to the final receive TLVs, while still surfacing the additional revenue from dummy hops. Receivers can account for these fees without changing the meaning of existing skimmed-fee fields.
1 parent d14446b commit f857e6e

10 files changed

Lines changed: 168 additions & 19 deletions

lightning/src/events/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,12 @@ pub enum Event {
902902
///
903903
/// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
904904
amount_msat: u64,
905+
/// The additional skimmed fee, in thousandths of a satoshi, that the receiver earns from
906+
/// dummy hops preceding the final receipt, in addition to the `amount_msat`.
907+
///
908+
/// For backwards compatibility with older LDK versions where this TLV was not serialized,
909+
/// this defaults to 0 when absent.
910+
dummy_hops_skimmed_fee_msat: u64,
905911
/// The value, in thousands of a satoshi, that was skimmed off of this payment as an extra fee
906912
/// taken by our channel counterparty.
907913
///
@@ -965,6 +971,12 @@ pub enum Event {
965971
/// The value, in thousandths of a satoshi, that this payment is for. May be greater than the
966972
/// invoice amount.
967973
amount_msat: u64,
974+
/// The additional skimmed fee, in thousandths of a satoshi, that the receiver earns from
975+
/// dummy hops preceding the final receipt, in addition to the `amount_msat`.
976+
///
977+
/// For backwards compatibility with older LDK versions where this TLV was not serialized,
978+
/// this defaults to 0 when absent.
979+
dummy_hops_skimmed_fee_msat: u64,
968980
/// The purpose of the claimed payment, i.e. whether the payment was for an invoice or a
969981
/// spontaneous payment.
970982
purpose: PaymentPurpose,
@@ -1891,6 +1903,7 @@ impl Writeable for Event {
18911903
&Event::PaymentClaimable {
18921904
ref payment_hash,
18931905
ref amount_msat,
1906+
dummy_hops_skimmed_fee_msat,
18941907
counterparty_skimmed_fee_msat,
18951908
ref purpose,
18961909
ref receiver_node_id,
@@ -1938,6 +1951,11 @@ impl Writeable for Event {
19381951
} else {
19391952
Some(counterparty_skimmed_fee_msat)
19401953
};
1954+
let dummy_skimmed_fee_opt = if dummy_hops_skimmed_fee_msat == 0 {
1955+
None
1956+
} else {
1957+
Some(dummy_hops_skimmed_fee_msat)
1958+
};
19411959

19421960
let (receiving_channel_id_legacy, receiving_user_channel_id_legacy) =
19431961
match receiving_channel_ids.last() {
@@ -1964,6 +1982,7 @@ impl Writeable for Event {
19641982
(11, payment_context, option),
19651983
(13, payment_id, option),
19661984
(15, *receiving_channel_ids, optional_vec),
1985+
(17, dummy_skimmed_fee_opt, option),
19671986
});
19681987
},
19691988
&Event::PaymentSent {
@@ -2189,6 +2208,7 @@ impl Writeable for Event {
21892208
&Event::PaymentClaimed {
21902209
ref payment_hash,
21912210
ref amount_msat,
2211+
dummy_hops_skimmed_fee_msat,
21922212
ref purpose,
21932213
ref receiver_node_id,
21942214
ref htlcs,
@@ -2197,6 +2217,11 @@ impl Writeable for Event {
21972217
ref payment_id,
21982218
} => {
21992219
19u8.write(writer)?;
2220+
let dummy_skimmed_fee_opt = if dummy_hops_skimmed_fee_msat == 0 {
2221+
None
2222+
} else {
2223+
Some(dummy_hops_skimmed_fee_msat)
2224+
};
22002225
write_tlv_fields!(writer, {
22012226
(0, payment_hash, required),
22022227
(1, receiver_node_id, option),
@@ -2206,6 +2231,7 @@ impl Writeable for Event {
22062231
(7, sender_intended_total_msat, option),
22072232
(9, onion_fields, option),
22082233
(11, payment_id, option),
2234+
(13, dummy_skimmed_fee_opt, option),
22092235
});
22102236
},
22112237
&Event::ProbeSuccessful { ref payment_id, ref payment_hash, ref path } => {
@@ -2407,6 +2433,7 @@ impl MaybeReadable for Event {
24072433
let mut payment_preimage = None;
24082434
let mut payment_secret = None;
24092435
let mut amount_msat = 0;
2436+
let mut dummy_skimmed_fee_msat_opt = None;
24102437
let mut counterparty_skimmed_fee_msat_opt = None;
24112438
let mut receiver_node_id = None;
24122439
let mut _user_payment_id = None::<u64>; // Used in 0.0.103 and earlier, no longer written in 0.0.116+.
@@ -2432,6 +2459,7 @@ impl MaybeReadable for Event {
24322459
(11, payment_context, option),
24332460
(13, payment_id, option),
24342461
(15, receiving_channel_ids_opt, optional_vec),
2462+
(17, dummy_skimmed_fee_msat_opt, option),
24352463
});
24362464
let purpose = match payment_secret {
24372465
Some(secret) => {
@@ -2455,6 +2483,7 @@ impl MaybeReadable for Event {
24552483
receiver_node_id,
24562484
payment_hash,
24572485
amount_msat,
2486+
dummy_hops_skimmed_fee_msat: dummy_skimmed_fee_msat_opt.unwrap_or(0),
24582487
counterparty_skimmed_fee_msat: counterparty_skimmed_fee_msat_opt
24592488
.unwrap_or(0),
24602489
purpose,
@@ -2760,6 +2789,7 @@ impl MaybeReadable for Event {
27602789
let mut payment_hash = PaymentHash([0; 32]);
27612790
let mut purpose = UpgradableRequired(None);
27622791
let mut amount_msat = 0;
2792+
let mut dummy_hops_skimmed_fee_msat_opt = None;
27632793
let mut receiver_node_id = None;
27642794
let mut htlcs: Option<Vec<ClaimedHTLC>> = Some(vec![]);
27652795
let mut sender_intended_total_msat: Option<u64> = None;
@@ -2775,12 +2805,14 @@ impl MaybeReadable for Event {
27752805
(9, onion_fields, (option: ReadableArgs,
27762806
sender_intended_total_msat.unwrap_or(amount_msat))),
27772807
(11, payment_id, option),
2808+
(13, dummy_hops_skimmed_fee_msat_opt, option),
27782809
});
27792810
Ok(Some(Event::PaymentClaimed {
27802811
receiver_node_id,
27812812
payment_hash,
27822813
purpose: _init_tlv_based_struct_field!(purpose, upgradable_required),
27832814
amount_msat,
2815+
dummy_hops_skimmed_fee_msat: dummy_hops_skimmed_fee_msat_opt.unwrap_or(0),
27842816
htlcs: htlcs.unwrap_or_default(),
27852817
sender_intended_total_msat,
27862818
onion_fields,

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,7 @@ fn update_add_msg(
15861586
cltv_expiry,
15871587
payment_hash: PaymentHash([0; 32]),
15881588
onion_routing_packet,
1589+
dummy_hops_skimmed_fee_msat: None,
15891590
skimmed_fee_msat: None,
15901591
blinding_point,
15911592
hold_htlc: None,

0 commit comments

Comments
 (0)