@@ -3036,12 +3036,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3036
3036
debug_assert!(!channel_type.supports_any_optional_bits());
3037
3037
debug_assert!(!channel_type.requires_unknown_bits_from(&channelmanager::provided_channel_type_features(&config)));
3038
3038
3039
- let (commitment_conf_target, anchor_outputs_value_msat) = if channel_type.supports_anchors_zero_fee_htlc_tx() {
3040
- (ConfirmationTarget::AnchorChannelFee, ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000)
3041
- } else {
3042
- (ConfirmationTarget::NonAnchorChannelFee, 0)
3043
- };
3044
- let commitment_feerate = fee_estimator.bounded_sat_per_1000_weight(commitment_conf_target);
3039
+ let (commitment_feerate, anchor_outputs_value_msat) =
3040
+ if channel_type.supports_anchor_zero_fee_commitments() {
3041
+ (0, 0)
3042
+ } else if channel_type.supports_anchors_zero_fee_htlc_tx() {
3043
+ let feerate = fee_estimator
3044
+ .bounded_sat_per_1000_weight(ConfirmationTarget::AnchorChannelFee);
3045
+ (feerate, ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000)
3046
+ } else {
3047
+ let feerate = fee_estimator
3048
+ .bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
3049
+ (feerate, 0)
3050
+ };
3045
3051
3046
3052
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
3047
3053
let commitment_tx_fee = commit_tx_fee_sat(commitment_feerate, MIN_AFFORDABLE_HTLC_COUNT, &channel_type) * 1000;
@@ -5232,6 +5238,15 @@ impl<SP: Deref> FundedChannel<SP> where
5232
5238
feerate_per_kw: u32, cur_feerate_per_kw: Option<u32>, logger: &L
5233
5239
) -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
5234
5240
{
5241
+ if channel_type.supports_anchor_zero_fee_commitments() {
5242
+ if feerate_per_kw != 0 {
5243
+ let err = "Zero Fee Channels must never attempt to use a fee".to_owned();
5244
+ return Err(ChannelError::close(err));
5245
+ } else {
5246
+ return Ok(());
5247
+ }
5248
+ }
5249
+
5235
5250
let lower_limit_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
5236
5251
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
5237
5252
} else {
@@ -13135,6 +13150,19 @@ mod tests {
13135
13150
do_test_supports_channel_type(config, expected_channel_type)
13136
13151
}
13137
13152
13153
+ #[test]
13154
+ fn test_supports_zero_fee_commitments() {
13155
+ // Tests that if both sides support and negotiate `anchors_zero_fee_commitments`, it is
13156
+ // the resulting `channel_type`.
13157
+ let mut config = UserConfig::default();
13158
+ config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true;
13159
+
13160
+ let mut expected_channel_type = ChannelTypeFeatures::empty();
13161
+ expected_channel_type.set_anchor_zero_fee_commitments_required();
13162
+
13163
+ do_test_supports_channel_type(config, expected_channel_type)
13164
+ }
13165
+
13138
13166
fn do_test_supports_channel_type(config: UserConfig, expected_channel_type: ChannelTypeFeatures) {
13139
13167
let secp_ctx = Secp256k1::new();
13140
13168
let fee_estimator = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
@@ -13169,6 +13197,14 @@ mod tests {
13169
13197
13170
13198
assert_eq!(channel_a.funding.get_channel_type(), &expected_channel_type);
13171
13199
assert_eq!(channel_b.funding.get_channel_type(), &expected_channel_type);
13200
+
13201
+ if expected_channel_type.supports_anchor_zero_fee_commitments() {
13202
+ assert_eq!(channel_a.context.feerate_per_kw, 0);
13203
+ assert_eq!(channel_b.context.feerate_per_kw, 0);
13204
+ } else {
13205
+ assert_ne!(channel_a.context.feerate_per_kw, 0);
13206
+ assert_ne!(channel_b.context.feerate_per_kw, 0);
13207
+ }
13172
13208
}
13173
13209
13174
13210
#[test]
0 commit comments