@@ -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);
@@ -5871,9 +5903,10 @@ where
5871
5903
fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,
5872
5904
channel: &mut Channel<SP>, raa: Option<msgs::RevokeAndACK>,
5873
5905
commitment_update: Option<msgs::CommitmentUpdate>, order: RAACommitmentOrder,
5874
- pending_forwards: Vec<(PendingHTLCInfo, u64)>, funding_broadcastable: Option<Transaction>,
5906
+ mut pending_forwards: Vec<(PendingHTLCInfo, u64)>, pending_htlc_status: Vec<msgs::UpdateAddHTLC>,
5907
+ funding_broadcastable: Option<Transaction>,
5875
5908
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
5876
- -> Option<(u64, OutPoint, u128, Vec<(PendingHTLCInfo, u64)>)> {
5909
+ -> ( Option<(u64, OutPoint, u128, Vec<(PendingHTLCInfo, u64)>)>, Vec<(HTLCFailureMsg, Option<u64>)>) {
5877
5910
let logger = WithChannelContext::from(&self.logger, &channel.context);
5878
5911
log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {}broadcasting funding, {} channel ready, {} announcement",
5879
5912
&channel.context.channel_id(),
@@ -5884,10 +5917,26 @@ where
5884
5917
if announcement_sigs.is_some() { "sending" } else { "without" });
5885
5918
5886
5919
let mut htlc_forwards = None;
5887
-
5920
+ let mut htlc_fails = Vec::new();
5888
5921
let counterparty_node_id = channel.context.get_counterparty_node_id();
5922
+ let short_channel_id = channel.context.get_short_channel_id().unwrap_or(channel.context.outbound_scid_alias());
5923
+ for update_add_htlc in pending_htlc_status {
5924
+ let decoded_hop_res = self.decode_update_add_htlc_onion(&update_add_htlc, &counterparty_node_id, Some(channel));
5925
+ match decoded_hop_res {
5926
+ Ok((next_hop, shared_secret, next_packet_pk_opt)) => {
5927
+ match self.construct_pending_htlc_status(
5928
+ &update_add_htlc, &counterparty_node_id, shared_secret, next_hop,
5929
+ channel.context.config().accept_underpaying_htlcs, next_packet_pk_opt,
5930
+ ) {
5931
+ PendingHTLCStatus::Forward(htlc_forward) => pending_forwards.push((htlc_forward, update_add_htlc.htlc_id)),
5932
+ PendingHTLCStatus::Fail(htlc_fail) => htlc_fails.push((htlc_fail, None)),
5933
+ }
5934
+ },
5935
+ Err(e) => htlc_fails.push(e),
5936
+ };
5937
+ }
5889
5938
if !pending_forwards.is_empty() {
5890
- htlc_forwards = Some((channel.context.get_short_channel_id().unwrap_or(channel.context.outbound_scid_alias()) ,
5939
+ htlc_forwards = Some((short_channel_id ,
5891
5940
channel.context.get_funding_txo().unwrap(), channel.context.get_user_id(), pending_forwards));
5892
5941
}
5893
5942
@@ -5939,7 +5988,7 @@ where
5939
5988
emit_channel_ready_event!(pending_events, channel);
5940
5989
}
5941
5990
5942
- htlc_forwards
5991
+ ( htlc_forwards, htlc_fails)
5943
5992
}
5944
5993
5945
5994
fn channel_monitor_updated(&self, funding_txo: &OutPoint, highest_applied_update_id: u64, counterparty_node_id: Option<&PublicKey>) {
@@ -6687,7 +6736,7 @@ where
6687
6736
msg, counterparty_node_id, shared_secret, next_hop,
6688
6737
chan.context.config().accept_underpaying_htlcs, next_packet_pk_opt,
6689
6738
),
6690
- Err(e) => PendingHTLCStatus::Fail(e )
6739
+ Err((fail_msg, _)) => PendingHTLCStatus::Fail(fail_msg )
6691
6740
};
6692
6741
let create_pending_htlc_status = |chan: &Channel<SP>, pending_forward_info: PendingHTLCStatus, error_code: u16| {
6693
6742
if msg.blinding_point.is_some() {
@@ -7198,10 +7247,10 @@ where
7198
7247
}
7199
7248
}
7200
7249
let need_lnd_workaround = chan.context.workaround_lnd_bug_4006.take();
7201
- let htlc_forwards = self.handle_channel_resumption(
7250
+ let ( htlc_forwards, htlc_fails) = self.handle_channel_resumption(
7202
7251
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
7203
- Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
7204
- debug_assert!(htlc_forwards.is_none());
7252
+ Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
7253
+ debug_assert!(htlc_forwards.is_none() && htlc_fails.is_empty() );
7205
7254
if let Some(upd) = channel_update {
7206
7255
peer_state.pending_msg_events.push(upd);
7207
7256
}
0 commit comments