@@ -3054,14 +3054,21 @@ where
30543054 // check if the funder's amount for the initial commitment tx is sufficient
30553055 // for full fee payment plus a few HTLCs to ensure the channel will be useful.
30563056 let funders_amount_msat = open_channel_fields.funding_satoshis * 1000 - msg_push_msat;
3057- let commit_tx_fee_sat = SpecTxBuilder {}.commit_tx_fee_sat(open_channel_fields.commitment_feerate_sat_per_1000_weight, MIN_AFFORDABLE_HTLC_COUNT, &channel_type);
3058- // Subtract any non-HTLC outputs from the remote balance
3059- let (_, remote_balance_before_fee_msat) = SpecTxBuilder {}.subtract_non_htlc_outputs(false, value_to_self_msat, funders_amount_msat, &channel_type);
3060- if remote_balance_before_fee_msat / 1000 < commit_tx_fee_sat {
3061- return Err(ChannelError::close(format!("Funding amount ({} sats) can't even pay fee for initial commitment transaction fee of {} sats.", funders_amount_msat / 1000, commit_tx_fee_sat)));
3057+ let local = false;
3058+ let is_outbound_from_holder = false;
3059+ let dust_exposure_limiting_feerate = if channel_type.supports_anchor_zero_fee_commitments() {
3060+ None
3061+ } else {
3062+ Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
3063+ };
3064+ let remote_stats = SpecTxBuilder {}.get_next_commitment_stats(local, is_outbound_from_holder, open_channel_fields.funding_satoshis, msg_push_msat, &[], MIN_AFFORDABLE_HTLC_COUNT,
3065+ open_channel_fields.commitment_feerate_sat_per_1000_weight, dust_exposure_limiting_feerate, open_channel_fields.dust_limit_satoshis, &channel_type);
3066+ let remote_balance_before_fee_msat = remote_stats.counterparty_balance_before_fee_msat.ok_or(ChannelError::close(format!("Funding amount ({} sats) can't even pay for non-HTLC outputs ie anchors.", funders_amount_msat / 1000)))?;
3067+ if remote_balance_before_fee_msat / 1000 < remote_stats.commit_tx_fee_sat {
3068+ return Err(ChannelError::close(format!("Funding amount ({} sats) can't even pay fee for initial commitment transaction fee of {} sats.", funders_amount_msat / 1000, remote_stats.commit_tx_fee_sat)));
30623069 }
30633070
3064- let to_remote_satoshis = remote_balance_before_fee_msat / 1000 - commit_tx_fee_sat;
3071+ let to_remote_satoshis = remote_balance_before_fee_msat / 1000 - remote_stats. commit_tx_fee_sat;
30653072 // While it's reasonable for us to not meet the channel reserve initially (if they don't
30663073 // want to push much to us), our counterparty should always have more than our reserve.
30673074 if to_remote_satoshis < holder_selected_channel_reserve_satoshis {
@@ -3137,7 +3144,7 @@ where
31373144 channel_transaction_parameters: ChannelTransactionParameters {
31383145 holder_pubkeys: pubkeys,
31393146 holder_selected_contest_delay: config.channel_handshake_config.our_to_self_delay,
3140- is_outbound_from_holder: false ,
3147+ is_outbound_from_holder,
31413148 counterparty_parameters: Some(CounterpartyChannelTransactionParameters {
31423149 selected_contest_delay: open_channel_fields.to_self_delay,
31433150 pubkeys: counterparty_pubkeys,
0 commit comments