Skip to content

Commit b58d1d0

Browse files
committed
Run fmt on can_accept_incoming_htlc
1 parent e3ab0ea commit b58d1d0

File tree

1 file changed

+59
-27
lines changed

1 file changed

+59
-27
lines changed

lightning/src/ln/channel.rs

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,53 +4604,85 @@ where
46044604
return true;
46054605
}
46064606

4607-
#[rustfmt::skip]
46084607
fn can_accept_incoming_htlc<L: Deref>(
4609-
&self, funding: &FundingScope,
4610-
dust_exposure_limiting_feerate: Option<u32>, logger: &L,
4608+
&self, funding: &FundingScope, dust_exposure_limiting_feerate: Option<u32>, logger: &L,
46114609
) -> Result<(), LocalHTLCFailureReason>
46124610
where
46134611
L::Target: Logger,
46144612
{
46154613
// The fee spike buffer (an additional nondust HTLC) we keep for the remote if the channel
46164614
// is not zero fee. This deviates from the spec because the fee spike buffer requirement
46174615
// doesn't exist on the receiver's side, only on the sender's.
4618-
let fee_spike_buffer_htlc = if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
4619-
0
4620-
} else {
4621-
1
4622-
};
4623-
// Do not include outbound update_add_htlc's in the holding cell, or those which haven't yet been ACK'ed by the counterparty (ie. LocalAnnounced HTLCs)
4616+
let fee_spike_buffer_htlc =
4617+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() { 0 } else { 1 };
4618+
// Do not include outbound update_add_htlc's in the holding cell, or those which haven't yet been ACK'ed
4619+
// by the counterparty (ie. LocalAnnounced HTLCs)
46244620
let include_counterparty_unknown_htlcs = false;
46254621
// A `None` `HTLCCandidate` is used as in this case because we're already accounting for
46264622
// the incoming HTLC as it has been fully committed by both sides.
4627-
let next_local_commitment_stats = self.get_next_local_commitment_stats(funding, None, include_counterparty_unknown_htlcs, fee_spike_buffer_htlc, self.feerate_per_kw, dust_exposure_limiting_feerate);
4628-
let next_remote_commitment_stats = self.get_next_remote_commitment_stats(funding, None, include_counterparty_unknown_htlcs, fee_spike_buffer_htlc, self.feerate_per_kw, dust_exposure_limiting_feerate);
4623+
let next_local_commitment_stats = self.get_next_local_commitment_stats(
4624+
funding,
4625+
None,
4626+
include_counterparty_unknown_htlcs,
4627+
fee_spike_buffer_htlc,
4628+
self.feerate_per_kw,
4629+
dust_exposure_limiting_feerate,
4630+
);
4631+
let next_remote_commitment_stats = self.get_next_remote_commitment_stats(
4632+
funding,
4633+
None,
4634+
include_counterparty_unknown_htlcs,
4635+
fee_spike_buffer_htlc,
4636+
self.feerate_per_kw,
4637+
dust_exposure_limiting_feerate,
4638+
);
46294639

4630-
let max_dust_htlc_exposure_msat = self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
4640+
let max_dust_htlc_exposure_msat =
4641+
self.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
46314642
if next_remote_commitment_stats.dust_exposure_msat > max_dust_htlc_exposure_msat {
4632-
// Note that the total dust exposure includes both the dust HTLCs and the excess mining fees of the counterparty commitment transaction
4633-
log_info!(logger, "Cannot accept value that would put our total dust exposure at {} over the limit {} on counterparty commitment tx",
4634-
next_remote_commitment_stats.dust_exposure_msat, max_dust_htlc_exposure_msat);
4635-
return Err(LocalHTLCFailureReason::DustLimitCounterparty)
4643+
// Note that the total dust exposure includes both the dust HTLCs and the excess mining fees of
4644+
// the counterparty commitment transaction
4645+
log_info!(
4646+
logger,
4647+
"Cannot accept value that would put our total dust exposure at {} over the limit {} on counterparty commitment tx",
4648+
next_remote_commitment_stats.dust_exposure_msat,
4649+
max_dust_htlc_exposure_msat,
4650+
);
4651+
return Err(LocalHTLCFailureReason::DustLimitCounterparty);
46364652
}
46374653
if next_local_commitment_stats.dust_exposure_msat > max_dust_htlc_exposure_msat {
4638-
log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx",
4639-
next_local_commitment_stats.dust_exposure_msat, max_dust_htlc_exposure_msat);
4640-
return Err(LocalHTLCFailureReason::DustLimitHolder)
4654+
log_info!(
4655+
logger,
4656+
"Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx",
4657+
next_local_commitment_stats.dust_exposure_msat,
4658+
max_dust_htlc_exposure_msat,
4659+
);
4660+
return Err(LocalHTLCFailureReason::DustLimitHolder);
46414661
}
46424662

46434663
if !funding.is_outbound() {
4644-
let mut remote_fee_incl_fee_spike_buffer_htlc_msat = next_remote_commitment_stats.commit_tx_fee_sat * 1000;
4645-
// Note that with anchor outputs we are no longer as sensitive to fee spikes, so we don't need to account for them.
4664+
let mut remote_fee_incl_fee_spike_buffer_htlc_msat =
4665+
next_remote_commitment_stats.commit_tx_fee_sat * 1000;
4666+
// Note that with anchor outputs we are no longer as sensitive to fee spikes, so we don't need
4667+
// to account for them.
46464668
if !funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
4647-
remote_fee_incl_fee_spike_buffer_htlc_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
4669+
remote_fee_incl_fee_spike_buffer_htlc_msat *=
4670+
FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
46484671
}
4649-
// We unwrap here; if the HTLC exhausts the counterparty's balance, we should have rejected it at `update_add_htlc`, here the HTLC is already
4650-
// irrevocably committed to the channel.
4651-
let remote_balance_before_fee_msat = next_remote_commitment_stats.counterparty_balance_before_fee_msat.expect("The counterparty's balance before fees should never underflow");
4652-
if remote_balance_before_fee_msat.saturating_sub(funding.holder_selected_channel_reserve_satoshis * 1000) < remote_fee_incl_fee_spike_buffer_htlc_msat {
4653-
log_info!(logger, "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", &self.channel_id());
4672+
// We unwrap here; if the HTLC exhausts the counterparty's balance, we should have rejected it
4673+
// at `update_add_htlc`, here the HTLC is already irrevocably committed to the channel.
4674+
let remote_balance_before_fee_msat = next_remote_commitment_stats
4675+
.counterparty_balance_before_fee_msat
4676+
.expect("The counterparty's balance before fees should never underflow");
4677+
if remote_balance_before_fee_msat
4678+
.saturating_sub(funding.holder_selected_channel_reserve_satoshis * 1000)
4679+
< remote_fee_incl_fee_spike_buffer_htlc_msat
4680+
{
4681+
log_info!(
4682+
logger,
4683+
"Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.",
4684+
&self.channel_id(),
4685+
);
46544686
return Err(LocalHTLCFailureReason::FeeSpikeBuffer);
46554687
}
46564688
}

0 commit comments

Comments
 (0)