@@ -5852,22 +5852,14 @@ impl<SP: Deref> FundedChannel<SP> where
5852
5852
);
5853
5853
update_add_count += 1;
5854
5854
},
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));
5871
5863
}
5872
5864
}
5873
5865
None
@@ -8524,22 +8516,19 @@ impl<SP: Deref> FundedChannel<SP> where
8524
8516
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
8525
8517
/// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
8526
8518
/// commitment update.
8527
- ///
8528
- /// `Err`s will only be [`ChannelError::Ignore`].
8529
8519
pub fn queue_add_htlc<F: Deref, L: Deref>(
8530
8520
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
8531
8521
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
8532
8522
blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8533
- ) -> Result<(), ChannelError >
8523
+ ) -> Result<(), (LocalHTLCFailureReason, String) >
8534
8524
where F::Target: FeeEstimator, L::Target: Logger
8535
8525
{
8536
8526
self
8537
8527
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
8538
8528
skimmed_fee_msat, blinding_point, fee_estimator, logger)
8539
8529
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
8540
8530
.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");
8543
8532
err
8544
8533
})
8545
8534
}
@@ -8559,38 +8548,40 @@ impl<SP: Deref> FundedChannel<SP> where
8559
8548
/// You MUST call [`Self::send_commitment_no_state_update`] prior to calling any other methods
8560
8549
/// on this [`FundedChannel`] if `force_holding_cell` is false.
8561
8550
///
8562
- /// `Err`s will only be [`ChannelError::Ignore`] .
8551
+ /// `Err`' s will always be temporary channel failures .
8563
8552
fn send_htlc<F: Deref, L: Deref>(
8564
8553
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
8565
8554
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
8566
8555
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
8567
8556
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8568
- ) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError >
8557
+ ) -> Result<Option<msgs::UpdateAddHTLC>, (LocalHTLCFailureReason, String) >
8569
8558
where F::Target: FeeEstimator, L::Target: Logger
8570
8559
{
8571
8560
if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
8572
8561
self.context.channel_state.is_local_shutdown_sent() ||
8573
8562
self.context.channel_state.is_remote_shutdown_sent()
8574
8563
{
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()));
8576
8566
}
8577
8567
let channel_total_msat = self.funding.get_value_satoshis() * 1000;
8578
8568
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)));
8580
8571
}
8581
8572
8582
8573
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()));
8584
8575
}
8585
8576
8586
8577
let available_balances = self.context.get_available_balances(&self.funding, fee_estimator);
8587
8578
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",
8589
8580
available_balances.next_outbound_htlc_minimum_msat)));
8590
8581
}
8591
8582
8592
8583
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",
8594
8585
available_balances.next_outbound_htlc_limit_msat)));
8595
8586
}
8596
8587
@@ -8601,7 +8592,8 @@ impl<SP: Deref> FundedChannel<SP> where
8601
8592
// disconnected during the time the previous hop was doing the commitment dance we may
8602
8593
// end up getting here after the forwarding delay. In any case, returning an
8603
8594
// 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()));
8605
8597
}
8606
8598
8607
8599
let need_holding_cell = !self.context.channel_state.can_generate_new_commitment();
@@ -8821,8 +8813,8 @@ impl<SP: Deref> FundedChannel<SP> where
8821
8813
{
8822
8814
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
8823
8815
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)) ? {
8826
8818
Some(_) => {
8827
8819
let monitor_update = self.build_commitment_no_status_check(logger);
8828
8820
self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
0 commit comments