@@ -2555,26 +2555,24 @@ impl FailHTLCContents for msgs::OnionErrorPacket {
25552555 HTLCUpdateAwaitingACK::FailHTLC { htlc_id, err_packet: self }
25562556 }
25572557}
2558- impl FailHTLCContents for (u16, [u8; 32]) {
2559- type Message = msgs::UpdateFailMalformedHTLC; // (failure_code, sha256_of_onion)
2558+ impl FailHTLCContents for ([u8; 32], u16 ) {
2559+ type Message = msgs::UpdateFailMalformedHTLC;
25602560 fn to_message(self, htlc_id: u64, channel_id: ChannelId) -> Self::Message {
25612561 msgs::UpdateFailMalformedHTLC {
25622562 htlc_id,
25632563 channel_id,
2564- failure_code : self.0,
2565- sha256_of_onion : self.1
2564+ sha256_of_onion : self.0,
2565+ failure_code : self.1
25662566 }
25672567 }
25682568 fn to_inbound_htlc_state(self) -> InboundHTLCState {
2569- InboundHTLCState::LocalRemoved(
2570- InboundHTLCRemovalReason::FailMalformed((self.1, self.0))
2571- )
2569+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(self))
25722570 }
25732571 fn to_htlc_update_awaiting_ack(self, htlc_id: u64) -> HTLCUpdateAwaitingACK {
25742572 HTLCUpdateAwaitingACK::FailMalformedHTLC {
25752573 htlc_id,
2576- failure_code : self.0,
2577- sha256_of_onion : self.1
2574+ sha256_of_onion : self.0,
2575+ failure_code : self.1
25782576 }
25792577 }
25802578}
@@ -2901,7 +2899,7 @@ impl<SP: Deref> Channel<SP> where
29012899 pub fn queue_fail_malformed_htlc<L: Deref>(
29022900 &mut self, htlc_id_arg: u64, failure_code: u16, sha256_of_onion: [u8; 32], logger: &L
29032901 ) -> Result<(), ChannelError> where L::Target: Logger {
2904- self.fail_htlc(htlc_id_arg, (failure_code, sha256_of_onion ), true, logger)
2902+ self.fail_htlc(htlc_id_arg, (sha256_of_onion, failure_code ), true, logger)
29052903 .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
29062904 }
29072905
@@ -2914,7 +2912,7 @@ impl<SP: Deref> Channel<SP> where
29142912 /// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
29152913 /// [`ChannelError::Ignore`].
29162914 fn fail_htlc<L: Deref, E: FailHTLCContents + Clone>(
2917- &mut self, htlc_id_arg: u64, err_packet : E, mut force_holding_cell: bool,
2915+ &mut self, htlc_id_arg: u64, err_contents : E, mut force_holding_cell: bool,
29182916 logger: &L
29192917 ) -> Result<Option<E::Message>, ChannelError> where L::Target: Logger {
29202918 if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
@@ -2981,18 +2979,18 @@ impl<SP: Deref> Channel<SP> where
29812979 }
29822980 }
29832981 log_trace!(logger, "Placing failure for HTLC ID {} in holding cell in channel {}.", htlc_id_arg, &self.context.channel_id());
2984- self.context.holding_cell_htlc_updates.push(err_packet .to_htlc_update_awaiting_ack(htlc_id_arg));
2982+ self.context.holding_cell_htlc_updates.push(err_contents .to_htlc_update_awaiting_ack(htlc_id_arg));
29852983 return Ok(None);
29862984 }
29872985
29882986 log_trace!(logger, "Failing HTLC ID {} back with {} message in channel {}.", htlc_id_arg,
29892987 E::Message::name(), &self.context.channel_id());
29902988 {
29912989 let htlc = &mut self.context.pending_inbound_htlcs[pending_idx];
2992- htlc.state = err_packet .clone().to_inbound_htlc_state();
2990+ htlc.state = err_contents .clone().to_inbound_htlc_state();
29932991 }
29942992
2995- Ok(Some(err_packet .to_message(htlc_id_arg, self.context.channel_id())))
2993+ Ok(Some(err_contents .to_message(htlc_id_arg, self.context.channel_id())))
29962994 }
29972995
29982996 // Message handlers:
@@ -3605,7 +3603,7 @@ impl<SP: Deref> Channel<SP> where
36053603 // the limit. In case it's less rare than I anticipate, we may want to revisit
36063604 // handling this case better and maybe fulfilling some of the HTLCs while attempting
36073605 // to rebalance channels.
3608- match &htlc_update {
3606+ let fail_htlc_res = match &htlc_update {
36093607 &HTLCUpdateAwaitingACK::AddHTLC {
36103608 amount_msat, cltv_expiry, ref payment_hash, ref source, ref onion_routing_packet,
36113609 skimmed_fee_msat, blinding_point, ..
@@ -3633,6 +3631,7 @@ impl<SP: Deref> Channel<SP> where
36333631 }
36343632 }
36353633 }
3634+ None
36363635 },
36373636 &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
36383637 // If an HTLC claim was previously added to the holding cell (via
@@ -3646,40 +3645,33 @@ impl<SP: Deref> Channel<SP> where
36463645 { monitor_update } else { unreachable!() };
36473646 update_fulfill_count += 1;
36483647 monitor_update.updates.append(&mut additional_monitor_update.updates);
3648+ None
36493649 },
36503650 &HTLCUpdateAwaitingACK::FailHTLC { htlc_id, ref err_packet } => {
3651- match self.fail_htlc(htlc_id, err_packet.clone(), false, logger) {
3652- Ok(update_fail_msg_option) => {
3653- // If an HTLC failure was previously added to the holding cell (via
3654- // `queue_fail_htlc`) then generating the fail message itself must
3655- // not fail - we should never end up in a state where we double-fail
3656- // an HTLC or fail-then-claim an HTLC as it indicates we didn't wait
3657- // for a full revocation before failing.
3658- debug_assert!(update_fail_msg_option.is_some());
3659- update_fail_count += 1;
3660- },
3661- Err(e) => {
3662- if let ChannelError::Ignore(_) = e {}
3663- else {
3664- panic!("Got a non-IgnoreError action trying to fail holding cell HTLC");
3665- }
3666- }
3667- }
3651+ Some(self.fail_htlc(htlc_id, err_packet.clone(), false, logger)
3652+ .map(|fail_msg_opt| fail_msg_opt.map(|_| ())))
36683653 },
36693654 &HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, failure_code, sha256_of_onion } => {
3670- match self.fail_htlc(htlc_id, (failure_code, sha256_of_onion), false, logger) {
3671- Ok(update_fail_malformed_opt) => {
3672- debug_assert!(update_fail_malformed_opt.is_some()); // See above comment
3673- update_fail_count += 1;
3674- },
3675- Err(e) => {
3676- if let ChannelError::Ignore(_) = e {}
3677- else {
3678- panic!("Got a non-IgnoreError action trying to fail holding cell HTLC");
3679- }
3680- }
3681- }
3682- },
3655+ Some(self.fail_htlc(htlc_id, (sha256_of_onion, failure_code), false, logger)
3656+ .map(|fail_msg_opt| fail_msg_opt.map(|_| ())))
3657+ }
3658+ };
3659+ if let Some(res) = fail_htlc_res {
3660+ match res {
3661+ Ok(fail_msg_opt) => {
3662+ // If an HTLC failure was previously added to the holding cell (via
3663+ // `queue_fail_{malformed_}htlc`) then generating the fail message itself must
3664+ // not fail - we should never end up in a state where we double-fail
3665+ // an HTLC or fail-then-claim an HTLC as it indicates we didn't wait
3666+ // for a full revocation before failing.
3667+ debug_assert!(fail_msg_opt.is_some());
3668+ update_fail_count += 1;
3669+ },
3670+ Err(ChannelError::Ignore(_)) => {},
3671+ Err(_) => {
3672+ panic!("Got a non-IgnoreError action trying to fail holding cell HTLC");
3673+ },
3674+ }
36833675 }
36843676 }
36853677 if update_add_count == 0 && update_fulfill_count == 0 && update_fail_count == 0 && self.context.holding_cell_update_fee.is_none() {
0 commit comments