File tree Expand file tree Collapse file tree 2 files changed +8
-13
lines changed Expand file tree Collapse file tree 2 files changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -2230,6 +2230,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2230
2230
) -> Result<Option<InteractiveTxMessageSend>, ChannelError>
2231
2231
where ES::Target: EntropySource
2232
2232
{
2233
+ debug_assert!(self.interactive_tx_constructor.is_none());
2234
+
2233
2235
let mut funding_inputs = Vec::new();
2234
2236
mem::swap(&mut self.dual_funding_context.our_funding_inputs, &mut funding_inputs);
2235
2237
@@ -2239,14 +2241,9 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2239
2241
2240
2242
let funding_inputs_prev_outputs = DualFundingChannelContext::txouts_from_input_prev_txs(&funding_inputs)?;
2241
2243
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
-
2249
2244
// 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
2250
2247
let mut funding_outputs = Vec::new();
2251
2248
let funding_output_value_satoshis = self.funding.get_value_satoshis();
2252
2249
let funding_output_script_pubkey = self.funding.get_funding_redeemscript().to_p2wsh();
Original file line number Diff line number Diff line change @@ -1699,19 +1699,17 @@ pub(super) fn calculate_change_output_value(
1699
1699
1700
1700
// Note: in case of additional outputs, they will have to be subtracted here
1701
1701
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 {
1704
1704
// Not enough to cover contribution plus fees
1705
1705
return Err ( AbortReason :: InsufficientFees ) ;
1706
1706
}
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 {
1710
1709
// Enough to cover contribution plus fees, but leftover is below dust limit; no change
1711
1710
Ok ( None )
1712
1711
} else {
1713
1712
// Enough to have over-dust change
1714
- let remaining_value = total_input_satoshis. saturating_sub ( min_contribution_and_fees) ;
1715
1713
Ok ( Some ( remaining_value) )
1716
1714
}
1717
1715
}
You can’t perform that action at this time.
0 commit comments