Skip to content

Commit 2d0fd42

Browse files
committed
fixup: correct to_self balance in new for inbound
1 parent 6aa0848 commit 2d0fd42

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,14 +2766,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27662766
return Err(ChannelError::close(format!("Dust limit ({}) too high for the channel reserve we require the remote to keep ({})", open_channel_fields.dust_limit_satoshis, holder_selected_channel_reserve_satoshis)));
27672767
}
27682768

2769+
// v1 channel opens set `our_funding_satoshis` to 0, and v2 channel opens set `msg_push_msat` to 0.
2770+
debug_assert!(our_funding_satoshis == 0 || msg_push_msat == 0);
2771+
let value_to_self_msat = our_funding_satoshis * 1000 + msg_push_msat;
2772+
27692773
// check if the funder's amount for the initial commitment tx is sufficient
27702774
// for full fee payment plus a few HTLCs to ensure the channel will be useful.
27712775
let funders_amount_msat = open_channel_fields.funding_satoshis * 1000 - msg_push_msat;
27722776
let CommitmentStats {
27732777
total_fee_sat,
27742778
local_balance_before_fee_msat: _,
27752779
remote_balance_before_fee_msat,
2776-
} = SpecTxBuilder {}.build_commitment_stats(false, open_channel_fields.commitment_feerate_sat_per_1000_weight, MIN_AFFORDABLE_HTLC_COUNT, msg_push_msat, funders_amount_msat, &channel_type);
2780+
} = SpecTxBuilder {}.build_commitment_stats(false, open_channel_fields.commitment_feerate_sat_per_1000_weight, MIN_AFFORDABLE_HTLC_COUNT, value_to_self_msat, funders_amount_msat, &channel_type);
27772781
if remote_balance_before_fee_msat / 1000 < total_fee_sat {
27782782
return Err(ChannelError::close(format!("Funding amount ({} sats) can't even pay fee for initial commitment transaction fee of {} sats.", remote_balance_before_fee_msat / 1000, total_fee_sat)));
27792783
}
@@ -2832,8 +2836,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
28322836
Some(cmp::max(config.channel_handshake_config.minimum_depth, 1))
28332837
};
28342838

2835-
let value_to_self_msat = our_funding_satoshis * 1000 + msg_push_msat;
2836-
28372839
// TODO(dual_funding): Checks for `funding_feerate_sat_per_1000_weight`?
28382840

28392841
let pubkeys = holder_signer.pubkeys(None, &secp_ctx);

0 commit comments

Comments
 (0)