Skip to content

Commit 0e9fa1a

Browse files
committed
Use TxBuilder::get_next_commitment_stats in new_for_outbound_channel
1 parent 90f23b1 commit 0e9fa1a

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,16 +3739,15 @@ where
37393739
);
37403740

37413741
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
3742-
let commit_tx_fee_sat = SpecTxBuilder {}.commit_tx_fee_sat(commitment_feerate, MIN_AFFORDABLE_HTLC_COUNT, &channel_type);
3743-
// Subtract any non-HTLC outputs from the local balance
3744-
let (local_balance_before_fee_msat, _) = SpecTxBuilder {}.subtract_non_htlc_outputs(
3745-
true,
3746-
value_to_self_msat,
3747-
push_msat,
3748-
&channel_type,
3749-
);
3750-
if local_balance_before_fee_msat / 1000 < commit_tx_fee_sat {
3751-
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) });
3742+
let local = true;
3743+
let is_outbound_from_holder = true;
3744+
let value_to_holder_msat = channel_value_msat - push_msat;
3745+
// We are not interested in dust exposure
3746+
let dust_exposure_limiting_feerate = None;
3747+
let local_stats = SpecTxBuilder {}.get_next_commitment_stats(local, is_outbound_from_holder, channel_value_satoshis, value_to_holder_msat, &[], MIN_AFFORDABLE_HTLC_COUNT,
3748+
commitment_feerate, dust_exposure_limiting_feerate, MIN_CHAN_DUST_LIMIT_SATOSHIS, &channel_type).map_err(|()| APIError::APIMisuseError { err: format!("Funding amount ({} sats) can't even pay for non-HTLC outputs ie anchors.", value_to_self_msat / 1000)})?;
3749+
if local_stats.holder_balance_before_fee_msat / 1000 < local_stats.commit_tx_fee_sat {
3750+
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) });
37523751
}
37533752

37543753
let mut secp_ctx = Secp256k1::new();
@@ -3796,7 +3795,7 @@ where
37963795
channel_transaction_parameters: ChannelTransactionParameters {
37973796
holder_pubkeys: pubkeys,
37983797
holder_selected_contest_delay: config.channel_handshake_config.our_to_self_delay,
3799-
is_outbound_from_holder: true,
3798+
is_outbound_from_holder,
38003799
counterparty_parameters: None,
38013800
funding_outpoint: None,
38023801
splice_parent_funding_txid: None,

0 commit comments

Comments
 (0)