File tree 2 files changed +8
-13
lines changed
2 files changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -2232,6 +2232,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2232
2232
) -> Result<Option<InteractiveTxMessageSend>, ChannelError>
2233
2233
where ES::Target: EntropySource
2234
2234
{
2235
+ debug_assert!(self.interactive_tx_constructor.is_none());
2236
+
2235
2237
let mut funding_inputs = Vec::new();
2236
2238
mem::swap(&mut self.dual_funding_context.our_funding_inputs, &mut funding_inputs);
2237
2239
@@ -2241,14 +2243,9 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2241
2243
2242
2244
let funding_inputs_prev_outputs = DualFundingChannelContext::txouts_from_input_prev_txs(&funding_inputs)?;
2243
2245
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
-
2251
2246
// 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
2252
2249
let mut funding_outputs = Vec::new();
2253
2250
let funding_output_value_satoshis = self.funding.get_value_satoshis();
2254
2251
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