Skip to content

Commit b497c73

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

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,13 +3979,20 @@ where
39793979
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
39803980
}
39813981

3982+
/// Returns a maximum "sane" fee rate used to reason about our dust exposure.
3983+
/// Will be Some if the `channel_type`'s dust exposure depends on its commitment fee rate, and
3984+
/// None otherwise.
39823985
fn get_dust_exposure_limiting_feerate<F: Deref>(
3983-
&self, fee_estimator: &LowerBoundedFeeEstimator<F>,
3986+
&self, fee_estimator: &LowerBoundedFeeEstimator<F>, channel_type: &ChannelTypeFeatures,
39843987
) -> Option<u32>
39853988
where
39863989
F::Target: FeeEstimator,
39873990
{
3988-
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
3991+
if channel_type.supports_anchor_zero_fee_commitments() {
3992+
None
3993+
} else {
3994+
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
3995+
}
39893996
}
39903997

39913998
/// Returns the maximum configured dust exposure.
@@ -4121,7 +4128,9 @@ where
41214128
return Err(ChannelError::close("Remote side tried to send more than the total value of the channel".to_owned()));
41224129
}
41234130

4124-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4131+
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4132+
&fee_estimator, funding.get_channel_type(),
4133+
);
41254134
let htlc_stats = self.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
41264135
if htlc_stats.pending_inbound_htlcs + 1 > self.holder_max_accepted_htlcs as usize {
41274136
return Err(ChannelError::close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.holder_max_accepted_htlcs)));
@@ -4197,7 +4206,9 @@ where
41974206
F::Target: FeeEstimator,
41984207
{
41994208
// Check that we won't be pushed over our dust exposure limit by the feerate increase.
4200-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4209+
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4210+
&fee_estimator, funding.get_channel_type(),
4211+
);
42014212
let htlc_stats = self.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
42024213
let max_dust_htlc_exposure_msat = self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
42034214
if htlc_stats.on_holder_tx_dust_exposure_msat > max_dust_htlc_exposure_msat {
@@ -4314,7 +4325,9 @@ where
43144325
L::Target: Logger,
43154326
{
43164327
// Before proposing a feerate update, check that we can actually afford the new fee.
4317-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4328+
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4329+
&fee_estimator, funding.get_channel_type(),
4330+
);
43184331
let htlc_stats = self.get_pending_htlc_stats(funding, Some(feerate_per_kw), dust_exposure_limiting_feerate);
43194332
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));
43204333
let holder_balance_msat = stats.local_balance_before_fee_msat - htlc_stats.outbound_holding_cell_msat;
@@ -4763,7 +4776,9 @@ where
47634776
.unwrap_or(self.feerate_per_kw)
47644777
.checked_sub(dust_exposure_limiting_feerate.unwrap_or(0));
47654778

4779+
// Dust exposure is only decoupled from feerate for zero fee commitment channels.
47664780
let is_zero_fee_comm = funding.get_channel_type().supports_anchor_zero_fee_commitments();
4781+
debug_assert_eq!(is_zero_fee_comm, dust_exposure_limiting_feerate.is_none());
47674782
if is_zero_fee_comm {
47684783
debug_assert_eq!(excess_feerate_opt, Some(0));
47694784
}
@@ -4899,7 +4914,9 @@ where
48994914
// Note that we have to handle overflow due to the case mentioned in the docs in general
49004915
// here.
49014916

4902-
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4917+
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
4918+
&fee_estimator, funding.get_channel_type(),
4919+
);
49034920
let htlc_stats = context.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
49044921

49054922
// Subtract any non-HTLC outputs from the local and remote balances
@@ -9191,7 +9208,9 @@ where
91919208
return Err(LocalHTLCFailureReason::ChannelClosed)
91929209
}
91939210

9194-
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
9211+
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(
9212+
&fee_estimator, self.funding.get_channel_type(),
9213+
);
91959214

91969215
core::iter::once(&self.funding)
91979216
.chain(self.pending_funding.iter())

0 commit comments

Comments
 (0)