Skip to content

Commit c7e9cc5

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 3321d10 commit c7e9cc5

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lightning/src/ln/channel.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22322232
) -> Result<Option<InteractiveTxMessageSend>, ChannelError>
22332233
where ES::Target: EntropySource
22342234
{
2235+
debug_assert!(self.interactive_tx_constructor.is_none());
2236+
22352237
let mut funding_inputs = Vec::new();
22362238
mem::swap(&mut self.dual_funding_context.our_funding_inputs, &mut funding_inputs);
22372239

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

22422244
let funding_inputs_prev_outputs = DualFundingChannelContext::txouts_from_input_prev_txs(&funding_inputs)?;
22432245

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

lightning/src/ln/interactivetxs.rs

+4-6
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)