@@ -50,7 +50,7 @@ use crate::ln::chan_utils::{
50
50
#[cfg(splicing)]
51
51
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
52
52
use crate::ln::chan_utils;
53
- use crate::ln::onion_utils::HTLCFailReason;
53
+ use crate::ln::onion_utils::{ HTLCFailReason, LocalHTLCFailureReason, HTLCFailureDetails} ;
54
54
use crate::chain::BestBlock;
55
55
use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBoundedFeeEstimator, fee_for_weight};
56
56
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
@@ -7588,20 +7588,20 @@ impl<SP: Deref> FundedChannel<SP> where
7588
7588
7589
7589
fn internal_htlc_satisfies_config(
7590
7590
&self, htlc: &msgs::UpdateAddHTLC, amt_to_forward: u64, outgoing_cltv_value: u32, config: &ChannelConfig,
7591
- ) -> Result<(), (&'static str, u16 )> {
7591
+ ) -> Result<(), (&'static str, LocalHTLCFailureReason )> {
7592
7592
let fee = amt_to_forward.checked_mul(config.forwarding_fee_proportional_millionths as u64)
7593
7593
.and_then(|prop_fee| (prop_fee / 1000000).checked_add(config.forwarding_fee_base_msat as u64));
7594
7594
if fee.is_none() || htlc.amount_msat < fee.unwrap() ||
7595
7595
(htlc.amount_msat - fee.unwrap()) < amt_to_forward {
7596
7596
return Err((
7597
7597
"Prior hop has deviated from specified fees parameters or origin node has obsolete ones",
7598
- 0x1000 | 12, // fee_insufficient
7598
+ LocalHTLCFailureReason::FeeInsufficient,
7599
7599
));
7600
7600
}
7601
7601
if (htlc.cltv_expiry as u64) < outgoing_cltv_value as u64 + config.cltv_expiry_delta as u64 {
7602
7602
return Err((
7603
7603
"Forwarding node has tampered with the intended HTLC values or origin node has an obsolete cltv_expiry_delta",
7604
- 0x1000 | 13, // incorrect_cltv_expiry
7604
+ LocalHTLCFailureReason::IncorrectCLTVDetla,
7605
7605
));
7606
7606
}
7607
7607
Ok(())
@@ -7612,7 +7612,7 @@ impl<SP: Deref> FundedChannel<SP> where
7612
7612
/// unsuccessful, falls back to the previous one if one exists.
7613
7613
pub fn htlc_satisfies_config(
7614
7614
&self, htlc: &msgs::UpdateAddHTLC, amt_to_forward: u64, outgoing_cltv_value: u32,
7615
- ) -> Result<(), (&'static str, u16 )> {
7615
+ ) -> Result<(), (&'static str, LocalHTLCFailureReason )> {
7616
7616
self.internal_htlc_satisfies_config(&htlc, amt_to_forward, outgoing_cltv_value, &self.context.config())
7617
7617
.or_else(|err| {
7618
7618
if let Some(prev_config) = self.context.prev_config() {
@@ -7627,13 +7627,16 @@ impl<SP: Deref> FundedChannel<SP> where
7627
7627
/// this function determines whether to fail the HTLC, or forward / claim it.
7628
7628
pub fn can_accept_incoming_htlc<F: Deref, L: Deref>(
7629
7629
&self, msg: &msgs::UpdateAddHTLC, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: L
7630
- ) -> Result<(), (&'static str, u16 )>
7630
+ ) -> Result<(), (&'static str, HTLCFailureDetails )>
7631
7631
where
7632
7632
F::Target: FeeEstimator,
7633
7633
L::Target: Logger
7634
7634
{
7635
7635
if self.context.channel_state.is_local_shutdown_sent() {
7636
- return Err(("Shutdown was already sent", 0x4000|8))
7636
+ return Err((
7637
+ "Shutdown was already sent",
7638
+ LocalHTLCFailureReason::ShutdownSent.into(),
7639
+ ))
7637
7640
}
7638
7641
7639
7642
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
@@ -7644,7 +7647,10 @@ impl<SP: Deref> FundedChannel<SP> where
7644
7647
// Note that the total dust exposure includes both the dust HTLCs and the excess mining fees of the counterparty commitment transaction
7645
7648
log_info!(logger, "Cannot accept value that would put our total dust exposure at {} over the limit {} on counterparty commitment tx",
7646
7649
on_counterparty_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
7647
- return Err(("Exceeded our total dust exposure limit on counterparty commitment tx", 0x1000|7))
7650
+ return Err((
7651
+ "Exceeded our total dust exposure limit on counterparty commitment tx.",
7652
+ LocalHTLCFailureReason::DustLimitReached { holder_commitment: false }.into(),
7653
+ ))
7648
7654
}
7649
7655
let htlc_success_dust_limit = if self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7650
7656
0
@@ -7658,7 +7664,10 @@ impl<SP: Deref> FundedChannel<SP> where
7658
7664
if on_holder_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
7659
7665
log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx",
7660
7666
on_holder_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
7661
- return Err(("Exceeded our dust exposure limit on holder commitment tx", 0x1000|7))
7667
+ return Err((
7668
+ "Exceeded our total dust exposure limit on holder commitment tx.",
7669
+ LocalHTLCFailureReason::DustLimitReached { holder_commitment: true }.into(),
7670
+ ))
7662
7671
}
7663
7672
}
7664
7673
@@ -7696,7 +7705,10 @@ impl<SP: Deref> FundedChannel<SP> where
7696
7705
}
7697
7706
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 {
7698
7707
log_info!(logger, "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", &self.context.channel_id());
7699
- return Err(("Fee spike buffer violation", 0x1000|7));
7708
+ return Err((
7709
+ "Fee spike buffer violation.",
7710
+ LocalHTLCFailureReason::FeeSpikeBuffer.into(),
7711
+ ));
7700
7712
}
7701
7713
}
7702
7714
0 commit comments