@@ -8134,7 +8134,20 @@ impl<SP: Deref> FundedChannel<SP> where
8134
8134
}
8135
8135
8136
8136
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
8137
- let htlc_stats = self.context.get_pending_htlc_stats(&self.funding, None, dust_exposure_limiting_feerate);
8137
+
8138
+ core::iter::once(&self.funding)
8139
+ .chain(self.pending_funding.iter())
8140
+ .try_for_each(|funding| self.can_accept_incoming_htlc_for_funding(funding, msg, dust_exposure_limiting_feerate, &logger))
8141
+ }
8142
+
8143
+ fn can_accept_incoming_htlc_for_funding<L: Deref>(
8144
+ &self, funding: &FundingScope, msg: &msgs::UpdateAddHTLC,
8145
+ dust_exposure_limiting_feerate: u32, logger: &L,
8146
+ ) -> Result<(), LocalHTLCFailureReason>
8147
+ where
8148
+ L::Target: Logger,
8149
+ {
8150
+ let htlc_stats = self.context.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
8138
8151
let max_dust_htlc_exposure_msat = self.context.get_max_dust_htlc_exposure_msat(dust_exposure_limiting_feerate);
8139
8152
let on_counterparty_tx_dust_htlc_exposure_msat = htlc_stats.on_counterparty_tx_dust_exposure_msat;
8140
8153
if on_counterparty_tx_dust_htlc_exposure_msat > max_dust_htlc_exposure_msat {
@@ -8143,11 +8156,11 @@ impl<SP: Deref> FundedChannel<SP> where
8143
8156
on_counterparty_tx_dust_htlc_exposure_msat, max_dust_htlc_exposure_msat);
8144
8157
return Err(LocalHTLCFailureReason::DustLimitCounterparty)
8145
8158
}
8146
- let htlc_success_dust_limit = if self. funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
8159
+ let htlc_success_dust_limit = if funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
8147
8160
0
8148
8161
} else {
8149
8162
let dust_buffer_feerate = self.context.get_dust_buffer_feerate(None) as u64;
8150
- dust_buffer_feerate * htlc_success_tx_weight(self. funding.get_channel_type()) / 1000
8163
+ dust_buffer_feerate * htlc_success_tx_weight(funding.get_channel_type()) / 1000
8151
8164
};
8152
8165
let exposure_dust_limit_success_sats = htlc_success_dust_limit + self.context.holder_dust_limit_satoshis;
8153
8166
if msg.amount_msat / 1000 < exposure_dust_limit_success_sats {
@@ -8159,7 +8172,7 @@ impl<SP: Deref> FundedChannel<SP> where
8159
8172
}
8160
8173
}
8161
8174
8162
- let anchor_outputs_value_msat = if self. funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
8175
+ let anchor_outputs_value_msat = if funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
8163
8176
ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000
8164
8177
} else {
8165
8178
0
@@ -8175,23 +8188,23 @@ impl<SP: Deref> FundedChannel<SP> where
8175
8188
}
8176
8189
8177
8190
let pending_value_to_self_msat =
8178
- self. funding.value_to_self_msat + htlc_stats.pending_inbound_htlcs_value_msat - removed_outbound_total_msat;
8191
+ funding.value_to_self_msat + htlc_stats.pending_inbound_htlcs_value_msat - removed_outbound_total_msat;
8179
8192
let pending_remote_value_msat =
8180
- self. funding.get_value_satoshis() * 1000 - pending_value_to_self_msat;
8193
+ funding.get_value_satoshis() * 1000 - pending_value_to_self_msat;
8181
8194
8182
- if !self. funding.is_outbound() {
8195
+ if !funding.is_outbound() {
8183
8196
// `Some(())` is for the fee spike buffer we keep for the remote. This deviates from
8184
8197
// the spec because the fee spike buffer requirement doesn't exist on the receiver's
8185
8198
// side, only on the sender's. Note that with anchor outputs we are no longer as
8186
8199
// sensitive to fee spikes, so we need to account for them.
8187
8200
//
8188
8201
// A `None` `HTLCCandidate` is used as in this case because we're already accounting for
8189
8202
// the incoming HTLC as it has been fully committed by both sides.
8190
- let mut remote_fee_cost_incl_stuck_buffer_msat = self.context.next_remote_commit_tx_fee_msat(&self. funding, None, Some(()));
8191
- if !self. funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
8203
+ let mut remote_fee_cost_incl_stuck_buffer_msat = self.context.next_remote_commit_tx_fee_msat(funding, None, Some(()));
8204
+ if !funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
8192
8205
remote_fee_cost_incl_stuck_buffer_msat *= FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
8193
8206
}
8194
- if pending_remote_value_msat.saturating_sub(self. funding.holder_selected_channel_reserve_satoshis * 1000).saturating_sub(anchor_outputs_value_msat) < remote_fee_cost_incl_stuck_buffer_msat {
8207
+ if pending_remote_value_msat.saturating_sub(funding.holder_selected_channel_reserve_satoshis * 1000).saturating_sub(anchor_outputs_value_msat) < remote_fee_cost_incl_stuck_buffer_msat {
8195
8208
log_info!(logger, "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required.", &self.context.channel_id());
8196
8209
return Err(LocalHTLCFailureReason::FeeSpikeBuffer);
8197
8210
}
0 commit comments