@@ -724,7 +724,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
724
724
725
725
cur_holder_commitment_transaction_number: u64,
726
726
cur_counterparty_commitment_transaction_number: u64,
727
- value_to_self_msat: u64, // Excluding all pending_htlcs, excluding fees
727
+ value_to_self_msat: u64, // Excluding all pending_htlcs, fees, and anchor outputs
728
728
pending_inbound_htlcs: Vec<InboundHTLCOutput>,
729
729
pending_outbound_htlcs: Vec<OutboundHTLCOutput>,
730
730
holding_cell_htlc_updates: Vec<HTLCUpdateAwaitingACK>,
@@ -1673,6 +1673,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1673
1673
1674
1674
let mut available_capacity_msat = outbound_capacity_msat;
1675
1675
1676
+ let anchor_outputs_value_msat = if context.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
1677
+ ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000
1678
+ } else {
1679
+ 0
1680
+ };
1676
1681
if context.is_outbound() {
1677
1682
// We should mind channel commit tx fee when computing how much of the available capacity
1678
1683
// can be used in the next htlc. Mirrors the logic in send_htlc.
@@ -1694,7 +1699,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1694
1699
// We will first subtract the fee as if we were above-dust. Then, if the resulting
1695
1700
// value ends up being below dust, we have this fee available again. In that case,
1696
1701
// match the value to right-below-dust.
1697
- let mut capacity_minus_commitment_fee_msat: i64 = (available_capacity_msat as i64) - (max_reserved_commit_tx_fee_msat as i64);
1702
+ let mut capacity_minus_commitment_fee_msat: i64 = available_capacity_msat as i64 -
1703
+ max_reserved_commit_tx_fee_msat as i64 - anchor_outputs_value_msat as i64;
1698
1704
if capacity_minus_commitment_fee_msat < (real_dust_limit_timeout_sat as i64) * 1000 {
1699
1705
let one_htlc_difference_msat = max_reserved_commit_tx_fee_msat - min_reserved_commit_tx_fee_msat;
1700
1706
debug_assert!(one_htlc_difference_msat != 0);
@@ -1719,7 +1725,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1719
1725
let remote_balance_msat = (context.channel_value_satoshis * 1000 - context.value_to_self_msat)
1720
1726
.saturating_sub(inbound_stats.pending_htlcs_value_msat);
1721
1727
1722
- if remote_balance_msat < max_reserved_commit_tx_fee_msat + holder_selected_chan_reserve_msat {
1728
+ if remote_balance_msat < max_reserved_commit_tx_fee_msat + holder_selected_chan_reserve_msat + anchor_outputs_value_msat {
1723
1729
// If another HTLC's fee would reduce the remote's balance below the reserve limit
1724
1730
// we've selected for them, we can only send dust HTLCs.
1725
1731
available_capacity_msat = cmp::min(available_capacity_msat, real_dust_limit_success_sat * 1000 - 1);
0 commit comments