Skip to content

Commit 37fc3d7

Browse files
Track the sender's skimmed fee in UpdateAddHTLC
1 parent 5fbc8e0 commit 37fc3d7

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
@@ -4166,6 +4166,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
41664166
payment_hash: htlc.payment_hash,
41674167
cltv_expiry: htlc.cltv_expiry,
41684168
onion_routing_packet: (**onion_packet).clone(),
4169+
skimmed_fee_msat: None,
41694170
});
41704171
}
41714172
}
@@ -6082,6 +6083,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60826083
payment_hash,
60836084
cltv_expiry,
60846085
onion_routing_packet,
6086+
skimmed_fee_msat: None,
60856087
};
60866088
self.next_holder_htlc_id += 1;
60876089

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);
@@ -1576,6 +1577,7 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
15761577
payment_hash: payment_hash,
15771578
cltv_expiry: htlc_cltv,
15781579
onion_routing_packet: onion_packet,
1580+
skimmed_fee_msat: None,
15791581
};
15801582

15811583
nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &msg);
@@ -1752,6 +1754,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
17521754
payment_hash: our_payment_hash_1,
17531755
cltv_expiry: htlc_cltv,
17541756
onion_routing_packet: onion_packet,
1757+
skimmed_fee_msat: None,
17551758
};
17561759

17571760
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
@@ -3404,6 +3407,7 @@ fn fail_backward_pending_htlc_upon_channel_failure() {
34043407
payment_hash,
34053408
cltv_expiry,
34063409
onion_routing_packet,
3410+
skimmed_fee_msat: None,
34073411
};
34083412
nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_htlc);
34093413
}
@@ -6253,6 +6257,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
62536257
payment_hash: our_payment_hash,
62546258
cltv_expiry: htlc_cltv,
62556259
onion_routing_packet: onion_packet.clone(),
6260+
skimmed_fee_msat: None,
62566261
};
62576262

62586263
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)