@@ -2189,16 +2189,17 @@ macro_rules! handle_monitor_update_completion {
2189
2189
let update_actions = $peer_state.monitor_update_blocked_actions
2190
2190
.remove(&$chan.context.channel_id()).unwrap_or(Vec::new());
2191
2191
2192
- let htlc_forwards = $self.handle_channel_resumption(
2192
+ let ( htlc_forwards, mut htlc_fails) = $self.handle_channel_resumption(
2193
2193
&mut $peer_state.pending_msg_events, $chan, updates.raa,
2194
- updates.commitment_update, updates.order, updates.accepted_htlcs,
2194
+ updates.commitment_update, updates.order, updates.accepted_htlcs, updates.pending_htlc_status,
2195
2195
updates.funding_broadcastable, updates.channel_ready,
2196
2196
updates.announcement_sigs);
2197
2197
if let Some(upd) = channel_update {
2198
2198
$peer_state.pending_msg_events.push(upd);
2199
2199
}
2200
2200
2201
2201
let channel_id = $chan.context.channel_id();
2202
+ let scid = $chan.context.get_short_channel_id().or($chan.context.latest_inbound_scid_alias());
2202
2203
let unbroadcasted_batch_funding_txid = $chan.context.unbroadcasted_batch_funding_txid();
2203
2204
core::mem::drop($peer_state_lock);
2204
2205
core::mem::drop($per_peer_state_lock);
@@ -2253,6 +2254,37 @@ macro_rules! handle_monitor_update_completion {
2253
2254
$self.forward_htlcs(&mut [forwards][..]);
2254
2255
}
2255
2256
$self.finalize_claims(updates.finalized_claimed_htlcs);
2257
+ for (htlc_fail, outgoing_scid) in htlc_fails.drain(..) {
2258
+ if let Some(scid) = scid {
2259
+ let (channel_id, failure) = match htlc_fail {
2260
+ HTLCFailureMsg::Relay(fail_htlc) => (fail_htlc.channel_id, HTLCForwardInfo::FailHTLC {
2261
+ htlc_id: fail_htlc.htlc_id,
2262
+ err_packet: fail_htlc.reason,
2263
+ }),
2264
+ HTLCFailureMsg::Malformed(fail_malformed_htlc) => (fail_malformed_htlc.channel_id, HTLCForwardInfo::FailMalformedHTLC {
2265
+ htlc_id: fail_malformed_htlc.htlc_id,
2266
+ sha256_of_onion: fail_malformed_htlc.sha256_of_onion,
2267
+ failure_code: fail_malformed_htlc.failure_code,
2268
+ }),
2269
+ };
2270
+ let destination = if let Some(outgoing_scid) = outgoing_scid {
2271
+ match $self.short_to_chan_info.read().unwrap().get(&outgoing_scid) {
2272
+ Some((_, outgoing_channel_id)) => HTLCDestination::NextHopChannel {
2273
+ node_id: Some(counterparty_node_id),
2274
+ channel_id: *outgoing_channel_id,
2275
+ },
2276
+ None => HTLCDestination::UnknownNextHop {
2277
+ requested_forward_scid: outgoing_scid,
2278
+ },
2279
+ }
2280
+ } else {
2281
+ HTLCDestination::InvalidOnion
2282
+ };
2283
+ $self.push_htlc_failure(scid, channel_id, failure, destination);
2284
+ } else {
2285
+ debug_assert!(false, "Channel with failed HTLC should have a real/alias short_channel_id")
2286
+ }
2287
+ }
2256
2288
for failure in updates.failed_htlcs.drain(..) {
2257
2289
let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id };
2258
2290
$self.fail_htlc_backwards_internal(&failure.0, &failure.1, &failure.2, receiver);
@@ -5872,9 +5904,10 @@ where
5872
5904
fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,
5873
5905
channel: &mut Channel<SP>, raa: Option<msgs::RevokeAndACK>,
5874
5906
commitment_update: Option<msgs::CommitmentUpdate>, order: RAACommitmentOrder,
5875
- pending_forwards: Vec<(PendingHTLCInfo, u64)>, funding_broadcastable: Option<Transaction>,
5907
+ mut pending_forwards: Vec<(PendingHTLCInfo, u64)>, pending_htlc_status: Vec<msgs::UpdateAddHTLC>,
5908
+ funding_broadcastable: Option<Transaction>,
5876
5909
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
5877
- -> Option<(u64, OutPoint, u128, Vec<(PendingHTLCInfo, u64)>)> {
5910
+ -> ( Option<(u64, OutPoint, u128, Vec<(PendingHTLCInfo, u64)>)>, Vec<(HTLCFailureMsg, Option<u64>)>) {
5878
5911
let logger = WithChannelContext::from(&self.logger, &channel.context);
5879
5912
log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {}broadcasting funding, {} channel ready, {} announcement",
5880
5913
&channel.context.channel_id(),
@@ -5885,10 +5918,26 @@ where
5885
5918
if announcement_sigs.is_some() { "sending" } else { "without" });
5886
5919
5887
5920
let mut htlc_forwards = None;
5888
-
5921
+ let mut htlc_fails = Vec::new();
5889
5922
let counterparty_node_id = channel.context.get_counterparty_node_id();
5923
+ let short_channel_id = channel.context.get_short_channel_id().unwrap_or(channel.context.outbound_scid_alias());
5924
+ for update_add_htlc in pending_htlc_status {
5925
+ let decoded_hop_res = self.decode_update_add_htlc_onion(&update_add_htlc, &counterparty_node_id, Some(channel));
5926
+ match decoded_hop_res {
5927
+ Ok((next_hop, shared_secret, next_packet_pk_opt)) => {
5928
+ match self.construct_pending_htlc_status(
5929
+ &update_add_htlc, &counterparty_node_id, shared_secret, next_hop,
5930
+ channel.context.config().accept_underpaying_htlcs, next_packet_pk_opt,
5931
+ ) {
5932
+ PendingHTLCStatus::Forward(htlc_forward) => pending_forwards.push((htlc_forward, update_add_htlc.htlc_id)),
5933
+ PendingHTLCStatus::Fail(htlc_fail) => htlc_fails.push((htlc_fail, None)),
5934
+ }
5935
+ },
5936
+ Err(e) => htlc_fails.push(e),
5937
+ };
5938
+ }
5890
5939
if !pending_forwards.is_empty() {
5891
- htlc_forwards = Some((channel.context.get_short_channel_id().unwrap_or(channel.context.outbound_scid_alias()) ,
5940
+ htlc_forwards = Some((short_channel_id ,
5892
5941
channel.context.get_funding_txo().unwrap(), channel.context.get_user_id(), pending_forwards));
5893
5942
}
5894
5943
@@ -5940,7 +5989,7 @@ where
5940
5989
emit_channel_ready_event!(pending_events, channel);
5941
5990
}
5942
5991
5943
- htlc_forwards
5992
+ ( htlc_forwards, htlc_fails)
5944
5993
}
5945
5994
5946
5995
fn channel_monitor_updated(&self, funding_txo: &OutPoint, highest_applied_update_id: u64, counterparty_node_id: Option<&PublicKey>) {
@@ -7199,10 +7248,10 @@ where
7199
7248
}
7200
7249
}
7201
7250
let need_lnd_workaround = chan.context.workaround_lnd_bug_4006.take();
7202
- let htlc_forwards = self.handle_channel_resumption(
7251
+ let ( htlc_forwards, htlc_fails) = self.handle_channel_resumption(
7203
7252
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
7204
- Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
7205
- debug_assert!(htlc_forwards.is_none());
7253
+ Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
7254
+ debug_assert!(htlc_forwards.is_none() && htlc_fails.is_empty() );
7206
7255
if let Some(upd) = channel_update {
7207
7256
peer_state.pending_msg_events.push(upd);
7208
7257
}
0 commit comments