Skip to content

Commit 83bdbcb

Browse files
committed
Smaller review changes
Remove redundant check on total input amount. Re-word checking against fee and dust limit. Add a debug assert on precondition in begin_intera...()
1 parent 17ed322 commit 83bdbcb

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22302230
) -> Result<Option<InteractiveTxMessageSend>, ChannelError>
22312231
where ES::Target: EntropySource
22322232
{
2233+
debug_assert!(self.interactive_tx_constructor.is_none());
2234+
22332235
let mut funding_inputs = Vec::new();
22342236
mem::swap(&mut self.dual_funding_context.our_funding_inputs, &mut funding_inputs);
22352237

@@ -2239,14 +2241,9 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22392241

22402242
let funding_inputs_prev_outputs = DualFundingChannelContext::txouts_from_input_prev_txs(&funding_inputs)?;
22412243

2242-
let total_input_satoshis: u64 = funding_inputs_prev_outputs.iter().map(|txout| txout.value.to_sat()).sum();
2243-
if total_input_satoshis < self.dual_funding_context.our_funding_satoshis {
2244-
return Err(ChannelError::Warn(format!(
2245-
"Total value of funding inputs must be at least funding amount. It was {} sats", total_input_satoshis,
2246-
)));
2247-
}
2248-
22492244
// Add output for funding tx
2245+
// Note: For the error case when the inputs are insufficient, it will be handled after
2246+
// the `calculate_change_output_value` call below
22502247
let mut funding_outputs = Vec::new();
22512248
let funding_output_value_satoshis = self.funding.get_value_satoshis();
22522249
let funding_output_script_pubkey = self.funding.get_funding_redeemscript().to_p2wsh();

lightning/src/ln/interactivetxs.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,19 +1699,17 @@ pub(super) fn calculate_change_output_value(
16991699

17001700
// Note: in case of additional outputs, they will have to be subtracted here
17011701

1702-
let min_contribution_and_fees = our_contribution.saturating_add(fees_sats);
1703-
if total_input_satoshis < min_contribution_and_fees {
1702+
let total_inputs_less_fees = total_input_satoshis.saturating_sub(fees_sats);
1703+
if total_inputs_less_fees < our_contribution {
17041704
// Not enough to cover contribution plus fees
17051705
return Err(AbortReason::InsufficientFees);
17061706
}
1707-
let min_contribution_and_fees_and_dust =
1708-
min_contribution_and_fees.saturating_add(holder_dust_limit_satoshis);
1709-
if total_input_satoshis < min_contribution_and_fees_and_dust {
1707+
let remaining_value = total_inputs_less_fees.saturating_sub(our_contribution);
1708+
if remaining_value < holder_dust_limit_satoshis {
17101709
// Enough to cover contribution plus fees, but leftover is below dust limit; no change
17111710
Ok(None)
17121711
} else {
17131712
// Enough to have over-dust change
1714-
let remaining_value = total_input_satoshis.saturating_sub(min_contribution_and_fees);
17151713
Ok(Some(remaining_value))
17161714
}
17171715
}

0 commit comments

Comments
 (0)