@@ -3041,12 +3041,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3041
3041
debug_assert!(!channel_type.supports_any_optional_bits());
3042
3042
debug_assert!(!channel_type.requires_unknown_bits_from(&channelmanager::provided_channel_type_features(&config)));
3043
3043
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
+ };
3050
3056
3051
3057
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
3052
3058
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
5253
5259
feerate_per_kw: u32, cur_feerate_per_kw: Option<u32>, logger: &L
5254
5260
) -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
5255
5261
{
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
+
5256
5271
let lower_limit_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
5257
5272
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
5258
5273
} else {
@@ -13162,6 +13177,19 @@ mod tests {
13162
13177
do_test_supports_channel_type(config, expected_channel_type)
13163
13178
}
13164
13179
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
+
13165
13193
fn do_test_supports_channel_type(config: UserConfig, expected_channel_type: ChannelTypeFeatures) {
13166
13194
let secp_ctx = Secp256k1::new();
13167
13195
let fee_estimator = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
@@ -13195,6 +13223,14 @@ mod tests {
13195
13223
13196
13224
assert_eq!(channel_a.funding.get_channel_type(), &expected_channel_type);
13197
13225
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
+ }
13198
13234
}
13199
13235
13200
13236
#[test]
0 commit comments