Skip to content

Commit 027c822

Browse files
committed
Use TxBuilder::get_next_commitment_stats in new_for_outbound_channel
1 parent 90a9f9f commit 027c822

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
@@ -3322,16 +3322,19 @@ where
33223322
);
33233323

33243324
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
3325-
let commit_tx_fee_sat = SpecTxBuilder {}.commit_tx_fee_sat(commitment_feerate, MIN_AFFORDABLE_HTLC_COUNT, &channel_type);
3326-
// Subtract any non-HTLC outputs from the local balance
3327-
let (local_balance_before_fee_msat, _) = SpecTxBuilder {}.subtract_non_htlc_outputs(
3328-
true,
3329-
value_to_self_msat,
3330-
push_msat,
3331-
&channel_type,
3332-
);
3333-
if local_balance_before_fee_msat / 1000 < commit_tx_fee_sat {
3334-
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) });
3325+
let local = true;
3326+
let is_outbound_from_holder = true;
3327+
let value_to_holder_msat = channel_value_msat - push_msat;
3328+
let dust_exposure_limiting_feerate = if channel_type.supports_anchor_zero_fee_commitments() {
3329+
None
3330+
} else {
3331+
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
3332+
};
3333+
let local_stats = SpecTxBuilder {}.get_next_commitment_stats(local, is_outbound_from_holder, channel_value_satoshis, value_to_holder_msat, &[], MIN_AFFORDABLE_HTLC_COUNT,
3334+
commitment_feerate, dust_exposure_limiting_feerate, MIN_CHAN_DUST_LIMIT_SATOSHIS, &channel_type);
3335+
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) })?;
3336+
if local_balance_before_fee_msat / 1000 < local_stats.commit_tx_fee_sat {
3337+
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) });
33353338
}
33363339

33373340
let mut secp_ctx = Secp256k1::new();
@@ -3379,7 +3382,7 @@ where
33793382
channel_transaction_parameters: ChannelTransactionParameters {
33803383
holder_pubkeys: pubkeys,
33813384
holder_selected_contest_delay: config.channel_handshake_config.our_to_self_delay,
3382-
is_outbound_from_holder: true,
3385+
is_outbound_from_holder,
33833386
counterparty_parameters: None,
33843387
funding_outpoint: None,
33853388
splice_parent_funding_txid: None,

0 commit comments

Comments
 (0)