Skip to content

Commit 96c9887

Browse files
committed
Cleanup calculation of the biggest HTLC value that can be sent next
No functional change.
1 parent be6beaf commit 96c9887

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5124,16 +5124,12 @@ where
51245124
// We will first subtract the fee as if we were above-dust. Then, if the resulting
51255125
// value ends up being below dust, we have this fee available again. In that case,
51265126
// match the value to right-below-dust.
5127-
let mut capacity_minus_commitment_fee_msat: i64 = available_capacity_msat as i64 -
5128-
max_reserved_commit_tx_fee_msat as i64;
5129-
if capacity_minus_commitment_fee_msat < (real_dust_limit_timeout_sat as i64) * 1000 {
5130-
let one_htlc_difference_msat = max_reserved_commit_tx_fee_msat - min_reserved_commit_tx_fee_msat;
5131-
debug_assert!(one_htlc_difference_msat != 0);
5132-
capacity_minus_commitment_fee_msat += one_htlc_difference_msat as i64;
5133-
capacity_minus_commitment_fee_msat = cmp::min(real_dust_limit_timeout_sat as i64 * 1000 - 1, capacity_minus_commitment_fee_msat);
5134-
available_capacity_msat = cmp::max(0, cmp::min(capacity_minus_commitment_fee_msat, available_capacity_msat as i64)) as u64;
5127+
let capacity_minus_max_commitment_fee_msat = available_capacity_msat.saturating_sub(max_reserved_commit_tx_fee_msat);
5128+
if capacity_minus_max_commitment_fee_msat < real_dust_limit_timeout_sat * 1000 {
5129+
let capacity_minus_min_commitment_fee_msat = available_capacity_msat.saturating_sub(min_reserved_commit_tx_fee_msat);
5130+
available_capacity_msat = cmp::min(real_dust_limit_timeout_sat * 1000 - 1, capacity_minus_min_commitment_fee_msat);
51355131
} else {
5136-
available_capacity_msat = capacity_minus_commitment_fee_msat as u64;
5132+
available_capacity_msat = capacity_minus_max_commitment_fee_msat;
51375133
}
51385134
} else {
51395135
// If the channel is inbound (i.e. counterparty pays the fee), we need to make sure

0 commit comments

Comments
 (0)