Skip to content

Commit 593a65b

Browse files
Set UpdateAddHTLC::skimmed_fee_msat on forward
So the receiver can verify it and approve underpaying HTLCs (see ChannelConfig::accept_underpaying_htlcs).
1 parent a13f456 commit 593a65b

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

lightning/src/ln/channel.rs

+28-15
Original file line numberDiff line numberDiff line change
@@ -3411,8 +3411,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
34113411
// handling this case better and maybe fulfilling some of the HTLCs while attempting
34123412
// to rebalance channels.
34133413
match &htlc_update {
3414-
&HTLCUpdateAwaitingACK::AddHTLC {amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, ..} => {
3415-
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(), onion_routing_packet.clone(), false, logger) {
3414+
&HTLCUpdateAwaitingACK::AddHTLC {
3415+
amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
3416+
skimmed_fee_msat, ..
3417+
} => {
3418+
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(),
3419+
onion_routing_packet.clone(), false, skimmed_fee_msat, logger)
3420+
{
34163421
Ok(update_add_msg_option) => update_add_htlcs.push(update_add_msg_option.unwrap()),
34173422
Err(e) => {
34183423
match e {
@@ -4054,7 +4059,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
40544059
payment_hash: htlc.payment_hash,
40554060
cltv_expiry: htlc.cltv_expiry,
40564061
onion_routing_packet: (**onion_packet).clone(),
4057-
skimmed_fee_msat: None,
4062+
skimmed_fee_msat: htlc.skimmed_fee_msat,
40584063
});
40594064
}
40604065
}
@@ -5868,11 +5873,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
58685873
/// commitment update.
58695874
///
58705875
/// `Err`s will only be [`ChannelError::Ignore`].
5871-
pub fn queue_add_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5872-
onion_routing_packet: msgs::OnionPacket, logger: &L)
5873-
-> Result<(), ChannelError> where L::Target: Logger {
5876+
pub fn queue_add_htlc<L: Deref>(
5877+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5878+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
5879+
) -> Result<(), ChannelError> where L::Target: Logger {
58745880
self
5875-
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true, logger)
5881+
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
5882+
skimmed_fee_msat, logger)
58765883
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
58775884
.map_err(|err| {
58785885
if let ChannelError::Ignore(_) = err { /* fine */ }
@@ -5897,9 +5904,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
58975904
/// on this [`Channel`] if `force_holding_cell` is false.
58985905
///
58995906
/// `Err`s will only be [`ChannelError::Ignore`].
5900-
fn send_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5901-
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool, logger: &L)
5902-
-> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
5907+
fn send_htlc<L: Deref>(
5908+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5909+
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
5910+
skimmed_fee_msat: Option<u64>, logger: &L
5911+
) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
59035912
if (self.channel_state & (ChannelState::ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK)) != (ChannelState::ChannelReady as u32) {
59045913
return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
59055914
}
@@ -6006,7 +6015,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60066015
cltv_expiry,
60076016
source,
60086017
onion_routing_packet,
6009-
skimmed_fee_msat: None,
6018+
skimmed_fee_msat,
60106019
});
60116020
return Ok(None);
60126021
}
@@ -6018,7 +6027,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60186027
cltv_expiry,
60196028
state: OutboundHTLCState::LocalAnnounced(Box::new(onion_routing_packet.clone())),
60206029
source,
6021-
skimmed_fee_msat: None,
6030+
skimmed_fee_msat,
60226031
});
60236032

60246033
let res = msgs::UpdateAddHTLC {
@@ -6028,7 +6037,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60286037
payment_hash,
60296038
cltv_expiry,
60306039
onion_routing_packet,
6031-
skimmed_fee_msat: None,
6040+
skimmed_fee_msat,
60326041
};
60336042
self.next_holder_htlc_id += 1;
60346043

@@ -6167,8 +6176,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
61676176
///
61686177
/// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
61696178
/// [`Self::send_htlc`] and [`Self::build_commitment_no_state_update`] for more info.
6170-
pub fn send_htlc_and_commit<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource, onion_routing_packet: msgs::OnionPacket, logger: &L) -> Result<Option<&ChannelMonitorUpdate>, ChannelError> where L::Target: Logger {
6171-
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, false, logger);
6179+
pub fn send_htlc_and_commit<L: Deref>(
6180+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
6181+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
6182+
) -> Result<Option<&ChannelMonitorUpdate>, ChannelError> where L::Target: Logger {
6183+
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
6184+
onion_routing_packet, false, skimmed_fee_msat, logger);
61726185
if let Err(e) = &send_res { if let ChannelError::Ignore(_) = e {} else { debug_assert!(false, "Sending cannot trigger channel failure"); } }
61736186
match send_res? {
61746187
Some(_) => {

lightning/src/ln/channelmanager.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2901,7 +2901,7 @@ where
29012901
session_priv: session_priv.clone(),
29022902
first_hop_htlc_msat: htlc_msat,
29032903
payment_id,
2904-
}, onion_packet, &self.logger);
2904+
}, onion_packet, None, &self.logger);
29052905
match break_chan_entry!(self, send_res, chan) {
29062906
Some(monitor_update) => {
29072907
let update_id = monitor_update.update_id;
@@ -3605,7 +3605,9 @@ where
36053605
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id: _,
36063606
forward_info: PendingHTLCInfo {
36073607
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3608-
routing: PendingHTLCRouting::Forward { onion_packet, .. }, incoming_amt_msat: _,
3608+
routing: PendingHTLCRouting::Forward {
3609+
onion_packet, skimmed_fee_msat, ..
3610+
}, incoming_amt_msat: _,
36093611
},
36103612
}) => {
36113613
log_trace!(self.logger, "Adding HTLC from short id {} with payment_hash {} to channel with short id {} after delay", prev_short_channel_id, log_bytes!(payment_hash.0), short_chan_id);
@@ -3619,7 +3621,7 @@ where
36193621
});
36203622
if let Err(e) = chan.get_mut().queue_add_htlc(outgoing_amt_msat,
36213623
payment_hash, outgoing_cltv_value, htlc_source.clone(),
3622-
onion_packet, &self.logger)
3624+
onion_packet, skimmed_fee_msat, &self.logger)
36233625
{
36243626
if let ChannelError::Ignore(msg) = e {
36253627
log_trace!(self.logger, "Failed to forward HTLC with payment_hash {}: {}", log_bytes!(payment_hash.0), msg);

0 commit comments

Comments
 (0)