Skip to content

Commit 346c962

Browse files
committed
Fold anchor amounts in get_available_balances_for_scope
1 parent 8dff91c commit 346c962

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4348,18 +4348,19 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43484348
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
43494349
let htlc_stats = context.get_pending_htlc_stats(funding, None, dust_exposure_limiting_feerate);
43504350

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
43534359
.saturating_sub(
43544360
funding.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) * 1000);
43554361

43564362
let mut available_capacity_msat = outbound_capacity_msat;
43574363

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-
};
43634364
if funding.is_outbound() {
43644365
// We should mind channel commit tx fee when computing how much of the available capacity
43654366
// 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 {
43864387
// value ends up being below dust, we have this fee available again. In that case,
43874388
// match the value to right-below-dust.
43884389
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;
43904391
if capacity_minus_commitment_fee_msat < (real_dust_limit_timeout_sat as i64) * 1000 {
43914392
let one_htlc_difference_msat = max_reserved_commit_tx_fee_msat - min_reserved_commit_tx_fee_msat;
43924393
debug_assert!(one_htlc_difference_msat != 0);
@@ -4408,10 +4409,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44084409
let max_reserved_commit_tx_fee_msat = context.next_remote_commit_tx_fee_msat(&funding, Some(htlc_above_dust), None);
44094410

44104411
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 {
44154413
// If another HTLC's fee would reduce the remote's balance below the reserve limit
44164414
// we've selected for them, we can only send dust HTLCs.
44174415
available_capacity_msat = cmp::min(available_capacity_msat, real_dust_limit_success_sat * 1000 - 1);

0 commit comments

Comments
 (0)