@@ -5739,16 +5739,16 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
5739
5739
let channel_type = Self::get_initial_channel_type(&config, their_features);
5740
5740
debug_assert!(channel_type.is_subset(&channelmanager::provided_channel_type_features(&config)));
5741
5741
5742
- let commitment_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
5743
- ConfirmationTarget::AnchorChannelFee
5742
+ let ( commitment_conf_target, anchor_outputs_value_msat) = if channel_type.supports_anchors_zero_fee_htlc_tx() {
5743
+ ( ConfirmationTarget::AnchorChannelFee, ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000)
5744
5744
} else {
5745
- ConfirmationTarget::NonAnchorChannelFee
5745
+ ( ConfirmationTarget::NonAnchorChannelFee, 0)
5746
5746
};
5747
5747
let commitment_feerate = fee_estimator.bounded_sat_per_1000_weight(commitment_conf_target);
5748
5748
5749
5749
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
5750
5750
let commitment_tx_fee = commit_tx_fee_msat(commitment_feerate, MIN_AFFORDABLE_HTLC_COUNT, &channel_type);
5751
- if value_to_self_msat < commitment_tx_fee {
5751
+ if value_to_self_msat.saturating_sub(anchor_outputs_value_msat) < commitment_tx_fee {
5752
5752
return Err(APIError::APIMisuseError{ err: format!("Funding amount ({}) can't even pay fee for initial commitment transaction fee of {}.", value_to_self_msat / 1000, commitment_tx_fee / 1000) });
5753
5753
}
5754
5754
@@ -6365,13 +6365,18 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
6365
6365
6366
6366
// check if the funder's amount for the initial commitment tx is sufficient
6367
6367
// for full fee payment plus a few HTLCs to ensure the channel will be useful.
6368
+ let anchor_outputs_value = if channel_type.supports_anchors_zero_fee_htlc_tx() {
6369
+ ANCHOR_OUTPUT_VALUE_SATOSHI * 2
6370
+ } else {
6371
+ 0
6372
+ };
6368
6373
let funders_amount_msat = msg.funding_satoshis * 1000 - msg.push_msat;
6369
6374
let commitment_tx_fee = commit_tx_fee_msat(msg.feerate_per_kw, MIN_AFFORDABLE_HTLC_COUNT, &channel_type) / 1000;
6370
- if funders_amount_msat / 1000 < commitment_tx_fee {
6371
- return Err(ChannelError::Close(format!("Funding amount ({} sats) can't even pay fee for initial commitment transaction fee of {} sats.", funders_amount_msat / 1000, commitment_tx_fee)));
6375
+ if ( funders_amount_msat / 1000).saturating_sub(anchor_outputs_value) < commitment_tx_fee {
6376
+ return Err(ChannelError::Close(format!("Funding amount ({} sats) can't even pay fee for initial commitment transaction fee of {} sats.", ( funders_amount_msat / 1000).saturating_sub(anchor_outputs_value) , commitment_tx_fee)));
6372
6377
}
6373
6378
6374
- let to_remote_satoshis = funders_amount_msat / 1000 - commitment_tx_fee;
6379
+ let to_remote_satoshis = funders_amount_msat / 1000 - commitment_tx_fee - anchor_outputs_value ;
6375
6380
// While it's reasonable for us to not meet the channel reserve initially (if they don't
6376
6381
// want to push much to us), our counterparty should always have more than our reserve.
6377
6382
if to_remote_satoshis < holder_selected_channel_reserve_satoshis {
0 commit comments