Skip to content

Commit dd21fdb

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 f8cddd5 commit dd21fdb

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

lightning/src/ln/channel.rs

+28-15
Original file line numberDiff line numberDiff line change
@@ -3055,8 +3055,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
30553055
// handling this case better and maybe fulfilling some of the HTLCs while attempting
30563056
// to rebalance channels.
30573057
match &htlc_update {
3058-
&HTLCUpdateAwaitingACK::AddHTLC {amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet, ..} => {
3059-
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(), onion_routing_packet.clone(), false, logger) {
3058+
&HTLCUpdateAwaitingACK::AddHTLC {
3059+
amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
3060+
skimmed_fee_msat, ..
3061+
} => {
3062+
match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(),
3063+
onion_routing_packet.clone(), false, skimmed_fee_msat, logger)
3064+
{
30603065
Ok(update_add_msg_option) => update_add_htlcs.push(update_add_msg_option.unwrap()),
30613066
Err(e) => {
30623067
match e {
@@ -3698,7 +3703,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
36983703
payment_hash: htlc.payment_hash,
36993704
cltv_expiry: htlc.cltv_expiry,
37003705
onion_routing_packet: (**onion_packet).clone(),
3701-
skimmed_fee_msat: None,
3706+
skimmed_fee_msat: htlc.skimmed_fee_msat,
37023707
});
37033708
}
37043709
}
@@ -5046,11 +5051,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
50465051
/// commitment update.
50475052
///
50485053
/// `Err`s will only be [`ChannelError::Ignore`].
5049-
pub fn queue_add_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5050-
onion_routing_packet: msgs::OnionPacket, logger: &L)
5051-
-> Result<(), ChannelError> where L::Target: Logger {
5054+
pub fn queue_add_htlc<L: Deref>(
5055+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5056+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
5057+
) -> Result<(), ChannelError> where L::Target: Logger {
50525058
self
5053-
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true, logger)
5059+
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
5060+
skimmed_fee_msat, logger)
50545061
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
50555062
.map_err(|err| {
50565063
if let ChannelError::Ignore(_) = err { /* fine */ }
@@ -5075,9 +5082,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
50755082
/// on this [`Channel`] if `force_holding_cell` is false.
50765083
///
50775084
/// `Err`s will only be [`ChannelError::Ignore`].
5078-
fn send_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5079-
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool, logger: &L)
5080-
-> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
5085+
fn send_htlc<L: Deref>(
5086+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5087+
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
5088+
skimmed_fee_msat: Option<u64>, logger: &L
5089+
) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError> where L::Target: Logger {
50815090
if (self.context.channel_state & (ChannelState::ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK)) != (ChannelState::ChannelReady as u32) {
50825091
return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
50835092
}
@@ -5129,7 +5138,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
51295138
cltv_expiry,
51305139
source,
51315140
onion_routing_packet,
5132-
skimmed_fee_msat: None,
5141+
skimmed_fee_msat,
51335142
});
51345143
return Ok(None);
51355144
}
@@ -5141,7 +5150,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
51415150
cltv_expiry,
51425151
state: OutboundHTLCState::LocalAnnounced(Box::new(onion_routing_packet.clone())),
51435152
source,
5144-
skimmed_fee_msat: None,
5153+
skimmed_fee_msat,
51455154
});
51465155

51475156
let res = msgs::UpdateAddHTLC {
@@ -5151,7 +5160,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
51515160
payment_hash,
51525161
cltv_expiry,
51535162
onion_routing_packet,
5154-
skimmed_fee_msat: None,
5163+
skimmed_fee_msat,
51555164
};
51565165
self.context.next_holder_htlc_id += 1;
51575166

@@ -5290,8 +5299,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
52905299
///
52915300
/// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
52925301
/// [`Self::send_htlc`] and [`Self::build_commitment_no_state_update`] for more info.
5293-
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 {
5294-
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, false, logger);
5302+
pub fn send_htlc_and_commit<L: Deref>(
5303+
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
5304+
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>, logger: &L
5305+
) -> Result<Option<&ChannelMonitorUpdate>, ChannelError> where L::Target: Logger {
5306+
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
5307+
onion_routing_packet, false, skimmed_fee_msat, logger);
52955308
if let Err(e) = &send_res { if let ChannelError::Ignore(_) = e {} else { debug_assert!(false, "Sending cannot trigger channel failure"); } }
52965309
match send_res? {
52975310
Some(_) => {

lightning/src/ln/channelmanager.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@ where
30243024
session_priv: session_priv.clone(),
30253025
first_hop_htlc_msat: htlc_msat,
30263026
payment_id,
3027-
}, onion_packet, &self.logger);
3027+
}, onion_packet, None, &self.logger);
30283028
match break_chan_entry!(self, send_res, chan) {
30293029
Some(monitor_update) => {
30303030
let update_id = monitor_update.update_id;
@@ -3728,7 +3728,7 @@ where
37283728
prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id: _,
37293729
forward_info: PendingHTLCInfo {
37303730
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3731-
routing: PendingHTLCRouting::Forward { onion_packet, .. }, ..
3731+
routing: PendingHTLCRouting::Forward { onion_packet, .. }, skimmed_fee_msat, ..
37323732
},
37333733
}) => {
37343734
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);
@@ -3742,7 +3742,7 @@ where
37423742
});
37433743
if let Err(e) = chan.get_mut().queue_add_htlc(outgoing_amt_msat,
37443744
payment_hash, outgoing_cltv_value, htlc_source.clone(),
3745-
onion_packet, &self.logger)
3745+
onion_packet, skimmed_fee_msat, &self.logger)
37463746
{
37473747
if let ChannelError::Ignore(msg) = e {
37483748
log_trace!(self.logger, "Failed to forward HTLC with payment_hash {}: {}", log_bytes!(payment_hash.0), msg);

0 commit comments

Comments
 (0)