@@ -7336,6 +7336,8 @@ impl<SP: Deref> FundedChannel<SP> where
73367336 })
73377337 }
73387338
7339+ /// When this function is called, the HTLC is already irrevocably committed to the channel;
7340+ /// this function determines whether to fail the HTLC, or forward / claim it.
73397341 pub fn can_accept_incoming_htlc<F: Deref, L: Deref>(
73407342 &self, msg: &msgs::UpdateAddHTLC, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: L
73417343 ) -> Result<(), (&'static str, u16)>
@@ -7350,33 +7352,19 @@ impl<SP: Deref> FundedChannel<SP> where
73507352 let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
73517353 let htlc_stats = self.context.get_pending_htlc_stats(None, dust_exposure_limiting_feerate);
73527354 let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
7353- let (htlc_timeout_dust_limit, htlc_success_dust_limit) = if self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7354- (0, 0)
7355+ let on_counterparty_tx_dust_htlc_exposure_msat = htlc_stats.on_counterparty_tx_dust_exposure_msat;
7356+ if on_counterparty_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
7357+ // Note that the total dust exposure includes both the dust HTLCs and the excess mining fees of the counterparty commitment transaction
7358+ log_info!(logger, "Cannot accept value that would put our total dust exposure at {} over the limit {} on counterparty commitment tx",
7359+ on_counterparty_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
7360+ return Err(("Exceeded our total dust exposure limit on counterparty commitment tx", 0x1000|7))
7361+ }
7362+ let htlc_success_dust_limit = if self.context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7363+ 0
73557364 } else {
73567365 let dust_buffer_feerate = self.context.get_dust_buffer_feerate(None) as u64;
7357- (dust_buffer_feerate * htlc_timeout_tx_weight(self.context.get_channel_type()) / 1000,
7358- dust_buffer_feerate * htlc_success_tx_weight(self.context.get_channel_type()) / 1000)
7366+ dust_buffer_feerate * htlc_success_tx_weight(self.context.get_channel_type()) / 1000
73597367 };
7360- let exposure_dust_limit_timeout_sats = htlc_timeout_dust_limit + self.context.counterparty_dust_limit_satoshis;
7361- if msg.amount_msat / 1000 < exposure_dust_limit_timeout_sats {
7362- let on_counterparty_tx_dust_htlc_exposure_msat = htlc_stats.on_counterparty_tx_dust_exposure_msat;
7363- if on_counterparty_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
7364- log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx",
7365- on_counterparty_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
7366- return Err(("Exceeded our dust exposure limit on counterparty commitment tx", 0x1000|7))
7367- }
7368- } else {
7369- let htlc_dust_exposure_msat =
7370- per_outbound_htlc_counterparty_commit_tx_fee_msat(self.context.feerate_per_kw, &self.context.channel_type);
7371- let counterparty_tx_dust_exposure =
7372- htlc_stats.on_counterparty_tx_dust_exposure_msat.saturating_add(htlc_dust_exposure_msat);
7373- if counterparty_tx_dust_exposure > max_dust_htlc_exposure_msat {
7374- log_info!(logger, "Cannot accept value that would put our exposure to tx fee dust at {} over the limit {} on counterparty commitment tx",
7375- counterparty_tx_dust_exposure, max_dust_htlc_exposure_msat);
7376- return Err(("Exceeded our tx fee dust exposure limit on counterparty commitment tx", 0x1000|7))
7377- }
7378- }
7379-
73807368 let exposure_dust_limit_success_sats = htlc_success_dust_limit + self.context.holder_dust_limit_satoshis;
73817369 if msg.amount_msat / 1000 < exposure_dust_limit_success_sats {
73827370 let on_holder_tx_dust_htlc_exposure_msat = htlc_stats.on_holder_tx_dust_exposure_msat;
0 commit comments