@@ -3041,12 +3041,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30413041 debug_assert!(!channel_type.supports_any_optional_bits());
30423042 debug_assert!(!channel_type.requires_unknown_bits_from(&channelmanager::provided_channel_type_features(&config)));
30433043
3044- let (commitment_conf_target, anchor_outputs_value_msat) = if channel_type.supports_anchors_zero_fee_htlc_tx() {
3045- (ConfirmationTarget::AnchorChannelFee, ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000)
3046- } else {
3047- (ConfirmationTarget::NonAnchorChannelFee, 0)
3048- };
3049- let commitment_feerate = fee_estimator.bounded_sat_per_1000_weight(commitment_conf_target);
3044+ let (commitment_feerate, anchor_outputs_value_msat) =
3045+ if channel_type.supports_anchor_zero_fee_commitments() {
3046+ (0, 0)
3047+ } else if channel_type.supports_anchors_zero_fee_htlc_tx() {
3048+ let feerate = fee_estimator
3049+ .bounded_sat_per_1000_weight(ConfirmationTarget::AnchorChannelFee);
3050+ (feerate, ANCHOR_OUTPUT_VALUE_SATOSHI * 2 * 1000)
3051+ } else {
3052+ let feerate = fee_estimator
3053+ .bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
3054+ (feerate, 0)
3055+ };
30503056
30513057 let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
30523058 let commitment_tx_fee = commit_tx_fee_sat(commitment_feerate, MIN_AFFORDABLE_HTLC_COUNT, &channel_type) * 1000;
@@ -5253,6 +5259,15 @@ impl<SP: Deref> FundedChannel<SP> where
52535259 feerate_per_kw: u32, cur_feerate_per_kw: Option<u32>, logger: &L
52545260 ) -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
52555261 {
5262+ if channel_type.supports_anchor_zero_fee_commitments() {
5263+ if feerate_per_kw != 0 {
5264+ let err = "Zero Fee Channels must never attempt to use a fee".to_owned();
5265+ return Err(ChannelError::close(err));
5266+ } else {
5267+ return Ok(());
5268+ }
5269+ }
5270+
52565271 let lower_limit_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
52575272 ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
52585273 } else {
@@ -13162,6 +13177,19 @@ mod tests {
1316213177 do_test_supports_channel_type(config, expected_channel_type)
1316313178 }
1316413179
13180+ #[test]
13181+ fn test_supports_zero_fee_commitments() {
13182+ // Tests that if both sides support and negotiate `anchors_zero_fee_commitments`, it is
13183+ // the resulting `channel_type`.
13184+ let mut config = UserConfig::default();
13185+ config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true;
13186+
13187+ let mut expected_channel_type = ChannelTypeFeatures::empty();
13188+ expected_channel_type.set_anchor_zero_fee_commitments_required();
13189+
13190+ do_test_supports_channel_type(config, expected_channel_type)
13191+ }
13192+
1316513193 fn do_test_supports_channel_type(config: UserConfig, expected_channel_type: ChannelTypeFeatures) {
1316613194 let secp_ctx = Secp256k1::new();
1316713195 let fee_estimator = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
@@ -13195,6 +13223,14 @@ mod tests {
1319513223
1319613224 assert_eq!(channel_a.funding.get_channel_type(), &expected_channel_type);
1319713225 assert_eq!(channel_b.funding.get_channel_type(), &expected_channel_type);
13226+
13227+ if expected_channel_type.supports_anchor_zero_fee_commitments() {
13228+ assert_eq!(channel_a.context.feerate_per_kw, 0);
13229+ assert_eq!(channel_b.context.feerate_per_kw, 0);
13230+ } else {
13231+ assert_ne!(channel_a.context.feerate_per_kw, 0);
13232+ assert_ne!(channel_b.context.feerate_per_kw, 0);
13233+ }
1319813234 }
1319913235
1320013236 #[test]
0 commit comments