Skip to content

Commit ebf6b13

Browse files
committed
Delete CommitmentStats.{broadcaster_dust_limit_sat, feerate_per_kw}
In preparation for the upcoming `TxBuilder` API, we remove any fields in `CommitmentStats` which will not be set by `TxBuilder`.
1 parent 098b98e commit ebf6b13

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

lightning/src/ln/channel.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,10 +1130,8 @@ struct CommitmentData<'a> {
11301130

11311131
/// A struct gathering stats on a commitment transaction, either local or remote.
11321132
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
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,31 +4422,39 @@ 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]
44304426
#[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 {
44394428
let mut feerate_per_kw = self.feerate_per_kw;
44404429
if let Some((feerate, update_state)) = self.pending_update_fee {
44414430
if match update_state {
44424431
// Note that these match the inclusion criteria when scanning
44434432
// pending_inbound_htlcs below.
44444433
FeeUpdateState::RemoteAnnounced => { debug_assert!(!funding.is_outbound()); !generated_by_local },
44454434
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 },
44474436
} {
44484437
feerate_per_kw = feerate;
44494438
}
44504439
}
44514440

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+
44524458
for htlc in self.pending_inbound_htlcs.iter() {
44534459
if htlc.state.included_in_commitment(generated_by_local) {
44544460
if !htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_sat, funding.get_channel_type()) {
@@ -4504,10 +4510,8 @@ where
45044510
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 };
45054511

45064512
CommitmentStats {
4507-
feerate_per_kw,
45084513
total_fee_sat,
45094514
total_anchors_sat,
4510-
broadcaster_dust_limit_sat,
45114515
local_balance_before_fee_anchors_msat: value_to_self_msat,
45124516
remote_balance_before_fee_anchors_msat: value_to_remote_msat,
45134517
}
@@ -4531,12 +4535,13 @@ where
45314535
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
45324536
where L::Target: Logger
45334537
{
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+
45344541
let stats = self.build_commitment_stats(funding, local, generated_by_local);
45354542
let CommitmentStats {
4536-
feerate_per_kw,
45374543
total_fee_sat,
45384544
total_anchors_sat,
4539-
broadcaster_dust_limit_sat,
45404545
local_balance_before_fee_anchors_msat,
45414546
remote_balance_before_fee_anchors_msat
45424547
} = stats;

0 commit comments

Comments
 (0)