@@ -5852,22 +5852,14 @@ impl<SP: Deref> FundedChannel<SP> where
58525852 );
58535853 update_add_count += 1;
58545854 },
5855- Err(e) => {
5856- match e {
5857- ChannelError::Ignore(ref msg) => {
5858- log_info!(logger, "Failed to send HTLC with payment_hash {} due to {} in channel {}", &payment_hash, msg, &self.context.channel_id());
5859- // If we fail to send here, then this HTLC should
5860- // be failed backwards. Failing to send here
5861- // indicates that this HTLC may keep being put back
5862- // into the holding cell without ever being
5863- // successfully forwarded/failed/fulfilled, causing
5864- // our counterparty to eventually close on us.
5865- htlcs_to_fail.push((source.clone(), *payment_hash));
5866- },
5867- _ => {
5868- panic!("Got a non-IgnoreError action trying to send holding cell HTLC");
5869- },
5870- }
5855+ Err((_, msg)) => {
5856+ log_info!(logger, "Failed to send HTLC with payment_hash {} due to {} in channel {}", &payment_hash, msg, &self.context.channel_id());
5857+ // If we fail to send here, then this HTLC should be failed
5858+ // backwards. Failing to send here indicates that this HTLC may
5859+ // keep being put back into the holding cell without ever being
5860+ // successfully forwarded/failed/fulfilled, causing our
5861+ // counterparty to eventually close on us.
5862+ htlcs_to_fail.push((source.clone(), *payment_hash));
58715863 }
58725864 }
58735865 None
@@ -8524,22 +8516,19 @@ impl<SP: Deref> FundedChannel<SP> where
85248516 /// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
85258517 /// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
85268518 /// commitment update.
8527- ///
8528- /// `Err`s will only be [`ChannelError::Ignore`].
85298519 pub fn queue_add_htlc<F: Deref, L: Deref>(
85308520 &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
85318521 onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
85328522 blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8533- ) -> Result<(), ChannelError >
8523+ ) -> Result<(), (LocalHTLCFailureReason, String) >
85348524 where F::Target: FeeEstimator, L::Target: Logger
85358525 {
85368526 self
85378527 .send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
85388528 skimmed_fee_msat, blinding_point, fee_estimator, logger)
85398529 .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
85408530 .map_err(|err| {
8541- if let ChannelError::Ignore(_) = err { /* fine */ }
8542- else { debug_assert!(false, "Queueing cannot trigger channel failure"); }
8531+ debug_assert!(err.0.is_temporary(), "Queuing HTLC should return temporary error");
85438532 err
85448533 })
85458534 }
@@ -8559,38 +8548,40 @@ impl<SP: Deref> FundedChannel<SP> where
85598548 /// You MUST call [`Self::send_commitment_no_state_update`] prior to calling any other methods
85608549 /// on this [`FundedChannel`] if `force_holding_cell` is false.
85618550 ///
8562- /// `Err`s will only be [`ChannelError::Ignore`] .
8551+ /// `Err`' s will always be temporary channel failures .
85638552 fn send_htlc<F: Deref, L: Deref>(
85648553 &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
85658554 onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
85668555 skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
85678556 fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8568- ) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError >
8557+ ) -> Result<Option<msgs::UpdateAddHTLC>, (LocalHTLCFailureReason, String) >
85698558 where F::Target: FeeEstimator, L::Target: Logger
85708559 {
85718560 if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
85728561 self.context.channel_state.is_local_shutdown_sent() ||
85738562 self.context.channel_state.is_remote_shutdown_sent()
85748563 {
8575- return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
8564+ return Err((LocalHTLCFailureReason::ChannelNotReady,
8565+ "Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
85768566 }
85778567 let channel_total_msat = self.funding.get_value_satoshis() * 1000;
85788568 if amount_msat > channel_total_msat {
8579- return Err(ChannelError::Ignore(format!("Cannot send amount {}, because it is more than the total value of the channel {}", amount_msat, channel_total_msat)));
8569+ return Err((LocalHTLCFailureReason::AmountExceedsCapacity,
8570+ format!("Cannot send amount {}, because it is more than the total value of the channel {}", amount_msat, channel_total_msat)));
85808571 }
85818572
85828573 if amount_msat == 0 {
8583- return Err(ChannelError::Ignore( "Cannot send 0-msat HTLC".to_owned()));
8574+ return Err((LocalHTLCFailureReason::ZeroAmount, "Cannot send 0-msat HTLC".to_owned()));
85848575 }
85858576
85868577 let available_balances = self.context.get_available_balances(&self.funding, fee_estimator);
85878578 if amount_msat < available_balances.next_outbound_htlc_minimum_msat {
8588- return Err(ChannelError::Ignore( format!("Cannot send less than our next-HTLC minimum - {} msat",
8579+ return Err((LocalHTLCFailureReason::LiquidityMinimum, format!("Cannot send less than our next-HTLC minimum - {} msat",
85898580 available_balances.next_outbound_htlc_minimum_msat)));
85908581 }
85918582
85928583 if amount_msat > available_balances.next_outbound_htlc_limit_msat {
8593- return Err(ChannelError::Ignore( format!("Cannot send more than our next-HTLC maximum - {} msat",
8584+ return Err((LocalHTLCFailureReason::LiquidityMaximum, format!("Cannot send more than our next-HTLC maximum - {} msat",
85948585 available_balances.next_outbound_htlc_limit_msat)));
85958586 }
85968587
@@ -8601,7 +8592,8 @@ impl<SP: Deref> FundedChannel<SP> where
86018592 // disconnected during the time the previous hop was doing the commitment dance we may
86028593 // end up getting here after the forwarding delay. In any case, returning an
86038594 // IgnoreError will get ChannelManager to do the right thing and fail backwards now.
8604- return Err(ChannelError::Ignore("Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
8595+ return Err((LocalHTLCFailureReason::PeerOffline,
8596+ "Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
86058597 }
86068598
86078599 let need_holding_cell = !self.context.channel_state.can_generate_new_commitment();
@@ -8821,8 +8813,8 @@ impl<SP: Deref> FundedChannel<SP> where
88218813 {
88228814 let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
88238815 onion_routing_packet, false, skimmed_fee_msat, None, fee_estimator, logger);
8824- if let Err(e) = &send_res { if let ChannelError::Ignore(_) = e {} else { debug_assert!(false, "Sending cannot trigger channel failure"); } }
8825- match send_res? {
8816+ // All [`LocalHTLCFailureReason`] errors are temporary, so they are [` ChannelError::Ignore`].
8817+ match send_res.map_err(|(_, msg)| ChannelError::Ignore(msg)) ? {
88268818 Some(_) => {
88278819 let monitor_update = self.build_commitment_no_status_check(logger);
88288820 self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
0 commit comments