Skip to content

Commit c72d7af

Browse files
Track the sender's skimmed fee in UpdateAddHTLC
1 parent 3a7f6cb commit c72d7af

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,6 +4019,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
40194019
payment_hash: htlc.payment_hash,
40204020
cltv_expiry: htlc.cltv_expiry,
40214021
onion_routing_packet: (**onion_packet).clone(),
4022+
skimmed_fee_msat: None,
40224023
});
40234024
}
40244025
}
@@ -5947,6 +5948,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
59475948
payment_hash,
59485949
cltv_expiry,
59495950
onion_routing_packet,
5951+
skimmed_fee_msat: None,
59505952
};
59515953
self.next_holder_htlc_id += 1;
59525954

lightning/src/ln/functional_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,7 @@ fn test_fee_spike_violation_fails_htlc() {
13871387
payment_hash: payment_hash,
13881388
cltv_expiry: htlc_cltv,
13891389
onion_routing_packet: onion_packet,
1390+
skimmed_fee_msat: None,
13901391
};
13911392

13921393
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
@@ -1575,6 +1576,7 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
15751576
payment_hash: payment_hash,
15761577
cltv_expiry: htlc_cltv,
15771578
onion_routing_packet: onion_packet,
1579+
skimmed_fee_msat: None,
15781580
};
15791581

15801582
nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &msg);
@@ -1749,6 +1751,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
17491751
payment_hash: our_payment_hash_1,
17501752
cltv_expiry: htlc_cltv,
17511753
onion_routing_packet: onion_packet,
1754+
skimmed_fee_msat: None,
17521755
};
17531756

17541757
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
@@ -3402,6 +3405,7 @@ fn fail_backward_pending_htlc_upon_channel_failure() {
34023405
payment_hash,
34033406
cltv_expiry,
34043407
onion_routing_packet,
3408+
skimmed_fee_msat: None,
34053409
};
34063410
nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_htlc);
34073411
}
@@ -6258,6 +6262,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
62586262
payment_hash: our_payment_hash,
62596263
cltv_expiry: htlc_cltv,
62606264
onion_routing_packet: onion_packet.clone(),
6265+
skimmed_fee_msat: None,
62616266
};
62626267

62636268
for i in 0..50 {

lightning/src/ln/msgs.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@ pub struct UpdateAddHTLC {
605605
pub payment_hash: PaymentHash,
606606
/// The expiry height of the HTLC
607607
pub cltv_expiry: u32,
608+
/// The extra fee skimmed by the sender of this message. See
609+
/// [`ChannelConfig::accept_underpaying_htlcs`].
610+
///
611+
/// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
612+
pub skimmed_fee_msat: Option<u64>,
608613
pub(crate) onion_routing_packet: OnionPacket,
609614
}
610615

@@ -1883,8 +1888,10 @@ impl_writeable_msg!(UpdateAddHTLC, {
18831888
amount_msat,
18841889
payment_hash,
18851890
cltv_expiry,
1886-
onion_routing_packet
1887-
}, {});
1891+
onion_routing_packet,
1892+
}, {
1893+
(65537, skimmed_fee_msat, option)
1894+
});
18881895

18891896
impl Readable for OnionMessage {
18901897
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
@@ -3309,7 +3316,8 @@ mod tests {
33093316
amount_msat: 3608586615801332854,
33103317
payment_hash: PaymentHash([1; 32]),
33113318
cltv_expiry: 821716,
3312-
onion_routing_packet
3319+
onion_routing_packet,
3320+
skimmed_fee_msat: None,
33133321
};
33143322
let encoded_value = update_add_htlc.encode();
33153323
let target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020200083a840000034d32144668701144760101010101010101010101010101010101010101010101010101010101010101000c89d4ff031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap();

0 commit comments

Comments
 (0)