@@ -57,7 +57,7 @@ use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Channel
57
57
use crate::chain::transaction::{OutPoint, TransactionData};
58
58
use crate::sign::ecdsa::EcdsaChannelSigner;
59
59
use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Recipient};
60
- use crate::events::{ClosureReason, Event};
60
+ use crate::events::{ClosureReason, Event, HTLCDestination };
61
61
use crate::events::bump_transaction::BASE_INPUT_WEIGHT;
62
62
use crate::routing::gossip::NodeId;
63
63
use crate::util::ser::{Readable, ReadableArgs, TransactionU16LenLimited, Writeable, Writer};
@@ -5888,21 +5888,14 @@ impl<SP: Deref> FundedChannel<SP> where
5888
5888
update_add_count += 1;
5889
5889
},
5890
5890
Err(e) => {
5891
- match e {
5892
- ChannelError::Ignore(ref msg) => {
5893
- log_info!(logger, "Failed to send HTLC with payment_hash {} due to {} in channel {}", &payment_hash, msg, &self.context.channel_id());
5894
- // If we fail to send here, then this HTLC should
5895
- // be failed backwards. Failing to send here
5896
- // indicates that this HTLC may keep being put back
5897
- // into the holding cell without ever being
5898
- // successfully forwarded/failed/fulfilled, causing
5899
- // our counterparty to eventually close on us.
5900
- htlcs_to_fail.push((source.clone(), *payment_hash));
5901
- },
5902
- _ => {
5903
- panic!("Got a non-IgnoreError action trying to send holding cell HTLC");
5904
- },
5905
- }
5891
+ log_info!(logger, "Failed to send HTLC with payment_hash {} due to {:?} in channel {}", &payment_hash, e, &self.context.channel_id());
5892
+ // If we fail to send here, then this HTLC should
5893
+ // be failed backwards. Failing to send here
5894
+ // indicates that this HTLC may keep being put back
5895
+ // into the holding cell without ever being
5896
+ // successfully forwarded/failed/fulfilled, causing
5897
+ // our counterparty to eventually close on us.
5898
+ htlcs_to_fail.push((source.clone(), *payment_hash));
5906
5899
}
5907
5900
}
5908
5901
None
@@ -7580,18 +7573,20 @@ impl<SP: Deref> FundedChannel<SP> where
7580
7573
7581
7574
fn internal_htlc_satisfies_config(
7582
7575
&self, htlc: &msgs::UpdateAddHTLC, amt_to_forward: u64, outgoing_cltv_value: u32, config: &ChannelConfig,
7583
- ) -> Result<(), (&'static str, u16)> {
7576
+ ) -> Result<(), (HTLCDestination, &'static str, u16)> {
7584
7577
let fee = amt_to_forward.checked_mul(config.forwarding_fee_proportional_millionths as u64)
7585
7578
.and_then(|prop_fee| (prop_fee / 1000000).checked_add(config.forwarding_fee_base_msat as u64));
7586
7579
if fee.is_none() || htlc.amount_msat < fee.unwrap() ||
7587
7580
(htlc.amount_msat - fee.unwrap()) < amt_to_forward {
7588
7581
return Err((
7582
+ HTLCDestination::FeeInsufficient,
7589
7583
"Prior hop has deviated from specified fees parameters or origin node has obsolete ones",
7590
7584
0x1000 | 12, // fee_insufficient
7591
7585
));
7592
7586
}
7593
7587
if (htlc.cltv_expiry as u64) < outgoing_cltv_value as u64 + config.cltv_expiry_delta as u64 {
7594
7588
return Err((
7589
+ HTLCDestination::OutgoingCLTVTooClose,
7595
7590
"Forwarding node has tampered with the intended HTLC values or origin node has an obsolete cltv_expiry_delta",
7596
7591
0x1000 | 13, // incorrect_cltv_expiry
7597
7592
));
@@ -7604,7 +7599,7 @@ impl<SP: Deref> FundedChannel<SP> where
7604
7599
/// unsuccessful, falls back to the previous one if one exists.
7605
7600
pub fn htlc_satisfies_config(
7606
7601
&self, htlc: &msgs::UpdateAddHTLC, amt_to_forward: u64, outgoing_cltv_value: u32,
7607
- ) -> Result<(), (&'static str, u16)> {
7602
+ ) -> Result<(), (HTLCDestination, &'static str, u16)> {
7608
7603
self.internal_htlc_satisfies_config(&htlc, amt_to_forward, outgoing_cltv_value, &self.context.config())
7609
7604
.or_else(|err| {
7610
7605
if let Some(prev_config) = self.context.prev_config() {
@@ -7619,13 +7614,13 @@ impl<SP: Deref> FundedChannel<SP> where
7619
7614
/// this function determines whether to fail the HTLC, or forward / claim it.
7620
7615
pub fn can_accept_incoming_htlc<F: Deref, L: Deref>(
7621
7616
&self, msg: &msgs::UpdateAddHTLC, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: L
7622
- ) -> Result<(), (&'static str , u16)>
7617
+ ) -> Result<(), (HTLCDestination , u16)>
7623
7618
where
7624
7619
F::Target: FeeEstimator,
7625
7620
L::Target: Logger
7626
7621
{
7627
7622
if self.context.channel_state.is_local_shutdown_sent() {
7628
- return Err(("Shutdown was already sent" , 0x4000|8))
7623
+ return Err((HTLCDestination::ShutdownSent , 0x4000|8))
7629
7624
}
7630
7625
7631
7626
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
@@ -7636,7 +7631,7 @@ impl<SP: Deref> FundedChannel<SP> where
7636
7631
// Note that the total dust exposure includes both the dust HTLCs and the excess mining fees of the counterparty commitment transaction
7637
7632
log_info!(logger, "Cannot accept value that would put our total dust exposure at {} over the limit {} on counterparty commitment tx",
7638
7633
on_counterparty_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
7639
- return Err(("Exceeded our total dust exposure limit on counterparty commitment tx" , 0x1000|7))
7634
+ return Err((HTLCDestination::DustLimitReached { holder_commitment: false } , 0x1000|7))
7640
7635
}
7641
7636
let htlc_success_dust_limit = if self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7642
7637
0
@@ -7650,7 +7645,7 @@ impl<SP: Deref> FundedChannel<SP> where
7650
7645
if on_holder_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
7651
7646
log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx",
7652
7647
on_holder_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
7653
- return Err(("Exceeded our dust exposure limit on holder commitment tx" , 0x1000|7))
7648
+ return Err((HTLCDestination::DustLimitReached { holder_commitment: true } , 0x1000|7))
7654
7649
}
7655
7650
}
7656
7651
@@ -7688,7 +7683,7 @@ impl<SP: Deref> FundedChannel<SP> where
7688
7683
}
7689
7684
if pending_remote_value_msat.saturating_sub(self.funding.holder_selected_channel_reserve_satoshis * 1000).saturating_sub(anchor_outputs_value_msat) < remote_fee_cost_incl_stuck_buffer_msat {
7690
7685
log_info!(logger, "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", &self.context.channel_id());
7691
- return Err(("Fee spike buffer violation" , 0x1000|7));
7686
+ return Err((HTLCDestination::FeeSpikeBuffer , 0x1000|7));
7692
7687
}
7693
7688
}
7694
7689
@@ -8564,18 +8559,13 @@ impl<SP: Deref> FundedChannel<SP> where
8564
8559
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
8565
8560
onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
8566
8561
blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8567
- ) -> Result<(), ChannelError >
8562
+ ) -> Result<(), HTLCDestination >
8568
8563
where F::Target: FeeEstimator, L::Target: Logger
8569
8564
{
8570
8565
self
8571
8566
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
8572
8567
skimmed_fee_msat, blinding_point, fee_estimator, logger)
8573
8568
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
8574
- .map_err(|err| {
8575
- if let ChannelError::Ignore(_) = err { /* fine */ }
8576
- else { debug_assert!(false, "Queueing cannot trigger channel failure"); }
8577
- err
8578
- })
8579
8569
}
8580
8570
8581
8571
/// Adds a pending outbound HTLC to this channel, note that you probably want
@@ -8599,33 +8589,42 @@ impl<SP: Deref> FundedChannel<SP> where
8599
8589
onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
8600
8590
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
8601
8591
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8602
- ) -> Result<Option<msgs::UpdateAddHTLC>, ChannelError >
8592
+ ) -> Result<Option<msgs::UpdateAddHTLC>, HTLCDestination >
8603
8593
where F::Target: FeeEstimator, L::Target: Logger
8604
8594
{
8605
8595
if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
8606
8596
self.context.channel_state.is_local_shutdown_sent() ||
8607
8597
self.context.channel_state.is_remote_shutdown_sent()
8608
8598
{
8609
- return Err(ChannelError::Ignore("Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()) );
8599
+ return Err(HTLCDestination::ChannelNotReady );
8610
8600
}
8611
8601
let channel_total_msat = self.funding.get_value_satoshis() * 1000;
8612
8602
if amount_msat > channel_total_msat {
8613
- return Err(ChannelError::Ignore(format!("Cannot send amount {}, because it is more than the total value of the channel {}", amount_msat, channel_total_msat)));
8603
+ return Err(HTLCDestination::AmountExceedsChannelValue {
8604
+ amount_msat,
8605
+ channel_value_msat: channel_total_msat,
8606
+ })
8614
8607
}
8615
8608
8616
8609
if amount_msat == 0 {
8617
- return Err(ChannelError::Ignore("Cannot send 0-msat HTLC".to_owned()));
8610
+ return Err(HTLCDestination::HTLCBelowMinimum)
8618
8611
}
8619
8612
8620
8613
let available_balances = self.context.get_available_balances(&self.funding, fee_estimator);
8621
8614
if amount_msat < available_balances.next_outbound_htlc_minimum_msat {
8622
- return Err(ChannelError::Ignore(format!("Cannot send less than our next-HTLC minimum - {} msat",
8623
- available_balances.next_outbound_htlc_minimum_msat)));
8615
+ return Err(HTLCDestination::InvalidPaymentAmount {
8616
+ amount_msat,
8617
+ next_outbound_min_msat: available_balances.next_outbound_htlc_minimum_msat,
8618
+ next_outbound_max_msat: available_balances.next_outbound_htlc_limit_msat,
8619
+ });
8624
8620
}
8625
8621
8626
8622
if amount_msat > available_balances.next_outbound_htlc_limit_msat {
8627
- return Err(ChannelError::Ignore(format!("Cannot send more than our next-HTLC maximum - {} msat",
8628
- available_balances.next_outbound_htlc_limit_msat)));
8623
+ return Err(HTLCDestination::InvalidPaymentAmount {
8624
+ amount_msat,
8625
+ next_outbound_min_msat: available_balances.next_outbound_htlc_minimum_msat,
8626
+ next_outbound_max_msat: available_balances.next_outbound_htlc_limit_msat,
8627
+ });
8629
8628
}
8630
8629
8631
8630
if self.context.channel_state.is_peer_disconnected() {
@@ -8635,7 +8634,7 @@ impl<SP: Deref> FundedChannel<SP> where
8635
8634
// disconnected during the time the previous hop was doing the commitment dance we may
8636
8635
// end up getting here after the forwarding delay. In any case, returning an
8637
8636
// IgnoreError will get ChannelManager to do the right thing and fail backwards now.
8638
- return Err(ChannelError::Ignore("Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
8637
+ return Err(HTLCDestination::ChannelDisabled)
8639
8638
}
8640
8639
8641
8640
let need_holding_cell = !self.context.channel_state.can_generate_new_commitment();
@@ -8850,12 +8849,11 @@ impl<SP: Deref> FundedChannel<SP> where
8850
8849
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
8851
8850
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
8852
8851
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
8853
- ) -> Result<Option<ChannelMonitorUpdate>, ChannelError >
8852
+ ) -> Result<Option<ChannelMonitorUpdate>, HTLCDestination >
8854
8853
where F::Target: FeeEstimator, L::Target: Logger
8855
8854
{
8856
8855
let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
8857
8856
onion_routing_packet, false, skimmed_fee_msat, None, fee_estimator, logger);
8858
- if let Err(e) = &send_res { if let ChannelError::Ignore(_) = e {} else { debug_assert!(false, "Sending cannot trigger channel failure"); } }
8859
8857
match send_res? {
8860
8858
Some(_) => {
8861
8859
let monitor_update = self.build_commitment_no_status_check(logger);
0 commit comments