Skip to content

Commit 555d6ed

Browse files
committed
Don't trim HTLCs when calculating the fee spike commit tx fee
We previously accounted for HTLC trims at the spiked feerate when calculating the commitment transaction fee including the fee spike multiple. This only ensured that the funder of the channel could afford the commitment transaction fee for an exact 2x increase in the feerate. Now, we check that the funder can cover any increase in the feerate between 1x to 2x.
1 parent 901ea21 commit 555d6ed

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

lightning/src/sign/tx_builder.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,18 @@ fn get_next_commitment_stats(
301301
// 2) Now including any additional non-dust HTLCs (usually the fee spike buffer HTLC), does the funder cover
302302
// this bigger transaction fee ? The funder can dip below their dust limit to cover this case, as the
303303
// commitment will have at least one output: the non-dust fee spike buffer HTLC offered by the counterparty.
304+
let nondust_htlc_count = next_commitment_htlcs
305+
.iter()
306+
.filter(|htlc| {
307+
!htlc.is_dust(local, feerate_per_kw, broadcaster_dust_limit_satoshis, channel_type)
308+
})
309+
.count();
310+
// Note here we use the htlc count at the current feerate together with the spiked feerate;
311+
// this makes sure that the holder can afford any fee bump between 1x to 2x from the current
312+
// feerate if the fee spike multiple is included.
304313
let commit_tx_fee_sat = commit_tx_fee_sat(
305314
spiked_feerate,
306-
spiked_nondust_htlc_count + addl_nondust_htlc_count,
315+
nondust_htlc_count + addl_nondust_htlc_count,
307316
channel_type,
308317
);
309318
let (holder_balance_msat, counterparty_balance_msat) = checked_sub_from_funder(

0 commit comments

Comments
 (0)