Adjust dust exposure due to excess fees for clarity
What changed, and why it matters
This commit is a code clarity and variable-naming refactor in a function that calculates how much money a Lightning channel could lose due to tiny ('dust') transactions plus extra fees. It renames variables, removes an unnecessary mutable parameter, and reorders calculations so the math is easier to follow. The actual arithmetic result appears unchanged, so this is not a security fix.
No security action required. Treat as normal code-quality/maintenance change. Reviewers may optionally verify that the renamed variables do not alter the returned tuple values compared to the previous commit.
Security signals we found
Function deals with fee and dust-exposure calculations in a Lightning commitment transaction
No change to control flow, comparisons, or arithmetic operators
No change to caller sites or public API signatures
Evidence from the diff
In lightning/src/sign/tx_builder.rs, excess_fees_on_counterparty_tx_dust_exposure_msat is refactored. The parameter mut on_counterparty_tx_dust_exposure_msat is replaced with dust_htlc_exposure_msat, and the function now computes both the base dust exposure and the ‘extra HTLC’ dust exposure from that same starting value. The formulas are preserved: commit_tx_fee_sat(..., accepted + offered, ...) and htlc_tx_fees_sat(..., accepted, offered, ...) for the base case, and +1 variants for the extra-HTLC case. The diff shows only renaming and reordering; no constants, conditions, or arithmetic change.
Changed components
lightning/src/sign/tx_builder.rsexcess_fees_on_counterparty_tx_dust_exposure_msatInspect captured patch +7 / −8
diff --git a/lightning/src/sign/tx_builder.rs b/lightning/src/sign/tx_builder.rs
index a704775..cd16b54 100644
--- a/lightning/src/sign/tx_builder.rs
+++ b/lightning/src/sign/tx_builder.rs
@@ -51,21 +51,20 @@ pub(crate) struct NextCommitmentStats {
#[rustfmt::skip]
fn excess_fees_on_counterparty_tx_dust_exposure_msat(
next_commitment_htlcs: &[HTLCAmountDirection], dust_buffer_feerate: u32,
- excess_feerate: u32, counterparty_dust_limit_satoshis: u64, mut on_counterparty_tx_dust_exposure_msat: u64,
+ excess_feerate: u32, counterparty_dust_limit_satoshis: u64, dust_htlc_exposure_msat: u64,
channel_type: &ChannelTypeFeatures,
) -> (u64, u64) {
let on_counterparty_tx_accepted_nondust_htlcs = next_commitment_htlcs.iter().filter(|htlc| htlc.outbound && !htlc.is_dust(false, dust_buffer_feerate, counterparty_dust_limit_satoshis, channel_type)).count();
let on_counterparty_tx_offered_nondust_htlcs = next_commitment_htlcs.iter().filter(|htlc| !htlc.outbound && !htlc.is_dust(false, dust_buffer_feerate, counterparty_dust_limit_satoshis, channel_type)).count();
- let extra_htlc_commit_tx_fee_sat = commit_tx_fee_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1 + on_counterparty_tx_offered_nondust_htlcs, channel_type);
- let extra_htlc_htlc_tx_fees_sat = htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, channel_type);
+ let commitment_fee_sat = commit_tx_fee_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + on_counterparty_tx_offered_nondust_htlcs, channel_type);
+ let second_stage_fees_sat = htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs, on_counterparty_tx_offered_nondust_htlcs, channel_type);
+ let on_counterparty_tx_dust_exposure_msat = dust_htlc_exposure_msat + (commitment_fee_sat + second_stage_fees_sat) * 1000;
- let commit_tx_fee_sat = commit_tx_fee_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + on_counterparty_tx_offered_nondust_htlcs, channel_type);
- let htlc_tx_fees_sat = htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs, on_counterparty_tx_offered_nondust_htlcs, channel_type);
-
- let extra_htlc_dust_exposure_msat = on_counterparty_tx_dust_exposure_msat + (extra_htlc_commit_tx_fee_sat + extra_htlc_htlc_tx_fees_sat) * 1000;
- on_counterparty_tx_dust_exposure_msat += (commit_tx_fee_sat + htlc_tx_fees_sat) * 1000;
+ let extra_htlc_commitment_fee_sat = commit_tx_fee_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1 + on_counterparty_tx_offered_nondust_htlcs, channel_type);
+ let extra_htlc_second_stage_fees_sat = htlc_tx_fees_sat(excess_feerate, on_counterparty_tx_accepted_nondust_htlcs + 1, on_counterparty_tx_offered_nondust_htlcs, channel_type);
+ let extra_htlc_dust_exposure_msat = dust_htlc_exposure_msat + (extra_htlc_commitment_fee_sat + extra_htlc_second_stage_fees_sat) * 1000;
(
on_counterparty_tx_dust_exposure_msat,
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.