Skip to content

Commit ad9bdf4

Browse files
Track the sender's skimmed fee in UpdateAddHTLC
1 parent 5765ddb commit ad9bdf4

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
@@ -3695,6 +3695,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36953695
payment_hash: htlc.payment_hash,
36963696
cltv_expiry: htlc.cltv_expiry,
36973697
onion_routing_packet: (**onion_packet).clone(),
3698+
skimmed_fee_msat: None,
36983699
});
36993700
}
37003701
}
@@ -5145,6 +5146,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
51455146
payment_hash,
51465147
cltv_expiry,
51475148
onion_routing_packet,
5149+
skimmed_fee_msat: None,
51485150
};
51495151
self.context.next_holder_htlc_id += 1;
51505152

lightning/src/ln/functional_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ fn test_fee_spike_violation_fails_htlc() {
13931393
payment_hash: payment_hash,
13941394
cltv_expiry: htlc_cltv,
13951395
onion_routing_packet: onion_packet,
1396+
skimmed_fee_msat: None,
13961397
};
13971398

13981399
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
@@ -1582,6 +1583,7 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
15821583
payment_hash: payment_hash,
15831584
cltv_expiry: htlc_cltv,
15841585
onion_routing_packet: onion_packet,
1586+
skimmed_fee_msat: None,
15851587
};
15861588

15871589
nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &msg);
@@ -1758,6 +1760,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
17581760
payment_hash: our_payment_hash_1,
17591761
cltv_expiry: htlc_cltv,
17601762
onion_routing_packet: onion_packet,
1763+
skimmed_fee_msat: None,
17611764
};
17621765

17631766
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
@@ -3410,6 +3413,7 @@ fn fail_backward_pending_htlc_upon_channel_failure() {
34103413
payment_hash,
34113414
cltv_expiry,
34123415
onion_routing_packet,
3416+
skimmed_fee_msat: None,
34133417
};
34143418
nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_htlc);
34153419
}
@@ -6259,6 +6263,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
62596263
payment_hash: our_payment_hash,
62606264
cltv_expiry: htlc_cltv,
62616265
onion_routing_packet: onion_packet.clone(),
6266+
skimmed_fee_msat: None,
62626267
};
62636268

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