@@ -3815,24 +3815,24 @@ pub(super) fn maybe_add_funding_change_output<SP: Deref>(
3815
3815
) -> Result<Option<TxOut>, ChannelError> where
3816
3816
SP::Target: SignerProvider,
3817
3817
{
3818
- let our_funding_inputs_weight = funding_inputs_prev_outputs.iter().fold(0u64, |weight, prev_output| {
3818
+ // Add the total estimated weight of our contributed inputs...
3819
+ let mut our_contributed_weight = funding_inputs_prev_outputs.iter().fold(0u64, |weight, prev_output| {
3819
3820
weight.saturating_add(estimate_input_weight(prev_output).to_wu())
3820
- });
3821
- let our_funding_outputs_weight = funding_outputs.iter().fold(0u64, | weight, txout| {
3822
- weight.saturating_add(get_output_weight(&txout.script_pubkey).to_wu())
3823
- });
3824
- let our_contributed_weight = our_funding_outputs_weight.saturating_add(our_funding_inputs_weight);
3825
- let mut fees_sats = fee_for_weight(funding_feerate_sat_per_1000_weight, our_contributed_weight );
3821
+ }).saturating_add(
3822
+ // ... with the total weight of our contributed outputs.
3823
+ funding_outputs.iter().fold(0u64, |weight, txout| {
3824
+ weight.saturating_add(get_output_weight(&txout.script_pubkey).to_wu())
3825
+ })
3826
+ );
3826
3827
3827
3828
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
3828
3829
if is_initiator {
3829
- let common_fees = fee_for_weight(funding_feerate_sat_per_1000_weight, TX_COMMON_FIELDS_WEIGHT);
3830
- fees_sats = fees_sats.saturating_add(common_fees);
3830
+ our_contributed_weight += TX_COMMON_FIELDS_WEIGHT;
3831
3831
}
3832
3832
3833
3833
let remaining_value = total_input_satoshis
3834
3834
.saturating_sub(our_funding_satoshis)
3835
- .saturating_sub(fees_sats );
3835
+ .saturating_sub(fee_for_weight(funding_feerate_sat_per_1000_weight, our_contributed_weight) );
3836
3836
3837
3837
if remaining_value < holder_dust_limit_satoshis {
3838
3838
Ok(None)
0 commit comments