@@ -1130,10 +1130,8 @@ struct CommitmentData<'a> {
11301130
11311131/// A struct gathering stats on a commitment transaction, either local or remote.
11321132struct CommitmentStats {
1133- feerate_per_kw: u32, // the feerate of the commitment transaction
1134- total_fee_sat: u64, // the total fee included in the transaction
1135- total_anchors_sat: u64, // the sum of the anchors' amounts
1136- broadcaster_dust_limit_sat: u64, // the broadcaster's dust limit
1133+ total_fee_sat: u64, // the total fee included in the transaction
1134+ total_anchors_sat: u64, // the sum of the anchors' amounts
11371135 local_balance_before_fee_anchors_msat: u64, // local balance before fees and anchors *not* considering dust limits
11381136 remote_balance_before_fee_anchors_msat: u64, // remote balance before fees and anchors *not* considering dust limits
11391137}
@@ -4424,17 +4422,8 @@ where
44244422 Ok(())
44254423 }
44264424
4427- /// Builds stats on a potential commitment transaction build, without actually building the
4428- /// commitment transaction. See `build_commitment_transaction` for further docs.
44294425 #[inline]
4430- #[rustfmt::skip]
4431- fn build_commitment_stats(&self, funding: &FundingScope, local: bool, generated_by_local: bool) -> CommitmentStats {
4432- let broadcaster_dust_limit_sat = if local { self.holder_dust_limit_satoshis } else { self.counterparty_dust_limit_satoshis };
4433- let mut non_dust_htlc_count = 0;
4434- let mut remote_htlc_total_msat = 0;
4435- let mut local_htlc_total_msat = 0;
4436- let mut value_to_self_msat_offset = 0;
4437-
4426+ fn get_commitment_feerate(&self, funding: &FundingScope, generated_by_local: bool) -> u32 {
44384427 let mut feerate_per_kw = self.feerate_per_kw;
44394428 if let Some((feerate, update_state)) = self.pending_update_fee {
44404429 if match update_state {
@@ -4448,6 +4437,22 @@ where
44484437 }
44494438 }
44504439
4440+ feerate_per_kw
4441+ }
4442+
4443+ /// Builds stats on a potential commitment transaction build, without actually building the
4444+ /// commitment transaction. See `build_commitment_transaction` for further docs.
4445+ #[inline]
4446+ #[rustfmt::skip]
4447+ fn build_commitment_stats(&self, funding: &FundingScope, local: bool, generated_by_local: bool) -> CommitmentStats {
4448+ let broadcaster_dust_limit_sat = if local { self.holder_dust_limit_satoshis } else { self.counterparty_dust_limit_satoshis };
4449+ let mut non_dust_htlc_count = 0;
4450+ let mut remote_htlc_total_msat = 0;
4451+ let mut local_htlc_total_msat = 0;
4452+ let mut value_to_self_msat_offset = 0;
4453+
4454+ let feerate_per_kw = self.get_commitment_feerate(funding, generated_by_local);
4455+
44514456 for htlc in self.pending_inbound_htlcs.iter() {
44524457 if htlc.state.included_in_commitment(generated_by_local) {
44534458 if !htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type()) {
@@ -4505,10 +4510,8 @@ where
45054510 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 };
45064511
45074512 CommitmentStats {
4508- feerate_per_kw,
45094513 total_fee_sat,
45104514 total_anchors_sat,
4511- broadcaster_dust_limit_sat,
45124515 local_balance_before_fee_anchors_msat: value_to_self_msat,
45134516 remote_balance_before_fee_anchors_msat: value_to_remote_msat,
45144517 }
@@ -4532,12 +4535,13 @@ where
45324535 fn build_commitment_transaction<L: Deref>(&self, funding: &FundingScope, commitment_number: u64, per_commitment_point: &PublicKey, local: bool, generated_by_local: bool, logger: &L) -> CommitmentData
45334536 where L::Target: Logger
45344537 {
4538+ let broadcaster_dust_limit_sat = if local { self.holder_dust_limit_satoshis } else { self.counterparty_dust_limit_satoshis };
4539+ let feerate_per_kw = self.get_commitment_feerate(funding, generated_by_local);
4540+
45354541 let stats = self.build_commitment_stats(funding, local, generated_by_local);
45364542 let CommitmentStats {
4537- feerate_per_kw,
45384543 total_fee_sat,
45394544 total_anchors_sat,
4540- broadcaster_dust_limit_sat,
45414545 local_balance_before_fee_anchors_msat,
45424546 remote_balance_before_fee_anchors_msat
45434547 } = stats;
0 commit comments