@@ -56,6 +56,7 @@ use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBounde
5656use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
5757use crate::chain::transaction::{OutPoint, TransactionData};
5858use crate::sign::ecdsa::EcdsaChannelSigner;
59+ use crate::sign::tx_builder::{SpecTxBuilder, TxBuilder};
5960use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Recipient};
6061use crate::events::{ClosureReason, Event};
6162use crate::events::bump_transaction::BASE_INPUT_WEIGHT;
@@ -985,10 +986,10 @@ struct CommitmentData<'a> {
985986}
986987
987988/// A struct gathering stats on a commitment transaction, either local or remote.
988- struct CommitmentStats {
989- total_fee_sat: u64, // the total fee included in the transaction
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
989+ pub(crate) struct CommitmentStats {
990+ pub(crate) total_fee_sat: u64, // the total fee included in the transaction
991+ pub(crate) local_balance_before_fee_msat: u64, // local balance before fees *not* considering dust limits
992+ pub(crate) remote_balance_before_fee_msat: u64, // remote balance before fees *not* considering dust limits
992993}
993994
994995/// Used when calculating whether we or the remote can afford an additional HTLC.
@@ -3869,7 +3870,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38693870 #[inline]
38703871 fn build_commitment_stats(&self, funding: &FundingScope, local: bool, generated_by_local: bool) -> CommitmentStats {
38713872 let broadcaster_dust_limit_sat = if local { self.holder_dust_limit_satoshis } else { self.counterparty_dust_limit_satoshis };
3872- let mut non_dust_htlc_count = 0;
3873+ let mut nondust_htlc_count = 0;
38733874 let mut remote_htlc_total_msat = 0;
38743875 let mut local_htlc_total_msat = 0;
38753876 let mut value_to_self_msat_offset = 0;
@@ -3879,7 +3880,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38793880 for htlc in self.pending_inbound_htlcs.iter() {
38803881 if htlc.state.included_in_commitment(generated_by_local) {
38813882 if !htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type()) {
3882- non_dust_htlc_count += 1;
3883+ nondust_htlc_count += 1;
38833884 }
38843885 remote_htlc_total_msat += htlc.amount_msat;
38853886 } else {
@@ -3892,7 +3893,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38923893 for htlc in self.pending_outbound_htlcs.iter() {
38933894 if htlc.state.included_in_commitment(generated_by_local) {
38943895 if !htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type()) {
3895- non_dust_htlc_count += 1;
3896+ nondust_htlc_count += 1;
38963897 }
38973898 local_htlc_total_msat += htlc.amount_msat;
38983899 } else {
@@ -3928,20 +3929,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39283929 debug_assert!(broadcaster_max_commitment_tx_output.1 <= value_to_remote_msat || value_to_remote_msat / 1000 >= funding.holder_selected_channel_reserve_satoshis);
39293930 broadcaster_max_commitment_tx_output.1 = cmp::max(broadcaster_max_commitment_tx_output.1, value_to_remote_msat);
39303931 }
3931-
3932- let total_fee_sat = commit_tx_fee_sat(feerate_per_kw, non_dust_htlc_count, &funding.channel_transaction_parameters.channel_type_features);
3933- 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 };
3934-
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- }
3932+ let builder = SpecTxBuilder {};
3933+ let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = builder.balances_excluding_tx_fee(
3934+ funding.is_outbound(),
3935+ &funding.channel_transaction_parameters.channel_type_features,
3936+ value_to_self_msat,
3937+ value_to_remote_msat,
3938+ );
39403939
39413940 CommitmentStats {
3942- total_fee_sat,
3943- local_balance_before_fee_msat: value_to_self_msat ,
3944- remote_balance_before_fee_msat: value_to_remote_msat ,
3941+ total_fee_sat: builder.commit_tx_fee_sat(feerate_per_kw, nondust_htlc_count, &funding.channel_transaction_parameters.channel_type_features) ,
3942+ local_balance_before_fee_msat,
3943+ remote_balance_before_fee_msat,
39453944 }
39463945 }
39473946
0 commit comments