@@ -4348,18 +4348,19 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4348
4348
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
4349
4349
let htlc_stats = context.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
4350
4350
4351
- let outbound_capacity_msat = funding.value_to_self_msat
4352
- .saturating_sub(htlc_stats.pending_outbound_htlcs_value_msat)
4351
+ let (local_balance_msat, remote_balance_msat) = SpecTxBuilder {}.balances_excluding_tx_fee(
4352
+ funding.is_outbound(),
4353
+ funding.get_channel_type(),
4354
+ funding.value_to_self_msat.saturating_sub(htlc_stats.pending_outbound_htlcs_value_msat),
4355
+ (funding.get_value_satoshis() * 1000 - funding.value_to_self_msat).saturating_sub(htlc_stats.pending_inbound_htlcs_value_msat),
4356
+ );
4357
+
4358
+ let outbound_capacity_msat = local_balance_msat
4353
4359
.saturating_sub(
4354
4360
funding.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) * 1000);
4355
4361
4356
4362
let mut available_capacity_msat = outbound_capacity_msat;
4357
4363
4358
- let anchor_outputs_value_msat = if funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
4359
- ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000
4360
- } else {
4361
- 0
4362
- };
4363
4364
if funding.is_outbound() {
4364
4365
// We should mind channel commit tx fee when computing how much of the available capacity
4365
4366
// can be used in the next htlc. Mirrors the logic in send_htlc.
@@ -4386,7 +4387,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4386
4387
// value ends up being below dust, we have this fee available again. In that case,
4387
4388
// match the value to right-below-dust.
4388
4389
let mut capacity_minus_commitment_fee_msat: i64 = available_capacity_msat as i64 -
4389
- max_reserved_commit_tx_fee_msat as i64 - anchor_outputs_value_msat as i64 ;
4390
+ max_reserved_commit_tx_fee_msat as i64;
4390
4391
if capacity_minus_commitment_fee_msat < (real_dust_limit_timeout_sat as i64) * 1000 {
4391
4392
let one_htlc_difference_msat = max_reserved_commit_tx_fee_msat - min_reserved_commit_tx_fee_msat;
4392
4393
debug_assert!(one_htlc_difference_msat != 0);
@@ -4408,10 +4409,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4408
4409
let max_reserved_commit_tx_fee_msat = context.next_remote_commit_tx_fee_msat(&funding, Some(htlc_above_dust), None);
4409
4410
4410
4411
let holder_selected_chan_reserve_msat = funding.holder_selected_channel_reserve_satoshis * 1000;
4411
- let remote_balance_msat = (funding.get_value_satoshis() * 1000 - funding.value_to_self_msat)
4412
- .saturating_sub(htlc_stats.pending_inbound_htlcs_value_msat);
4413
-
4414
- if remote_balance_msat < max_reserved_commit_tx_fee_msat + holder_selected_chan_reserve_msat + anchor_outputs_value_msat {
4412
+ if remote_balance_msat < max_reserved_commit_tx_fee_msat + holder_selected_chan_reserve_msat {
4415
4413
// If another HTLC's fee would reduce the remote's balance below the reserve limit
4416
4414
// we've selected for them, we can only send dust HTLCs.
4417
4415
available_capacity_msat = cmp::min(available_capacity_msat, real_dust_limit_success_sat * 1000 - 1);
0 commit comments