@@ -6561,7 +6561,9 @@ trait FailHTLCContents {
65616561 type Message: FailHTLCMessageName;
65626562 fn to_message(self, htlc_id: u64, channel_id: ChannelId) -> Self::Message;
65636563 fn to_inbound_htlc_state(self) -> InboundHTLCState;
6564- fn to_htlc_update_awaiting_ack(self, htlc_id: u64) -> HTLCUpdateAwaitingACK;
6564+ fn to_htlc_update_awaiting_ack(
6565+ self, htlc_id: u64, monitor_event_source: Option<MonitorEventSource>,
6566+ ) -> HTLCUpdateAwaitingACK;
65656567}
65666568impl FailHTLCContents for msgs::OnionErrorPacket {
65676569 type Message = msgs::UpdateFailHTLC;
@@ -6576,8 +6578,10 @@ impl FailHTLCContents for msgs::OnionErrorPacket {
65766578 fn to_inbound_htlc_state(self) -> InboundHTLCState {
65776579 InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(self))
65786580 }
6579- fn to_htlc_update_awaiting_ack(self, htlc_id: u64) -> HTLCUpdateAwaitingACK {
6580- HTLCUpdateAwaitingACK::FailHTLC { htlc_id, err_packet: self, monitor_event_source: None }
6581+ fn to_htlc_update_awaiting_ack(
6582+ self, htlc_id: u64, monitor_event_source: Option<MonitorEventSource>,
6583+ ) -> HTLCUpdateAwaitingACK {
6584+ HTLCUpdateAwaitingACK::FailHTLC { htlc_id, err_packet: self, monitor_event_source }
65816585 }
65826586}
65836587impl FailHTLCContents for ([u8; 32], u16) {
@@ -6596,12 +6600,14 @@ impl FailHTLCContents for ([u8; 32], u16) {
65966600 failure_code: self.1,
65976601 })
65986602 }
6599- fn to_htlc_update_awaiting_ack(self, htlc_id: u64) -> HTLCUpdateAwaitingACK {
6603+ fn to_htlc_update_awaiting_ack(
6604+ self, htlc_id: u64, monitor_event_source: Option<MonitorEventSource>,
6605+ ) -> HTLCUpdateAwaitingACK {
66006606 HTLCUpdateAwaitingACK::FailMalformedHTLC {
66016607 htlc_id,
66026608 sha256_of_onion: self.0,
66036609 failure_code: self.1,
6604- monitor_event_source: None ,
6610+ monitor_event_source,
66056611 }
66066612 }
66076613}
@@ -7343,9 +7349,10 @@ where
73437349 /// Returns `Err` (always with [`ChannelError::Ignore`]) if the HTLC could not be failed (e.g.
73447350 /// if it was already resolved). Otherwise returns `Ok`.
73457351 pub fn queue_fail_htlc<L: Logger>(
7346- &mut self, htlc_id_arg: u64, err_packet: msgs::OnionErrorPacket, logger: &L,
7352+ &mut self, htlc_id_arg: u64, err_packet: msgs::OnionErrorPacket,
7353+ monitor_event_source: Option<MonitorEventSource>, logger: &L,
73477354 ) -> Result<(), ChannelError> {
7348- self.fail_htlc(htlc_id_arg, err_packet, true, logger)
7355+ self.fail_htlc(htlc_id_arg, err_packet, true, monitor_event_source, logger)
73497356 .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
73507357 }
73517358
@@ -7354,18 +7361,25 @@ where
73547361 ///
73557362 /// See [`Self::queue_fail_htlc`] for more info.
73567363 pub fn queue_fail_malformed_htlc<L: Logger>(
7357- &mut self, htlc_id_arg: u64, failure_code: u16, sha256_of_onion: [u8; 32], logger: &L,
7364+ &mut self, htlc_id_arg: u64, failure_code: u16, sha256_of_onion: [u8; 32],
7365+ monitor_event_source: Option<MonitorEventSource>, logger: &L,
73587366 ) -> Result<(), ChannelError> {
7359- self.fail_htlc(htlc_id_arg, (sha256_of_onion, failure_code), true, logger)
7360- .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
7367+ self.fail_htlc(
7368+ htlc_id_arg,
7369+ (sha256_of_onion, failure_code),
7370+ true,
7371+ monitor_event_source,
7372+ logger,
7373+ )
7374+ .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
73617375 }
73627376
73637377 /// Returns `Err` (always with [`ChannelError::Ignore`]) if the HTLC could not be failed (e.g.
73647378 /// if it was already resolved). Otherwise returns `Ok`.
73657379 #[rustfmt::skip]
73667380 fn fail_htlc<L: Logger, E: FailHTLCContents + Clone>(
73677381 &mut self, htlc_id_arg: u64, err_contents: E, mut force_holding_cell: bool,
7368- logger: &L
7382+ monitor_event_source: Option<MonitorEventSource>, logger: &L
73697383 ) -> Result<Option<E::Message>, ChannelError> {
73707384 if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
73717385 panic!("Was asked to fail an HTLC when channel was not in an operational state");
@@ -7402,25 +7416,28 @@ where
74027416
74037417 // Now update local state:
74047418 if force_holding_cell {
7405- for pending_update in self.context.holding_cell_htlc_updates.iter () {
7419+ for pending_update in self.context.holding_cell_htlc_updates.iter_mut () {
74067420 match pending_update {
7407- &HTLCUpdateAwaitingACK::ClaimHTLC { htlc_id, .. } => {
7421+ &mut HTLCUpdateAwaitingACK::ClaimHTLC { htlc_id, .. } => {
74087422 if htlc_id_arg == htlc_id {
74097423 return Err(ChannelError::Ignore(format!("HTLC {} was already claimed!", htlc_id)));
74107424 }
74117425 },
7412- &HTLCUpdateAwaitingACK::FailHTLC { htlc_id, .. } |
7413- &HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, .. } =>
7426+ &mut HTLCUpdateAwaitingACK::FailHTLC { htlc_id, monitor_event_source: ref mut src , .. } |
7427+ &mut HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, monitor_event_source: ref mut src , .. } =>
74147428 {
74157429 if htlc_id_arg == htlc_id {
7430+ if src.is_none() {
7431+ *src = monitor_event_source;
7432+ }
74167433 return Err(ChannelError::Ignore(format!("HTLC {} was already pending failure", htlc_id)));
74177434 }
74187435 },
74197436 _ => {}
74207437 }
74217438 }
74227439 log_trace!(logger, "Placing failure for HTLC ID {} in holding cell.", htlc_id_arg);
7423- self.context.holding_cell_htlc_updates.push(err_contents.to_htlc_update_awaiting_ack(htlc_id_arg));
7440+ self.context.holding_cell_htlc_updates.push(err_contents.to_htlc_update_awaiting_ack(htlc_id_arg, monitor_event_source ));
74247441 return Ok(None);
74257442 }
74267443
@@ -8449,18 +8466,34 @@ where
84498466 monitor_update.updates.append(&mut additional_monitor_update.updates);
84508467 None
84518468 },
8452- &HTLCUpdateAwaitingACK::FailHTLC { htlc_id, ref err_packet, .. } => Some(
8453- self.fail_htlc(htlc_id, err_packet.clone(), false, logger)
8454- .map(|fail_msg_opt| fail_msg_opt.map(|_| ())),
8469+ &HTLCUpdateAwaitingACK::FailHTLC {
8470+ htlc_id,
8471+ ref err_packet,
8472+ monitor_event_source,
8473+ } => Some(
8474+ self.fail_htlc(
8475+ htlc_id,
8476+ err_packet.clone(),
8477+ false,
8478+ monitor_event_source,
8479+ logger,
8480+ )
8481+ .map(|fail_msg_opt| fail_msg_opt.map(|_| ())),
84558482 ),
84568483 &HTLCUpdateAwaitingACK::FailMalformedHTLC {
84578484 htlc_id,
84588485 failure_code,
84598486 sha256_of_onion,
8460- ..
8487+ monitor_event_source,
84618488 } => Some(
8462- self.fail_htlc(htlc_id, (sha256_of_onion, failure_code), false, logger)
8463- .map(|fail_msg_opt| fail_msg_opt.map(|_| ())),
8489+ self.fail_htlc(
8490+ htlc_id,
8491+ (sha256_of_onion, failure_code),
8492+ false,
8493+ monitor_event_source,
8494+ logger,
8495+ )
8496+ .map(|fail_msg_opt| fail_msg_opt.map(|_| ())),
84648497 ),
84658498 };
84668499 if let Some(res) = fail_htlc_res {
0 commit comments