@@ -3678,24 +3678,24 @@ pub(super) fn maybe_add_funding_change_output<SP: Deref>(
3678
3678
) -> Result<Option<TxOut>, ChannelError> where
3679
3679
SP::Target: SignerProvider,
3680
3680
{
3681
- let our_funding_inputs_weight = funding_inputs_prev_outputs.iter().fold(0u64, |weight, prev_output| {
3681
+ // Add the total estimated weight of our contributed inputs...
3682
+ let mut our_contributed_weight = funding_inputs_prev_outputs.iter().fold(0u64, |weight, prev_output| {
3682
3683
weight.saturating_add(estimate_input_weight(prev_output).to_wu())
3683
- });
3684
- let our_funding_outputs_weight = funding_outputs.iter().fold(0u64, | weight, txout| {
3685
- weight.saturating_add(get_output_weight(&txout.script_pubkey).to_wu())
3686
- });
3687
- let our_contributed_weight = our_funding_outputs_weight.saturating_add(our_funding_inputs_weight);
3688
- let mut fees_sats = fee_for_weight(funding_feerate_sat_per_1000_weight, our_contributed_weight );
3684
+ }).saturating_add(
3685
+ // ... with the total weight of our contributed outputs.
3686
+ funding_outputs.iter().fold(0u64, |weight, txout| {
3687
+ weight.saturating_add(get_output_weight(&txout.script_pubkey).to_wu())
3688
+ })
3689
+ );
3689
3690
3690
3691
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
3691
3692
if is_initiator {
3692
- let common_fees = fee_for_weight(funding_feerate_sat_per_1000_weight, TX_COMMON_FIELDS_WEIGHT);
3693
- fees_sats = fees_sats.saturating_add(common_fees);
3693
+ our_contributed_weight += TX_COMMON_FIELDS_WEIGHT;
3694
3694
}
3695
3695
3696
3696
let remaining_value = total_input_satoshis
3697
3697
.saturating_sub(our_funding_satoshis)
3698
- .saturating_sub(fees_sats );
3698
+ .saturating_sub(fee_for_weight(funding_feerate_sat_per_1000_weight, our_contributed_weight) );
3699
3699
3700
3700
if remaining_value < holder_dust_limit_satoshis {
3701
3701
Ok(None)
0 commit comments