Skip to content

Commit 5329947

Browse files
carlaKCTheBlueMatt
andcommitted
ln: add channel type awareness to get_dust_exposure_limiting_feerate
Co-authored-by: Matt Corallo <[email protected]>
1 parent 489c6f6 commit 5329947

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,13 +3997,20 @@ where
39973997
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
39983998
}
39993999

4000+
/// Returns a maximum "sane" fee rate used to reason about our dust exposure.
4001+
/// Will be Some if the `channel_type`'s dust exposure depends on its commitment fee rate, and
4002+
/// None otherwise.
40004003
fn get_dust_exposure_limiting_feerate<F: Deref>(
4001-
&self, fee_estimator: &LowerBoundedFeeEstimator<F>,
4004+
&self, fee_estimator: &LowerBoundedFeeEstimator<F>, channel_type: &ChannelTypeFeatures,
40024005
) -> Option<u32>
40034006
where
40044007
F::Target: FeeEstimator,
40054008
{
4006-
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
4009+
if channel_type.supports_anchor_zero_fee_commitments() {
4010+
None
4011+
} else {
4012+
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
4013+
}
40074014
}
40084015

40094016
/// Returns the maximum configured dust exposure.
@@ -4139,7 +4146,9 @@ where
41394146
return Err(ChannelError::close("Remote side tried to send more than the total value of the channel".to_owned()));
41404147
}
41414148

4142-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4149+
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4150+
&fee_estimator, funding.get_channel_type(),
4151+
);
41434152
let htlc_stats = self.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
41444153
if htlc_stats.pending_inbound_htlcs + 1 > self.holder_max_accepted_htlcs as usize {
41454154
return Err(ChannelError::close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.holder_max_accepted_htlcs)));
@@ -4215,7 +4224,9 @@ where
42154224
F::Target: FeeEstimator,
42164225
{
42174226
// Check that we won't be pushed over our dust exposure limit by the feerate increase.
4218-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4227+
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4228+
&fee_estimator, funding.get_channel_type(),
4229+
);
42194230
let htlc_stats = self.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
42204231
let max_dust_htlc_exposure_msat = self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
42214232
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
@@ -4332,7 +4343,9 @@ where
43324343
L::Target: Logger,
43334344
{
43344345
// Before proposing a feerate update, check that we can actually afford the new fee.
4335-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4346+
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4347+
&fee_estimator, funding.get_channel_type(),
4348+
);
43364349
let htlc_stats = self.get_pending_htlc_stats(funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
43374350
let stats = self.build_commitment_stats(funding, true, true, Some(feerate_per_kw), Some(htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize));
43384351
let holder_balance_msat = stats.local_balance_before_fee_msat - htlc_stats.outbound_holding_cell_msat;
@@ -4781,6 +4794,12 @@ where
47814794
.unwrap_or(self.feerate_per_kw)
47824795
.checked_sub(dust_exposure_limiting_feerate.unwrap_or(0));
47834796

4797+
// Dust exposure is only decoupled from feerate for zero fee commitment channels.
4798+
debug_assert!(
4799+
funding.get_channel_type().supports_anchor_zero_fee_commitments()
4800+
== dust_exposure_limiting_feerate.is_none()
4801+
);
4802+
47844803
let extra_nondust_htlc_on_counterparty_tx_dust_exposure_msat = excess_feerate_opt.map(|excess_feerate| {
47854804
let extra_htlc_commit_tx_fee_sat = SpecTxBuilder {}.commit_tx_fee_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1 + on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type());
47864805
let extra_htlc_htlc_tx_fees_sat = chan_utils::htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, funding.get_channel_type());
@@ -4912,7 +4931,9 @@ where
49124931
// Note that we have to handle overflow due to the case mentioned in the docs in general
49134932
// here.
49144933

4915-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4934+
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4935+
&fee_estimator, funding.get_channel_type(),
4936+
);
49164937
let htlc_stats = context.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
49174938

49184939
// Subtract any non-HTLC outputs from the local and remote balances
@@ -9205,7 +9226,9 @@ where
92059226
return Err(LocalHTLCFailureReason::ChannelClosed)
92069227
}
92079228

9208-
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
9229+
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(
9230+
&fee_estimator, self.funding.get_channel_type(),
9231+
);
92099232

92109233
core::iter::once(&self.funding)
92119234
.chain(self.pending_funding.iter())

0 commit comments

Comments
 (0)