Skip to content

Commit fe65f1d

Browse files
carlaKCTheBlueMatt
andcommitted
ln: do not set or accept non-zero feerates in open_channel for v3
Sender: MUST set `feerate_per_kw` to zero Receiver: MUST fail the channel if `feerate_per_kw` != 0 Co-authored-by: Matt Corallo <git@bluematt.me>
1 parent 6a43d62 commit fe65f1d

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

lightning/src/ln/channel.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,12 +3036,18 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30363036
debug_assert!(!channel_type.supports_any_optional_bits());
30373037
debug_assert!(!channel_type.requires_unknown_bits_from(&channelmanager::provided_channel_type_features(&config)));
30383038

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+
};
30453051

30463052
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
30473053
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
52325238
feerate_per_kw: u32, cur_feerate_per_kw: Option<u32>, logger: &L
52335239
) -> Result<(), ChannelError> where F::Target: FeeEstimator, L::Target: Logger,
52345240
{
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+
52355250
let lower_limit_conf_target = if channel_type.supports_anchors_zero_fee_htlc_tx() {
52365251
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
52375252
} else {
@@ -13135,6 +13150,19 @@ mod tests {
1313513150
do_test_supports_channel_type(config, expected_channel_type)
1313613151
}
1313713152

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+
1313813166
fn do_test_supports_channel_type(config: UserConfig, expected_channel_type: ChannelTypeFeatures) {
1313913167
let secp_ctx = Secp256k1::new();
1314013168
let fee_estimator = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
@@ -13169,6 +13197,14 @@ mod tests {
1316913197

1317013198
assert_eq!(channel_a.funding.get_channel_type(), &expected_channel_type);
1317113199
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+
}
1317213208
}
1317313209

1317413210
#[test]

0 commit comments

Comments
 (0)