@@ -6142,22 +6142,14 @@ impl<SP: Deref> FundedChannel<SP> where
61426142 );
61436143 update_add_count += 1;
61446144 },
6145- Err(e) => {
6146- match e {
6147- ChannelError::Ignore(ref msg) => {
6148- log_info!(logger, "Failed to send HTLC with payment_hash {} due to {} in channel {}", &payment_hash, msg, &self.context.channel_id());
6149- // If we fail to send here, then this HTLC should
6150- // be failed backwards. Failing to send here
6151- // indicates that this HTLC may keep being put back
6152- // into the holding cell without ever being
6153- // successfully forwarded/failed/fulfilled, causing
6154- // our counterparty to eventually close on us.
6155- htlcs_to_fail.push((source.clone(), *payment_hash));
6156- },
6157- _ => {
6158- panic!("Got a non-IgnoreError action trying to send holding cell HTLC");
6159- },
6160- }
6145+ Err((_, msg)) => {
6146+ log_info!(logger, "Failed to send HTLC with payment_hash {} due to {} in channel {}", &payment_hash, msg, &self.context.channel_id());
6147+ // If we fail to send here, then this HTLC should be failed
6148+ // backwards. Failing to send here indicates that this HTLC may
6149+ // keep being put back into the holding cell without ever being
6150+ // successfully forwarded/failed/fulfilled, causing our
6151+ // counterparty to eventually close on us.
6152+ htlcs_to_fail.push((source.clone(), *payment_hash));
61616153 }
61626154 }
61636155 None
@@ -8819,22 +8811,19 @@ impl<SP: Deref> FundedChannel<SP> where
88198811 /// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
88208812 /// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
88218813 /// commitment update.
8822- ///
8823- /// `Err`s will only be [`ChannelError::Ignore`].
88248814 pub fn queue_add_htlc<F: Deref, L: Deref>(
88258815 &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
88268816 onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
88278817 blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8828- ) -> Result<(), ChannelError >
8818+ ) -> Result<(), (LocalHTLCFailureReason, String) >
88298819 where F::Target: FeeEstimator, L::Target: Logger
88308820 {
88318821 self
88328822 .send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
88338823 skimmed_fee_msat, blinding_point, fee_estimator, logger)
88348824 .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
88358825 .map_err(|err| {
8836- if let ChannelError::Ignore(_) = err { /* fine */ }
8837- else { debug_assert!(false, "Queueing cannot trigger channel failure"); }
8826+ debug_assert!(err.0.is_temporary(), "Queuing HTLC should return temporary error");
88388827 err
88398828 })
88408829 }
@@ -8854,38 +8843,40 @@ impl<SP: Deref> FundedChannel<SP> where
88548843 /// You MUST call [`Self::send_commitment_no_state_update`] prior to calling any other methods
88558844 /// on this [`FundedChannel`] if `force_holding_cell` is false.
88568845 ///
8857- /// `Err`s will only be [`ChannelError::Ignore`] .
8846+ /// `Err`' s will always be temporary channel failures .
88588847 fn send_htlc<F: Deref, L: Deref>(
88598848 &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
88608849 onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
88618850 skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
88628851 fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8863- ) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError >
8852+ ) -> Result<Option<msgs::UpdateAddHTLC>, (LocalHTLCFailureReason, String) >
88648853 where F::Target: FeeEstimator, L::Target: Logger
88658854 {
88668855 if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
88678856 self.context.channel_state.is_local_shutdown_sent() ||
88688857 self.context.channel_state.is_remote_shutdown_sent()
88698858 {
8870- return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
8859+ return Err((LocalHTLCFailureReason::ChannelNotReady,
8860+ "Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
88718861 }
88728862 let channel_total_msat = self.funding.get_value_satoshis() * 1000;
88738863 if amount_msat > channel_total_msat {
8874- return Err(ChannelError::Ignore(format!("Cannot send amount {}, because it is more than the total value of the channel {}", amount_msat, channel_total_msat)));
8864+ return Err((LocalHTLCFailureReason::AmountExceedsCapacity,
8865+ format!("Cannot send amount {}, because it is more than the total value of the channel {}", amount_msat, channel_total_msat)));
88758866 }
88768867
88778868 if amount_msat == 0 {
8878- return Err(ChannelError::Ignore( "Cannot send 0-msat HTLC".to_owned()));
8869+ return Err((LocalHTLCFailureReason::ZeroAmount, "Cannot send 0-msat HTLC".to_owned()));
88798870 }
88808871
88818872 let available_balances = self.get_available_balances(fee_estimator);
88828873 if amount_msat < available_balances.next_outbound_htlc_minimum_msat {
8883- return Err(ChannelError::Ignore( format!("Cannot send less than our next-HTLC minimum - {} msat",
8874+ return Err((LocalHTLCFailureReason::HTLCMinimum, format!("Cannot send less than our next-HTLC minimum - {} msat",
88848875 available_balances.next_outbound_htlc_minimum_msat)));
88858876 }
88868877
88878878 if amount_msat > available_balances.next_outbound_htlc_limit_msat {
8888- return Err(ChannelError::Ignore( format!("Cannot send more than our next-HTLC maximum - {} msat",
8879+ return Err((LocalHTLCFailureReason::HTLCMaximum, format!("Cannot send more than our next-HTLC maximum - {} msat",
88898880 available_balances.next_outbound_htlc_limit_msat)));
88908881 }
88918882
@@ -8896,7 +8887,8 @@ impl<SP: Deref> FundedChannel<SP> where
88968887 // disconnected during the time the previous hop was doing the commitment dance we may
88978888 // end up getting here after the forwarding delay. In any case, returning an
88988889 // IgnoreError will get ChannelManager to do the right thing and fail backwards now.
8899- return Err(ChannelError::Ignore("Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
8890+ return Err((LocalHTLCFailureReason::PeerOffline,
8891+ "Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
89008892 }
89018893
89028894 let need_holding_cell = !self.context.channel_state.can_generate_new_commitment();
@@ -9185,8 +9177,8 @@ impl<SP: Deref> FundedChannel<SP> where
91859177 {
91869178 let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
91879179 onion_routing_packet, false, skimmed_fee_msat, None, fee_estimator, logger);
9188- if let Err(e) = &send_res { if let ChannelError::Ignore(_) = e {} else { debug_assert!(false, "Sending cannot trigger channel failure"); } }
9189- match send_res? {
9180+ // All [`LocalHTLCFailureReason`] errors are temporary, so they are [` ChannelError::Ignore`].
9181+ match send_res.map_err(|(_, msg)| ChannelError::Ignore(msg)) ? {
91909182 Some(_) => {
91919183 let monitor_update = self.build_commitment_no_status_check(logger);
91929184 self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
0 commit comments