@@ -1130,10 +1130,8 @@ struct CommitmentData<'a> {
1130
1130
1131
1131
/// A struct gathering stats on a commitment transaction, either local or remote.
1132
1132
struct 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
1137
1135
local_balance_before_fee_anchors_msat: u64, // local balance before fees and anchors *not* considering dust limits
1138
1136
remote_balance_before_fee_anchors_msat: u64, // remote balance before fees and anchors *not* considering dust limits
1139
1137
}
@@ -4424,31 +4422,39 @@ where
4424
4422
Ok(())
4425
4423
}
4426
4424
4427
- /// Builds stats on a potential commitment transaction build, without actually building the
4428
- /// commitment transaction. See `build_commitment_transaction` for further docs.
4429
4425
#[inline]
4430
4426
#[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_claimed_msat = 0;
4437
- let mut value_to_remote_claimed_msat = 0;
4438
-
4427
+ fn get_commitment_feerate(&self, funding: &FundingScope, generated_by_local: bool) -> u32 {
4439
4428
let mut feerate_per_kw = self.feerate_per_kw;
4440
4429
if let Some((feerate, update_state)) = self.pending_update_fee {
4441
4430
if match update_state {
4442
4431
// Note that these match the inclusion criteria when scanning
4443
4432
// pending_inbound_htlcs below.
4444
4433
FeeUpdateState::RemoteAnnounced => { debug_assert!(!funding.is_outbound()); !generated_by_local },
4445
4434
FeeUpdateState::AwaitingRemoteRevokeToAnnounce => { debug_assert!(!funding.is_outbound()); !generated_by_local },
4446
- FeeUpdateState::Outbound => { assert!(funding.is_outbound()); generated_by_local },
4435
+ FeeUpdateState::Outbound => { assert!(funding.is_outbound()); generated_by_local },
4447
4436
} {
4448
4437
feerate_per_kw = feerate;
4449
4438
}
4450
4439
}
4451
4440
4441
+ feerate_per_kw
4442
+ }
4443
+
4444
+ /// Builds stats on a potential commitment transaction build, without actually building the
4445
+ /// commitment transaction. See `build_commitment_transaction` for further docs.
4446
+ #[inline]
4447
+ #[rustfmt::skip]
4448
+ fn build_commitment_stats(&self, funding: &FundingScope, local: bool, generated_by_local: bool) -> CommitmentStats {
4449
+ let broadcaster_dust_limit_sat = if local { self.holder_dust_limit_satoshis } else { self.counterparty_dust_limit_satoshis };
4450
+ let mut non_dust_htlc_count = 0;
4451
+ let mut remote_htlc_total_msat = 0;
4452
+ let mut local_htlc_total_msat = 0;
4453
+ let mut value_to_self_claimed_msat = 0;
4454
+ let mut value_to_remote_claimed_msat = 0;
4455
+
4456
+ let feerate_per_kw = self.get_commitment_feerate(funding, generated_by_local);
4457
+
4452
4458
for htlc in self.pending_inbound_htlcs.iter() {
4453
4459
if htlc.state.included_in_commitment(generated_by_local) {
4454
4460
if !htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type()) {
@@ -4504,10 +4510,8 @@ where
4504
4510
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 };
4505
4511
4506
4512
CommitmentStats {
4507
- feerate_per_kw,
4508
4513
total_fee_sat,
4509
4514
total_anchors_sat,
4510
- broadcaster_dust_limit_sat,
4511
4515
local_balance_before_fee_anchors_msat: value_to_self_msat,
4512
4516
remote_balance_before_fee_anchors_msat: value_to_remote_msat,
4513
4517
}
@@ -4531,12 +4535,13 @@ where
4531
4535
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
4532
4536
where L::Target: Logger
4533
4537
{
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
+
4534
4541
let stats = self.build_commitment_stats(funding, local, generated_by_local);
4535
4542
let CommitmentStats {
4536
- feerate_per_kw,
4537
4543
total_fee_sat,
4538
4544
total_anchors_sat,
4539
- broadcaster_dust_limit_sat,
4540
4545
local_balance_before_fee_anchors_msat,
4541
4546
remote_balance_before_fee_anchors_msat
4542
4547
} = stats;
0 commit comments