@@ -3597,24 +3597,24 @@ pub(super) fn maybe_add_funding_change_output<SP: Deref>(
3597
3597
) -> Result<Option<TxOut>, ChannelError> where
3598
3598
SP::Target: SignerProvider,
3599
3599
{
3600
- let our_funding_inputs_weight = funding_inputs_prev_outputs.iter().fold(0u64, |weight, prev_output| {
3600
+ // Add the total estimated weight of our contributed inputs...
3601
+ let mut our_contributed_weight = funding_inputs_prev_outputs.iter().fold(0u64, |weight, prev_output| {
3601
3602
weight.saturating_add(estimate_input_weight(prev_output).to_wu())
3602
- });
3603
- let our_funding_outputs_weight = funding_outputs.iter().fold(0u64, | weight, txout| {
3604
- weight.saturating_add(get_output_weight(&txout.script_pubkey).to_wu())
3605
- });
3606
- let our_contributed_weight = our_funding_outputs_weight.saturating_add(our_funding_inputs_weight);
3607
- let mut fees_sats = fee_for_weight(funding_feerate_sat_per_1000_weight, our_contributed_weight );
3603
+ }).saturating_add(
3604
+ // ... with the total weight of our contributed outputs.
3605
+ funding_outputs.iter().fold(0u64, |weight, txout| {
3606
+ weight.saturating_add(get_output_weight(&txout.script_pubkey).to_wu())
3607
+ })
3608
+ );
3608
3609
3609
3610
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
3610
3611
if is_initiator {
3611
- let common_fees = fee_for_weight(funding_feerate_sat_per_1000_weight, TX_COMMON_FIELDS_WEIGHT);
3612
- fees_sats = fees_sats.saturating_add(common_fees);
3612
+ our_contributed_weight += TX_COMMON_FIELDS_WEIGHT;
3613
3613
}
3614
3614
3615
3615
let remaining_value = total_input_satoshis
3616
3616
.saturating_sub(our_funding_satoshis)
3617
- .saturating_sub(fees_sats );
3617
+ .saturating_sub(fee_for_weight(funding_feerate_sat_per_1000_weight, our_contributed_weight) );
3618
3618
3619
3619
if remaining_value < holder_dust_limit_satoshis {
3620
3620
Ok(None)
0 commit comments