@@ -3077,12 +3077,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30773077 debug_assert!(!channel_type.supports_any_optional_bits());
30783078 debug_assert!(!channel_type.requires_unknown_bits_from(&channelmanager::provided_channel_type_features(&config)));
30793079
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+ };
30863092
30873093 let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
30883094 let commitment_tx_fee = commit_tx_fee_sat(commitment_feerate, MIN_AFFORDABLE_HTLC_COUNT, &channel_type) * 1000;
@@ -5297,6 +5303,15 @@ impl<SP: Deref> FundedChannel<SP> where
52975303 feerate_per_kw: u32, cur_feerate_per_kw: Option<u32>, logger: &L
52985304 ) -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
52995305 {
5306+ if channel_type.supports_anchor_zero_fee_commitments() {
5307+ if feerate_per_kw != 0 {
5308+ let err = "Zero Fee Channels must never attempt to use a fee".to_owned();
5309+ return Err(ChannelError::close(err));
5310+ } else {
5311+ return Ok(());
5312+ }
5313+ }
5314+
53005315 let lower_limit_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
53015316 ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
53025317 } else {
@@ -13330,6 +13345,34 @@ mod tests {
1333013345 do_test_supports_channel_type(config, expected_channel_type)
1333113346 }
1333213347
13348+ #[test]
13349+ fn test_supports_zero_fee_commitments() {
13350+ // Tests that if both sides support and negotiate `anchors_zero_fee_commitments`, it is
13351+ // the resulting `channel_type`.
13352+ let mut config = UserConfig::default();
13353+ config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true;
13354+
13355+ let mut expected_channel_type = ChannelTypeFeatures::empty();
13356+ expected_channel_type.set_anchor_zero_fee_commitments_required();
13357+
13358+ do_test_supports_channel_type(config, expected_channel_type)
13359+ }
13360+
13361+ #[test]
13362+ fn test_supports_zero_fee_commitments_and_htlc_tx_fee() {
13363+ // Tests that if both sides support and negotiate `anchors_zero_fee_commitments` and
13364+ // `anchors_zero_fee_htlc_tx`, the resulting `channel_type` is
13365+ // `anchors_zero_fee_commitments`.
13366+ let mut config = UserConfig::default();
13367+ config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
13368+ config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true;
13369+
13370+ let mut expected_channel_type = ChannelTypeFeatures::empty();
13371+ expected_channel_type.set_anchor_zero_fee_commitments_required();
13372+
13373+ do_test_supports_channel_type(config, expected_channel_type)
13374+ }
13375+
1333313376 fn do_test_supports_channel_type(config: UserConfig, expected_channel_type: ChannelTypeFeatures) {
1333413377 let secp_ctx = Secp256k1::new();
1333513378 let fee_estimator = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
@@ -13363,6 +13406,14 @@ mod tests {
1336313406
1336413407 assert_eq!(channel_a.funding.get_channel_type(), &expected_channel_type);
1336513408 assert_eq!(channel_b.funding.get_channel_type(), &expected_channel_type);
13409+
13410+ if expected_channel_type.supports_anchor_zero_fee_commitments() {
13411+ assert_eq!(channel_a.context.feerate_per_kw, 0);
13412+ assert_eq!(channel_b.context.feerate_per_kw, 0);
13413+ } else {
13414+ assert_ne!(channel_a.context.feerate_per_kw, 0);
13415+ assert_ne!(channel_b.context.feerate_per_kw, 0);
13416+ }
1336613417 }
1336713418
1336813419 #[test]
0 commit comments