@@ -6142,22 +6142,14 @@ impl<SP: Deref> FundedChannel<SP> where
6142
6142
);
6143
6143
update_add_count += 1;
6144
6144
},
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));
6161
6153
}
6162
6154
}
6163
6155
None
@@ -8819,22 +8811,19 @@ impl<SP: Deref> FundedChannel<SP> where
8819
8811
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
8820
8812
/// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
8821
8813
/// commitment update.
8822
- ///
8823
- /// `Err`s will only be [`ChannelError::Ignore`].
8824
8814
pub fn queue_add_htlc<F: Deref, L: Deref>(
8825
8815
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
8826
8816
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
8827
8817
blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8828
- ) -> Result<(), ChannelError >
8818
+ ) -> Result<(), (LocalHTLCFailureReason, String) >
8829
8819
where F::Target: FeeEstimator, L::Target: Logger
8830
8820
{
8831
8821
self
8832
8822
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
8833
8823
skimmed_fee_msat, blinding_point, fee_estimator, logger)
8834
8824
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
8835
8825
.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");
8838
8827
err
8839
8828
})
8840
8829
}
@@ -8854,38 +8843,40 @@ impl<SP: Deref> FundedChannel<SP> where
8854
8843
/// You MUST call [`Self::send_commitment_no_state_update`] prior to calling any other methods
8855
8844
/// on this [`FundedChannel`] if `force_holding_cell` is false.
8856
8845
///
8857
- /// `Err`s will only be [`ChannelError::Ignore`] .
8846
+ /// `Err`' s will always be temporary channel failures .
8858
8847
fn send_htlc<F: Deref, L: Deref>(
8859
8848
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
8860
8849
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
8861
8850
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
8862
8851
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8863
- ) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError >
8852
+ ) -> Result<Option<msgs::UpdateAddHTLC>, (LocalHTLCFailureReason, String) >
8864
8853
where F::Target: FeeEstimator, L::Target: Logger
8865
8854
{
8866
8855
if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
8867
8856
self.context.channel_state.is_local_shutdown_sent() ||
8868
8857
self.context.channel_state.is_remote_shutdown_sent()
8869
8858
{
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()));
8871
8861
}
8872
8862
let channel_total_msat = self.funding.get_value_satoshis() * 1000;
8873
8863
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)));
8875
8866
}
8876
8867
8877
8868
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()));
8879
8870
}
8880
8871
8881
8872
let available_balances = self.get_available_balances(fee_estimator);
8882
8873
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",
8884
8875
available_balances.next_outbound_htlc_minimum_msat)));
8885
8876
}
8886
8877
8887
8878
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",
8889
8880
available_balances.next_outbound_htlc_limit_msat)));
8890
8881
}
8891
8882
@@ -8896,7 +8887,8 @@ impl<SP: Deref> FundedChannel<SP> where
8896
8887
// disconnected during the time the previous hop was doing the commitment dance we may
8897
8888
// end up getting here after the forwarding delay. In any case, returning an
8898
8889
// 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()));
8900
8892
}
8901
8893
8902
8894
let need_holding_cell = !self.context.channel_state.can_generate_new_commitment();
@@ -9185,8 +9177,8 @@ impl<SP: Deref> FundedChannel<SP> where
9185
9177
{
9186
9178
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
9187
9179
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)) ? {
9190
9182
Some(_) => {
9191
9183
let monitor_update = self.build_commitment_no_status_check(logger);
9192
9184
self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
0 commit comments