@@ -3077,12 +3077,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3077
3077
debug_assert!(!channel_type.supports_any_optional_bits());
3078
3078
debug_assert!(!channel_type.requires_unknown_bits_from(&channelmanager::provided_channel_type_features(&config)));
3079
3079
3080
- let (commitment_conf_target, anchor_outputs_value_msat) = if channel_type.supports_anchors_zero_fee_htlc_tx() {
3081
- (ConfirmationTarget::AnchorChannelFee, ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000)
3082
- } else {
3083
- (ConfirmationTarget::NonAnchorChannelFee, 0)
3084
- };
3085
- let commitment_feerate = fee_estimator.bounded_sat_per_1000_weight(commitment_conf_target);
3080
+ let (commitment_feerate, anchor_outputs_value_msat) =
3081
+ if channel_type.supports_anchor_zero_fee_commitments() {
3082
+ (0, 0)
3083
+ } else if channel_type.supports_anchors_zero_fee_htlc_tx() {
3084
+ let feerate = fee_estimator
3085
+ .bounded_sat_per_1000_weight(ConfirmationTarget::AnchorChannelFee);
3086
+ (feerate, ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000)
3087
+ } else {
3088
+ let feerate = fee_estimator
3089
+ .bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
3090
+ (feerate, 0)
3091
+ };
3086
3092
3087
3093
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
3088
3094
let commitment_tx_fee = commit_tx_fee_sat(commitment_feerate, MIN_AFFORDABLE_HTLC_COUNT, &channel_type) * 1000;
@@ -5295,6 +5301,15 @@ impl<SP: Deref> FundedChannel<SP> where
5295
5301
feerate_per_kw: u32, cur_feerate_per_kw: Option<u32>, logger: &L
5296
5302
) -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
5297
5303
{
5304
+ if channel_type.supports_anchor_zero_fee_commitments() {
5305
+ if feerate_per_kw != 0 {
5306
+ let err = "Zero Fee Channels must never attempt to use a fee".to_owned();
5307
+ return Err(ChannelError::close(err));
5308
+ } else {
5309
+ return Ok(());
5310
+ }
5311
+ }
5312
+
5298
5313
let lower_limit_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
5299
5314
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
5300
5315
} else {
@@ -13328,6 +13343,34 @@ mod tests {
13328
13343
do_test_supports_channel_type(config, expected_channel_type)
13329
13344
}
13330
13345
13346
+ #[test]
13347
+ fn test_supports_zero_fee_commitments() {
13348
+ // Tests that if both sides support and negotiate `anchors_zero_fee_commitments`, it is
13349
+ // the resulting `channel_type`.
13350
+ let mut config = UserConfig::default();
13351
+ config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true;
13352
+
13353
+ let mut expected_channel_type = ChannelTypeFeatures::empty();
13354
+ expected_channel_type.set_anchor_zero_fee_commitments_required();
13355
+
13356
+ do_test_supports_channel_type(config, expected_channel_type)
13357
+ }
13358
+
13359
+ #[test]
13360
+ fn test_supports_zero_fee_commitments_and_htlc_tx_fee() {
13361
+ // Tests that if both sides support and negotiate `anchors_zero_fee_commitments` and
13362
+ // `anchors_zero_fee_htlc_tx`, the resulting `channel_type` is
13363
+ // `anchors_zero_fee_commitments`.
13364
+ let mut config = UserConfig::default();
13365
+ config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
13366
+ config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true;
13367
+
13368
+ let mut expected_channel_type = ChannelTypeFeatures::empty();
13369
+ expected_channel_type.set_anchor_zero_fee_commitments_required();
13370
+
13371
+ do_test_supports_channel_type(config, expected_channel_type)
13372
+ }
13373
+
13331
13374
fn do_test_supports_channel_type(config: UserConfig, expected_channel_type: ChannelTypeFeatures) {
13332
13375
let secp_ctx = Secp256k1::new();
13333
13376
let fee_estimator = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
@@ -13361,6 +13404,14 @@ mod tests {
13361
13404
13362
13405
assert_eq!(channel_a.funding.get_channel_type(), &expected_channel_type);
13363
13406
assert_eq!(channel_b.funding.get_channel_type(), &expected_channel_type);
13407
+
13408
+ if expected_channel_type.supports_anchor_zero_fee_commitments() {
13409
+ assert_eq!(channel_a.context.feerate_per_kw, 0);
13410
+ assert_eq!(channel_b.context.feerate_per_kw, 0);
13411
+ } else {
13412
+ assert_ne!(channel_a.context.feerate_per_kw, 0);
13413
+ assert_ne!(channel_b.context.feerate_per_kw, 0);
13414
+ }
13364
13415
}
13365
13416
13366
13417
#[test]
0 commit comments