Skip to content

Commit 73513f1

Browse files
Track the sender's skimmed fee in UpdateAddHTLC
1 parent b885dea commit 73513f1

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
@@ -4051,6 +4051,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
40514051
payment_hash: htlc.payment_hash,
40524052
cltv_expiry: htlc.cltv_expiry,
40534053
onion_routing_packet: (**onion_packet).clone(),
4054+
skimmed_fee_msat: None,
40544055
});
40554056
}
40564057
}
@@ -6022,6 +6023,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60226023
payment_hash,
60236024
cltv_expiry,
60246025
onion_routing_packet,
6026+
skimmed_fee_msat: None,
60256027
};
60266028
self.next_holder_htlc_id += 1;
60276029

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
}
@@ -6262,6 +6266,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
62626266
payment_hash: our_payment_hash,
62636267
cltv_expiry: htlc_cltv,
62646268
onion_routing_packet: onion_packet.clone(),
6269+
skimmed_fee_msat: None,
62656270
};
62666271

62676272
for i in 0..50 {

lightning/src/ln/msgs.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ pub struct UpdateAddHTLC {
610610
pub payment_hash: PaymentHash,
611611
/// The expiry height of the HTLC
612612
pub cltv_expiry: u32,
613+
/// The extra fee skimmed by the sender of this message. See
614+
/// [`ChannelConfig::accept_underpaying_htlcs`].
615+
///
616+
/// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
617+
pub skimmed_fee_msat: Option<u64>,
613618
pub(crate) onion_routing_packet: OnionPacket,
614619
}
615620

@@ -1903,8 +1908,10 @@ impl_writeable_msg!(UpdateAddHTLC, {
19031908
amount_msat,
19041909
payment_hash,
19051910
cltv_expiry,
1906-
onion_routing_packet
1907-
}, {});
1911+
onion_routing_packet,
1912+
}, {
1913+
(65537, skimmed_fee_msat, option)
1914+
});
19081915

19091916
impl Readable for OnionMessage {
19101917
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
@@ -3330,7 +3337,8 @@ mod tests {
33303337
amount_msat: 3608586615801332854,
33313338
payment_hash: PaymentHash([1; 32]),
33323339
cltv_expiry: 821716,
3333-
onion_routing_packet
3340+
onion_routing_packet,
3341+
skimmed_fee_msat: None,
33343342
};
33353343
let encoded_value = update_add_htlc.encode();
33363344
let target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020200083a840000034d32144668701144760101010101010101010101010101010101010101010101010101010101010101000c89d4ff031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap();

0 commit comments

Comments
 (0)