@@ -7303,6 +7303,8 @@ impl<SP: Deref> FundedChannel<SP> where
73037303 })
73047304 }
73057305
7306+ /// When this function is called, the HTLC is already irrevocably committed to the channel;
7307+ /// this function determines whether to fail the HTLC, or forward / claim it.
73067308 pub fn can_accept_incoming_htlc<F: Deref, L: Deref>(
73077309 &self, msg: &msgs::UpdateAddHTLC, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: L
73087310 ) -> Result<(), (&'static str, u16)>
@@ -7317,33 +7319,19 @@ impl<SP: Deref> FundedChannel<SP> where
73177319 let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
73187320 let htlc_stats = self.context.get_pending_htlc_stats(None, dust_exposure_limiting_feerate);
73197321 let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
7320- let (htlc_timeout_dust_limit, htlc_success_dust_limit) = if self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7321- (0, 0)
7322+ let on_counterparty_tx_dust_htlc_exposure_msat = htlc_stats.on_counterparty_tx_dust_exposure_msat;
7323+ if on_counterparty_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
7324+ // Note that the total dust exposure includes both the dust HTLCs and the excess mining fees of the counterparty commitment transaction
7325+ log_info!(logger, "Cannot accept value that would put our total dust exposure at {} over the limit {} on counterparty commitment tx",
7326+ on_counterparty_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
7327+ return Err(("Exceeded our total dust exposure limit on counterparty commitment tx", 0x1000|7))
7328+ }
7329+ let htlc_success_dust_limit = if self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7330+ 0
73227331 } else {
73237332 let dust_buffer_feerate = self.context.get_dust_buffer_feerate(None) as u64;
7324- (dust_buffer_feerate * htlc_timeout_tx_weight(self.context.get_channel_type()) / 1000,
7325- dust_buffer_feerate * htlc_success_tx_weight(self.context.get_channel_type()) / 1000)
7333+ dust_buffer_feerate * htlc_success_tx_weight(self.context.get_channel_type()) / 1000
73267334 };
7327- let exposure_dust_limit_timeout_sats = htlc_timeout_dust_limit + self.context.counterparty_dust_limit_satoshis;
7328- if msg.amount_msat / 1000 < exposure_dust_limit_timeout_sats {
7329- let on_counterparty_tx_dust_htlc_exposure_msat = htlc_stats.on_counterparty_tx_dust_exposure_msat;
7330- if on_counterparty_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
7331- log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx",
7332- on_counterparty_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
7333- return Err(("Exceeded our dust exposure limit on counterparty commitment tx", 0x1000|7))
7334- }
7335- } else {
7336- let htlc_dust_exposure_msat =
7337- per_outbound_htlc_counterparty_commit_tx_fee_msat(self.context.feerate_per_kw, &self.context.channel_type);
7338- let counterparty_tx_dust_exposure =
7339- htlc_stats.on_counterparty_tx_dust_exposure_msat.saturating_add(htlc_dust_exposure_msat);
7340- if counterparty_tx_dust_exposure > max_dust_htlc_exposure_msat {
7341- log_info!(logger, "Cannot accept value that would put our exposure to tx fee dust at {} over the limit {} on counterparty commitment tx",
7342- counterparty_tx_dust_exposure, max_dust_htlc_exposure_msat);
7343- return Err(("Exceeded our tx fee dust exposure limit on counterparty commitment tx", 0x1000|7))
7344- }
7345- }
7346-
73477335 let exposure_dust_limit_success_sats = htlc_success_dust_limit + self.context.holder_dust_limit_satoshis;
73487336 if msg.amount_msat / 1000 < exposure_dust_limit_success_sats {
73497337 let on_holder_tx_dust_htlc_exposure_msat = htlc_stats.on_holder_tx_dust_exposure_msat;
0 commit comments