Skip to content

Commit f8e98ae

Browse files
committed
Use TxBuilder::get_next_commitment_stats in new_for_outbound_channel
1 parent 5d9b550 commit f8e98ae

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lightning/src/ln/channel.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,16 +3327,19 @@ where
33273327
);
33283328

33293329
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
3330-
let commit_tx_fee_sat = SpecTxBuilder {}.commit_tx_fee_sat(commitment_feerate, MIN_AFFORDABLE_HTLC_COUNT, &channel_type);
3331-
// Subtract any non-HTLC outputs from the local balance
3332-
let (local_balance_before_fee_msat, _) = SpecTxBuilder {}.subtract_non_htlc_outputs(
3333-
true,
3334-
value_to_self_msat,
3335-
push_msat,
3336-
&channel_type,
3337-
);
3338-
if local_balance_before_fee_msat / 1000 < commit_tx_fee_sat {
3339-
return Err(APIError::APIMisuseError{ err: format!("Funding amount ({}) can't even pay fee for initial commitment transaction fee of {}.", value_to_self_msat / 1000, commit_tx_fee_sat) });
3330+
let local = true;
3331+
let is_outbound_from_holder = true;
3332+
let value_to_holder_msat = channel_value_msat - push_msat;
3333+
let dust_exposure_limiting_feerate = if channel_type.supports_anchor_zero_fee_commitments() {
3334+
None
3335+
} else {
3336+
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
3337+
};
3338+
let local_stats = SpecTxBuilder {}.get_next_commitment_stats(local, is_outbound_from_holder, channel_value_satoshis, value_to_holder_msat, &[], MIN_AFFORDABLE_HTLC_COUNT,
3339+
commitment_feerate, dust_exposure_limiting_feerate, MIN_CHAN_DUST_LIMIT_SATOSHIS, &channel_type);
3340+
let local_balance_before_fee_msat = local_stats.holder_balance_before_fee_msat.ok_or(APIError::APIMisuseError { err: format!("Funding amount ({} sats) can't even pay for non-HTLC outputs ie anchors.", value_to_self_msat / 1000) })?;
3341+
if local_balance_before_fee_msat / 1000 < local_stats.commit_tx_fee_sat {
3342+
return Err(APIError::APIMisuseError{ err: format!("Funding amount ({}) can't even pay fee for initial commitment transaction fee of {}.", value_to_self_msat / 1000, local_stats.commit_tx_fee_sat) });
33403343
}
33413344

33423345
let mut secp_ctx = Secp256k1::new();
@@ -3384,7 +3387,7 @@ where
33843387
channel_transaction_parameters: ChannelTransactionParameters {
33853388
holder_pubkeys: pubkeys,
33863389
holder_selected_contest_delay: config.channel_handshake_config.our_to_self_delay,
3387-
is_outbound_from_holder: true,
3390+
is_outbound_from_holder,
33883391
counterparty_parameters: None,
33893392
funding_outpoint: None,
33903393
splice_parent_funding_txid: None,

0 commit comments

Comments
 (0)