@@ -987,9 +987,8 @@ struct CommitmentData<'a> {
987987/// A struct gathering stats on a commitment transaction, either local or remote.
988988struct CommitmentStats {
989989 total_fee_sat: u64, // the total fee included in the transaction
990- total_anchors_sat: u64, // the sum of the anchors' amounts
991- local_balance_before_fee_anchors_msat: u64, // local balance before fees and anchors *not* considering dust limits
992- remote_balance_before_fee_anchors_msat: u64, // remote balance before fees and anchors *not* considering dust limits
990+ local_balance_before_fee_msat: u64, // local balance before fees *not* considering dust limits
991+ remote_balance_before_fee_msat: u64, // remote balance before fees *not* considering dust limits
993992}
994993
995994/// Used when calculating whether we or the remote can afford an additional HTLC.
@@ -3773,7 +3772,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37733772 if update_fee {
37743773 debug_assert!(!funding.is_outbound());
37753774 let counterparty_reserve_we_require_msat = funding.holder_selected_channel_reserve_satoshis * 1000;
3776- if commitment_data.stats.remote_balance_before_fee_anchors_msat < commitment_data.stats.total_fee_sat * 1000 + counterparty_reserve_we_require_msat {
3775+ if commitment_data.stats.remote_balance_before_fee_msat < commitment_data.stats.total_fee_sat * 1000 + counterparty_reserve_we_require_msat {
37773776 return Err(ChannelError::close("Funding remote cannot afford proposed new fee".to_owned()));
37783777 }
37793778 }
@@ -3933,11 +3932,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39333932 let total_fee_sat = commit_tx_fee_sat(feerate_per_kw, non_dust_htlc_count, &funding.channel_transaction_parameters.channel_type_features);
39343933 let total_anchors_sat = if funding.channel_transaction_parameters.channel_type_features.supports_anchors_zero_fee_htlc_tx() { ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 };
39353934
3935+ if funding.is_outbound() {
3936+ value_to_self_msat = value_to_self_msat.saturating_sub(total_anchors_sat * 1000);
3937+ } else {
3938+ value_to_remote_msat = value_to_remote_msat.saturating_sub(total_anchors_sat * 1000);
3939+ }
3940+
39363941 CommitmentStats {
39373942 total_fee_sat,
3938- total_anchors_sat,
3939- local_balance_before_fee_anchors_msat: value_to_self_msat,
3940- remote_balance_before_fee_anchors_msat: value_to_remote_msat,
3943+ local_balance_before_fee_msat: value_to_self_msat,
3944+ remote_balance_before_fee_msat: value_to_remote_msat,
39413945 }
39423946 }
39433947
@@ -3964,9 +3968,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39643968 let stats = self.build_commitment_stats(funding, local, generated_by_local);
39653969 let CommitmentStats {
39663970 total_fee_sat,
3967- total_anchors_sat,
3968- local_balance_before_fee_anchors_msat,
3969- remote_balance_before_fee_anchors_msat
3971+ local_balance_before_fee_msat,
3972+ remote_balance_before_fee_msat
39703973 } = stats;
39713974
39723975 let num_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len();
@@ -4037,9 +4040,9 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
40374040 // cover the total fee and the anchors.
40384041
40394042 let (value_to_self, value_to_remote) = if funding.is_outbound() {
4040- ((local_balance_before_fee_anchors_msat / 1000).saturating_sub(total_anchors_sat).saturating_sub( total_fee_sat), remote_balance_before_fee_anchors_msat / 1000)
4043+ ((local_balance_before_fee_msat / 1000).saturating_sub(total_fee_sat), remote_balance_before_fee_msat / 1000)
40414044 } else {
4042- (local_balance_before_fee_anchors_msat / 1000, (remote_balance_before_fee_anchors_msat / 1000).saturating_sub(total_anchors_sat ).saturating_sub(total_fee_sat))
4045+ (local_balance_before_fee_msat / 1000, (remote_balance_before_fee_msat / 1000).saturating_sub(total_fee_sat))
40434046 };
40444047
40454048 let mut to_broadcaster_value_sat = if local { value_to_self } else { value_to_remote };
@@ -6667,7 +6670,7 @@ impl<SP: Deref> FundedChannel<SP> where
66676670 &self.holder_commitment_point.current_point(), true, true, logger,
66686671 );
66696672 let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_data.tx.nondust_htlcs().len() + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, self.funding.get_channel_type()) * 1000;
6670- let holder_balance_msat = commitment_data.stats.local_balance_before_fee_anchors_msat - htlc_stats.outbound_holding_cell_msat;
6673+ let holder_balance_msat = commitment_data.stats.local_balance_before_fee_msat - htlc_stats.outbound_holding_cell_msat;
66716674 if holder_balance_msat < buffer_fee_msat + self.funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
66726675 //TODO: auto-close after a number of failures?
66736676 log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
0 commit comments