@@ -4589,39 +4589,69 @@ where
45894589 Ok((holder_commitment_tx, commitment_data.htlcs_included))
45904590 }
45914591
4592- #[rustfmt::skip]
45934592 fn can_send_update_fee<F: Deref, L: Deref>(
4594- &self, funding: &FundingScope, feerate_per_kw: u32, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
4593+ &self, funding: &FundingScope, feerate_per_kw: u32,
4594+ fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
45954595 ) -> bool
45964596 where
45974597 F::Target: FeeEstimator,
45984598 L::Target: Logger,
45994599 {
46004600 // Before proposing a feerate update, check that we can actually afford the new fee.
4601- let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4602- &fee_estimator, funding.get_channel_type(),
4603- );
4604- // Include outbound update_add_htlc's in the holding cell, and those which haven't yet been ACK'ed by the counterparty (ie. LocalAnnounced HTLCs)
4601+ let dust_exposure_limiting_feerate =
4602+ self.get_dust_exposure_limiting_feerate( &fee_estimator, funding.get_channel_type());
4603+ // Include outbound update_add_htlc's in the holding cell, and those which haven't yet been ACK'ed by
4604+ // the counterparty (ie. LocalAnnounced HTLCs)
46054605 let include_counterparty_unknown_htlcs = true;
4606- let next_remote_commitment_stats = self.get_next_remote_commitment_stats(funding, None, include_counterparty_unknown_htlcs, CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, feerate_per_kw, dust_exposure_limiting_feerate);
4607- let holder_balance_msat = next_remote_commitment_stats.holder_balance_before_fee_msat.expect("The holder's balance before fees should never underflow.");
4608- // Note that `stats.commit_tx_fee_sat` accounts for any HTLCs that transition from non-dust to dust under a higher feerate (in the case where HTLC-transactions pay endogenous fees).
4609- if holder_balance_msat < next_remote_commitment_stats.commit_tx_fee_sat * 1000 + funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
4606+ let next_remote_commitment_stats = self.get_next_remote_commitment_stats(
4607+ funding,
4608+ None,
4609+ include_counterparty_unknown_htlcs,
4610+ CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize,
4611+ feerate_per_kw,
4612+ dust_exposure_limiting_feerate,
4613+ );
4614+ let holder_balance_msat = next_remote_commitment_stats
4615+ .holder_balance_before_fee_msat
4616+ .expect("The holder's balance before fees should never underflow.");
4617+ // Note that `stats.commit_tx_fee_sat` accounts for any HTLCs that transition from non-dust to dust
4618+ // under a higher feerate (in the case where HTLC-transactions pay endogenous fees).
4619+ if holder_balance_msat
4620+ < next_remote_commitment_stats.commit_tx_fee_sat * 1000
4621+ + funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000
4622+ {
46104623 //TODO: auto-close after a number of failures?
46114624 log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
46124625 return false;
46134626 }
46144627
4615- // Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed `feerate_per_kw`.
4616- let max_dust_htlc_exposure_msat = self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
4628+ // Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed
4629+ // `feerate_per_kw`.
4630+ let max_dust_htlc_exposure_msat =
4631+ self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
46174632 if next_remote_commitment_stats.dust_exposure_msat > max_dust_htlc_exposure_msat {
4618- log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
4633+ log_debug!(
4634+ logger,
4635+ "Cannot afford to send new feerate at {} without infringing max dust htlc exposure",
4636+ feerate_per_kw,
4637+ );
46194638 return false;
46204639 }
46214640
4622- let next_local_commitment_stats = self.get_next_local_commitment_stats(funding, None, include_counterparty_unknown_htlcs, CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, feerate_per_kw, dust_exposure_limiting_feerate);
4641+ let next_local_commitment_stats = self.get_next_local_commitment_stats(
4642+ funding,
4643+ None,
4644+ include_counterparty_unknown_htlcs,
4645+ CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize,
4646+ feerate_per_kw,
4647+ dust_exposure_limiting_feerate,
4648+ );
46234649 if next_local_commitment_stats.dust_exposure_msat > max_dust_htlc_exposure_msat {
4624- log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
4650+ log_debug!(
4651+ logger,
4652+ "Cannot afford to send new feerate at {} without infringing max dust htlc exposure",
4653+ feerate_per_kw,
4654+ );
46254655 return false;
46264656 }
46274657
0 commit comments