@@ -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,6 +4422,33 @@ where
44244422 Ok(())
44254423 }
44264424
4425+ #[inline]
4426+ fn get_commitment_feerate(&self, funding: &FundingScope, generated_by_local: bool) -> u32 {
4427+ let mut feerate_per_kw = self.feerate_per_kw;
4428+ if let Some((feerate, update_state)) = self.pending_update_fee {
4429+ if match update_state {
4430+ // Note that these match the inclusion criteria when scanning
4431+ // pending_inbound_htlcs below.
4432+ FeeUpdateState::RemoteAnnounced => {
4433+ debug_assert!(!funding.is_outbound());
4434+ !generated_by_local
4435+ },
4436+ FeeUpdateState::AwaitingRemoteRevokeToAnnounce => {
4437+ debug_assert!(!funding.is_outbound());
4438+ !generated_by_local
4439+ },
4440+ FeeUpdateState::Outbound => {
4441+ assert!(funding.is_outbound());
4442+ generated_by_local
4443+ },
4444+ } {
4445+ feerate_per_kw = feerate;
4446+ }
4447+ }
4448+
4449+ feerate_per_kw
4450+ }
4451+
44274452 /// Builds stats on a potential commitment transaction build, without actually building the
44284453 /// commitment transaction. See `build_commitment_transaction` for further docs.
44294454 #[inline]
@@ -4435,18 +4460,7 @@ where
44354460 let mut local_htlc_total_msat = 0;
44364461 let mut value_to_self_msat_offset = 0;
44374462
4438- let mut feerate_per_kw = self.feerate_per_kw;
4439- if let Some((feerate, update_state)) = self.pending_update_fee {
4440- if match update_state {
4441- // Note that these match the inclusion criteria when scanning
4442- // pending_inbound_htlcs below.
4443- FeeUpdateState::RemoteAnnounced => { debug_assert!(!funding.is_outbound()); !generated_by_local },
4444- FeeUpdateState::AwaitingRemoteRevokeToAnnounce => { debug_assert!(!funding.is_outbound()); !generated_by_local },
4445- FeeUpdateState::Outbound => { assert!(funding.is_outbound()); generated_by_local },
4446- } {
4447- feerate_per_kw = feerate;
4448- }
4449- }
4463+ let feerate_per_kw = self.get_commitment_feerate(funding, generated_by_local);
44504464
44514465 for htlc in self.pending_inbound_htlcs.iter() {
44524466 if htlc.state.included_in_commitment(generated_by_local) {
@@ -4505,10 +4519,8 @@ where
45054519 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 };
45064520
45074521 CommitmentStats {
4508- feerate_per_kw,
45094522 total_fee_sat,
45104523 total_anchors_sat,
4511- broadcaster_dust_limit_sat,
45124524 local_balance_before_fee_anchors_msat: value_to_self_msat,
45134525 remote_balance_before_fee_anchors_msat: value_to_remote_msat,
45144526 }
@@ -4532,12 +4544,13 @@ where
45324544 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
45334545 where L::Target: Logger
45344546 {
4547+ let broadcaster_dust_limit_sat = if local { self.holder_dust_limit_satoshis } else { self.counterparty_dust_limit_satoshis };
4548+ let feerate_per_kw = self.get_commitment_feerate(funding, generated_by_local);
4549+
45354550 let stats = self.build_commitment_stats(funding, local, generated_by_local);
45364551 let CommitmentStats {
4537- feerate_per_kw,
45384552 total_fee_sat,
45394553 total_anchors_sat,
4540- broadcaster_dust_limit_sat,
45414554 local_balance_before_fee_anchors_msat,
45424555 remote_balance_before_fee_anchors_msat
45434556 } = stats;
0 commit comments