@@ -6736,31 +6736,11 @@ impl<SP: Deref> FundedChannel<SP> where
6736
6736
panic!("Cannot update fee while peer is disconnected/we're awaiting a monitor update (ChannelManager should have caught this)");
6737
6737
}
6738
6738
6739
- // Before proposing a feerate update, check that we can actually afford the new fee.
6740
- let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
6741
- let htlc_stats = self.context.get_pending_htlc_stats(&self.funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
6742
- let commitment_data = self.context.build_commitment_transaction(
6743
- &self.funding, self.holder_commitment_point.transaction_number(),
6744
- &self.holder_commitment_point.current_point(), true, true, logger,
6745
- );
6746
- let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_data.tx.nondust_htlcs().len() + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, self.funding.get_channel_type()) * 1000;
6747
- let holder_balance_msat = commitment_data.stats.local_balance_before_fee_anchors_msat - htlc_stats.outbound_holding_cell_msat;
6748
- if holder_balance_msat < buffer_fee_msat + commitment_data.stats.total_anchors_sat * 1000 + self.funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
6749
- //TODO: auto-close after a number of failures?
6750
- log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
6751
- return None;
6752
- }
6753
-
6754
- // Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed `feerate_per_kw`.
6755
- let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
6756
- if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
6757
- log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
6758
- return None;
6759
- }
6760
- if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
6761
- log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
6762
- return None;
6763
- }
6739
+ core::iter::once(&self.funding)
6740
+ .chain(self.pending_funding.iter())
6741
+ .map(|funding| self.validate_send_update_fee(funding, feerate_per_kw, fee_estimator, logger))
6742
+ .collect::<Result<(), ()>>()
6743
+ .ok()?;
6764
6744
6765
6745
// Some of the checks of `can_generate_new_commitment` have already been done above, but
6766
6746
// it's much more brittle to not use it in favor of checking the remaining flags left, as it
@@ -6783,6 +6763,43 @@ impl<SP: Deref> FundedChannel<SP> where
6783
6763
})
6784
6764
}
6785
6765
6766
+ fn validate_send_update_fee<F: Deref, L: Deref>(
6767
+ &self, funding: &FundingScope, feerate_per_kw: u32,
6768
+ fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
6769
+ ) -> Result<(), ()>
6770
+ where
6771
+ F::Target: FeeEstimator,
6772
+ L::Target: Logger,
6773
+ {
6774
+ // Before proposing a feerate update, check that we can actually afford the new fee.
6775
+ let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
6776
+ let htlc_stats = self.context.get_pending_htlc_stats(funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
6777
+ let commitment_data = self.context.build_commitment_transaction(
6778
+ funding, self.holder_commitment_point.transaction_number(),
6779
+ &self.holder_commitment_point.current_point(), true, true, logger,
6780
+ );
6781
+ let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_data.tx.nondust_htlcs().len() + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, funding.get_channel_type()) * 1000;
6782
+ let holder_balance_msat = commitment_data.stats.local_balance_before_fee_anchors_msat - htlc_stats.outbound_holding_cell_msat;
6783
+ if holder_balance_msat < buffer_fee_msat + commitment_data.stats.total_anchors_sat * 1000 + funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
6784
+ //TODO: auto-close after a number of failures?
6785
+ log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
6786
+ return Err(());
6787
+ }
6788
+
6789
+ // Note, we evaluate pending htlc "preemptive" trimmed-to-dust threshold at the proposed `feerate_per_kw`.
6790
+ let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
6791
+ if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
6792
+ log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
6793
+ return Err(());
6794
+ }
6795
+ if htlc_stats.on_counterparty_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
6796
+ log_debug!(logger, "Cannot afford to send new feerate at {} without infringing max dust htlc exposure", feerate_per_kw);
6797
+ return Err(());
6798
+ }
6799
+
6800
+ Ok(())
6801
+ }
6802
+
6786
6803
/// Removes any uncommitted inbound HTLCs and resets the state of uncommitted outbound HTLC
6787
6804
/// updates, to be used on peer disconnection. After this, update_*_htlc messages need to be
6788
6805
/// resent.
0 commit comments