Skip to content

Commit 7a5597a

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 dc571c7 commit 7a5597a

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,8 +3526,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
35263526
// handling this case better and maybe fulfilling some of the HTLCs while attempting
35273527
// to rebalance channels.
35283528
match &htlc_update {
3529-
&HTLCUpdateAwaitingACK::AddHTLC {amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, ..} => {
3530-
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(), onion_routing_packet.clone(), false, logger) {
3529+
&HTLCUpdateAwaitingACK::AddHTLC {
3530+
amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
3531+
skimmed_fee_msat, ..
3532+
} => {
3533+
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(),
3534+
onion_routing_packet.clone(), false, skimmed_fee_msat, logger)
3535+
{
35313536
Ok(update_add_msg_option) => update_add_htlcs.push(update_add_msg_option.unwrap()),
35323537
Err(e) => {
35333538
match e {
@@ -4169,7 +4174,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
41694174
payment_hash: htlc.payment_hash,
41704175
cltv_expiry: htlc.cltv_expiry,
41714176
onion_routing_packet: (**onion_packet).clone(),
4172-
skimmed_fee_msat: None,
4177+
skimmed_fee_msat: htlc.skimmed_fee_msat,
41734178
});
41744179
}
41754180
}
@@ -5983,11 +5988,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
59835988
/// commitment update.
59845989
///
59855990
/// `Err`s will only be [`ChannelError::Ignore`].
5986-
pub fn queue_add_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5987-
onion_routing_packet: msgs::OnionPacket, logger: &L)
5988-
-> Result<(), ChannelError> where L::Target: Logger {
5991+
pub fn queue_add_htlc<L: Deref>(
5992+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5993+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
5994+
) -> Result<(), ChannelError> where L::Target: Logger {
59895995
self
5990-
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true, logger)
5996+
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
5997+
skimmed_fee_msat, logger)
59915998
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
59925999
.map_err(|err| {
59936000
if let ChannelError::Ignore(_) = err { /* fine */ }
@@ -6012,9 +6019,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60126019
/// on this [`Channel`] if `force_holding_cell` is false.
60136020
///
60146021
/// `Err`s will only be [`ChannelError::Ignore`].
6015-
fn send_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
6016-
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool, logger: &L)
6017-
-> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
6022+
fn send_htlc<L: Deref>(
6023+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
6024+
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
6025+
skimmed_fee_msat: Option<u64>, logger: &L
6026+
) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
60186027
if (self.channel_state & (ChannelState::ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK)) != (ChannelState::ChannelReady as u32) {
60196028
return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
60206029
}
@@ -6066,7 +6075,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60666075
cltv_expiry,
60676076
source,
60686077
onion_routing_packet,
6069-
skimmed_fee_msat: None,
6078+
skimmed_fee_msat,
60706079
});
60716080
return Ok(None);
60726081
}
@@ -6078,7 +6087,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60786087
cltv_expiry,
60796088
state: OutboundHTLCState::LocalAnnounced(Box::new(onion_routing_packet.clone())),
60806089
source,
6081-
skimmed_fee_msat: None,
6090+
skimmed_fee_msat,
60826091
});
60836092

60846093
let res = msgs::UpdateAddHTLC {
@@ -6088,7 +6097,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60886097
payment_hash,
60896098
cltv_expiry,
60906099
onion_routing_packet,
6091-
skimmed_fee_msat: None,
6100+
skimmed_fee_msat,
60926101
};
60936102
self.next_holder_htlc_id += 1;
60946103

@@ -6227,8 +6236,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
62276236
///
62286237
/// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
62296238
/// [`Self::send_htlc`] and [`Self::build_commitment_no_state_update`] for more info.
6230-
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 {
6231-
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, false, logger);
6239+
pub fn send_htlc_and_commit<L: Deref>(
6240+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
6241+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
6242+
) -> Result<Option<&ChannelMonitorUpdate>, ChannelError> where L::Target: Logger {
6243+
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
6244+
onion_routing_packet, false, skimmed_fee_msat, logger);
62326245
if let Err(e) = &send_res { if let ChannelError::Ignore(_) = e {} else { debug_assert!(false, "Sending cannot trigger channel failure"); } }
62336246
match send_res? {
62346247
Some(_) => {

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,7 +2911,7 @@ where
29112911
session_priv: session_priv.clone(),
29122912
first_hop_htlc_msat: htlc_msat,
29132913
payment_id,
2914-
}, onion_packet, &self.logger);
2914+
}, onion_packet, None, &self.logger);
29152915
match break_chan_entry!(self, send_res, chan) {
29162916
Some(monitor_update) => {
29172917
let update_id = monitor_update.update_id;
@@ -3613,7 +3613,9 @@ where
36133613
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id: _,
36143614
forward_info: PendingHTLCInfo {
36153615
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3616-
routing: PendingHTLCRouting::Forward { onion_packet, .. }, incoming_amt_msat: _,
3616+
routing: PendingHTLCRouting::Forward {
3617+
onion_packet, skimmed_fee_msat, ..
3618+
}, incoming_amt_msat: _,
36173619
},
36183620
}) => {
36193621
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);
@@ -3627,7 +3629,7 @@ where
36273629
});
36283630
if let Err(e) = chan.get_mut().queue_add_htlc(outgoing_amt_msat,
36293631
payment_hash, outgoing_cltv_value, htlc_source.clone(),
3630-
onion_packet, &self.logger)
3632+
onion_packet, skimmed_fee_msat, &self.logger)
36313633
{
36323634
if let ChannelError::Ignore(msg) = e {
36333635
log_trace!(self.logger, "Failed to forward HTLC with payment_hash {}: {}", log_bytes!(payment_hash.0), msg);

0 commit comments

Comments
 (0)