Skip to content

Commit 90a9f9f

Browse files
committed
Use TxBuilder::get_next_commitment_stats in new_for_inbound_channel
1 parent 50881ca commit 90a9f9f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,14 +3049,21 @@ where
30493049
// check if the funder's amount for the initial commitment tx is sufficient
30503050
// for full fee payment plus a few HTLCs to ensure the channel will be useful.
30513051
let funders_amount_msat = open_channel_fields.funding_satoshis * 1000 - msg_push_msat;
3052-
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);
3053-
// Subtract any non-HTLC outputs from the remote balance
3054-
let (_, remote_balance_before_fee_msat) = SpecTxBuilder {}.subtract_non_htlc_outputs(false, value_to_self_msat, funders_amount_msat, &channel_type);
3055-
if remote_balance_before_fee_msat / 1000 < commit_tx_fee_sat {
3056-
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)));
3052+
let local = false;
3053+
let is_outbound_from_holder = false;
3054+
let dust_exposure_limiting_feerate = if channel_type.supports_anchor_zero_fee_commitments() {
3055+
None
3056+
} else {
3057+
Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::MaximumFeeEstimate))
3058+
};
3059+
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,
3060+
open_channel_fields.commitment_feerate_sat_per_1000_weight, dust_exposure_limiting_feerate, open_channel_fields.dust_limit_satoshis, &channel_type);
3061+
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)))?;
3062+
if remote_balance_before_fee_msat / 1000 < remote_stats.commit_tx_fee_sat {
3063+
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)));
30573064
}
30583065

3059-
let to_remote_satoshis = remote_balance_before_fee_msat / 1000 - commit_tx_fee_sat;
3066+
let to_remote_satoshis = remote_balance_before_fee_msat / 1000 - remote_stats.commit_tx_fee_sat;
30603067
// While it's reasonable for us to not meet the channel reserve initially (if they don't
30613068
// want to push much to us), our counterparty should always have more than our reserve.
30623069
if to_remote_satoshis < holder_selected_channel_reserve_satoshis {
@@ -3132,7 +3139,7 @@ where
31323139
channel_transaction_parameters: ChannelTransactionParameters {
31333140
holder_pubkeys: pubkeys,
31343141
holder_selected_contest_delay: config.channel_handshake_config.our_to_self_delay,
3135-
is_outbound_from_holder: false,
3142+
is_outbound_from_holder,
31363143
counterparty_parameters: Some(CounterpartyChannelTransactionParameters {
31373144
selected_contest_delay: open_channel_fields.to_self_delay,
31383145
pubkeys: counterparty_pubkeys,

0 commit comments

Comments
 (0)