Skip to content

Commit 90f23b1

Browse files
committed
Use TxBuilder::get_next_commitment_stats in new_for_inbound_channel
1 parent b725ed4 commit 90f23b1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,14 +3467,17 @@ where
34673467
// check if the funder's amount for the initial commitment tx is sufficient
34683468
// for full fee payment plus a few HTLCs to ensure the channel will be useful.
34693469
let funders_amount_msat = open_channel_fields.funding_satoshis * 1000 - msg_push_msat;
3470-
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);
3471-
// Subtract any non-HTLC outputs from the remote balance
3472-
let (_, remote_balance_before_fee_msat) = SpecTxBuilder {}.subtract_non_htlc_outputs(false, value_to_self_msat, funders_amount_msat, &channel_type);
3473-
if remote_balance_before_fee_msat / 1000 < commit_tx_fee_sat {
3474-
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)));
3470+
let local = false;
3471+
let is_outbound_from_holder = false;
3472+
// We are not interested in dust exposure
3473+
let dust_exposure_limiting_feerate = None;
3474+
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,
3475+
open_channel_fields.commitment_feerate_sat_per_1000_weight, dust_exposure_limiting_feerate, open_channel_fields.dust_limit_satoshis, &channel_type).map_err(|()| ChannelError::close(format!("Funding amount ({} sats) can't even pay for non-HTLC outputs ie anchors.", funders_amount_msat / 1000)))?;
3476+
if remote_stats.counterparty_balance_before_fee_msat / 1000 < remote_stats.commit_tx_fee_sat {
3477+
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)));
34753478
}
34763479

3477-
let to_remote_satoshis = remote_balance_before_fee_msat / 1000 - commit_tx_fee_sat;
3480+
let to_remote_satoshis = remote_stats.counterparty_balance_before_fee_msat / 1000 - remote_stats.commit_tx_fee_sat;
34783481
// While it's reasonable for us to not meet the channel reserve initially (if they don't
34793482
// want to push much to us), our counterparty should always have more than our reserve.
34803483
if to_remote_satoshis < holder_selected_channel_reserve_satoshis {
@@ -3550,7 +3553,7 @@ where
35503553
channel_transaction_parameters: ChannelTransactionParameters {
35513554
holder_pubkeys: pubkeys,
35523555
holder_selected_contest_delay: config.channel_handshake_config.our_to_self_delay,
3553-
is_outbound_from_holder: false,
3556+
is_outbound_from_holder,
35543557
counterparty_parameters: Some(CounterpartyChannelTransactionParameters {
35553558
selected_contest_delay: open_channel_fields.to_self_delay,
35563559
pubkeys: counterparty_pubkeys,

0 commit comments

Comments
 (0)