Skip to content

Commit 7ccc6b7

Browse files
committed
Disallow holders from selecting 0-reserve in legacy channels
We still allow counterparties to set 0-reserve legacy channels, as in prior releases.
1 parent 2631b91 commit 7ccc6b7

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

fuzz/src/chanmon_consistency.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ fn assert_action_timeout_awaiting_response(action: &msgs::ErrorAction) {
628628
);
629629
}
630630

631-
#[derive(Copy, Clone)]
631+
#[derive(Clone, Copy, PartialEq)]
632632
enum ChanType {
633633
Legacy,
634634
KeyedAnchors,
@@ -2082,19 +2082,20 @@ impl<'a, Out: Output + MaybeSend + MaybeSync> Harness<'a, Out> {
20822082
connect_peers(&nodes[0], &nodes[1]);
20832083
connect_peers(&nodes[1], &nodes[2]);
20842084

2085+
let set_0reserve = chan_type != ChanType::Legacy;
20852086
// Create 3 channels between A-B and 3 channels between B-C (6 total).
20862087
//
20872088
// Use distinct version numbers for each funding transaction so each test
20882089
// channel gets its own txid and funding outpoint.
20892090
// A-B: channel 2 A and B have 0-reserve (trusted open + trusted accept),
2090-
// channel 3 A has 0-reserve (trusted accept).
2091+
// channel 3 A has 0-reserve (trusted accept), if channels are non-legacy.
20912092
make_channel(&nodes[0], &nodes[1], 1, false, false, &mut chain_state);
2092-
make_channel(&nodes[0], &nodes[1], 2, true, true, &mut chain_state);
2093-
make_channel(&nodes[0], &nodes[1], 3, false, true, &mut chain_state);
2093+
make_channel(&nodes[0], &nodes[1], 2, set_0reserve, set_0reserve, &mut chain_state);
2094+
make_channel(&nodes[0], &nodes[1], 3, false, set_0reserve, &mut chain_state);
20942095
// B-C: channel 4 B has 0-reserve (via trusted accept),
2095-
// channel 5 C has 0-reserve (via trusted open).
2096-
make_channel(&nodes[1], &nodes[2], 4, false, true, &mut chain_state);
2097-
make_channel(&nodes[1], &nodes[2], 5, true, false, &mut chain_state);
2096+
// channel 5 C has 0-reserve (via trusted open), if channels are non-legacy.
2097+
make_channel(&nodes[1], &nodes[2], 4, false, set_0reserve, &mut chain_state);
2098+
make_channel(&nodes[1], &nodes[2], 5, set_0reserve, false, &mut chain_state);
20982099
make_channel(&nodes[1], &nodes[2], 6, false, false, &mut chain_state);
20992100

21002101
// Wipe the transactions-broadcasted set to make sure we don't broadcast

lightning/src/ln/channel.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,6 +3832,14 @@ impl<SP: SignerProvider> ChannelContext<SP> {
38323832
"Funding must be smaller than the total bitcoin supply. It was {channel_value_satoshis}"
38333833
)));
38343834
}
3835+
if !channel_type.supports_anchors_zero_fee_htlc_tx()
3836+
&& !channel_type.supports_anchor_zero_fee_commitments()
3837+
&& holder_selected_channel_reserve_satoshis == 0
3838+
{
3839+
return Err(ChannelError::close(
3840+
"0-reserve is not allowed on legacy channels".to_owned(),
3841+
));
3842+
}
38353843
if msg_channel_reserve_satoshis > channel_value_satoshis {
38363844
return Err(ChannelError::close(format!(
38373845
"Bogus channel_reserve_satoshis ({msg_channel_reserve_satoshis}). Must be no greater than channel_value_satoshis: {channel_value_satoshis}"
@@ -4323,6 +4331,14 @@ impl<SP: SignerProvider> ChannelContext<SP> {
43234331
}
43244332

43254333
let channel_type = get_initial_channel_type(&config, their_features);
4334+
if !channel_type.supports_anchors_zero_fee_htlc_tx()
4335+
&& !channel_type.supports_anchor_zero_fee_commitments()
4336+
&& holder_selected_channel_reserve_satoshis == 0
4337+
{
4338+
return Err(APIError::APIMisuseError {
4339+
err: "0-reserve is not allowed on legacy channels".to_owned(),
4340+
});
4341+
}
43264342
debug_assert!(!channel_type.supports_any_optional_bits());
43274343
debug_assert!(!channel_type
43284344
.requires_unknown_bits_from(&channelmanager::provided_channel_type_features(&config)));
@@ -4869,6 +4885,14 @@ impl<SP: SignerProvider> ChannelContext<SP> {
48694885
}
48704886

48714887
let channel_type = funding.get_channel_type();
4888+
if !channel_type.supports_anchors_zero_fee_htlc_tx()
4889+
&& !channel_type.supports_anchor_zero_fee_commitments()
4890+
&& funding.holder_selected_channel_reserve_satoshis == 0
4891+
{
4892+
return Err(ChannelError::close(
4893+
"0-reserve is not allowed on legacy channels".to_owned(),
4894+
));
4895+
}
48724896
if common_fields.max_accepted_htlcs > max_htlcs(channel_type) {
48734897
return Err(ChannelError::close(format!(
48744898
"max_accepted_htlcs was {}. It must not be larger than {}",
@@ -6576,6 +6600,13 @@ impl<SP: SignerProvider> ChannelContext<SP> {
65766600
}
65776601

65786602
let next_channel_type = get_initial_channel_type(user_config, &eligible_features);
6603+
if !next_channel_type.supports_anchors_zero_fee_htlc_tx()
6604+
&& !next_channel_type.supports_anchor_zero_fee_commitments()
6605+
&& funding.holder_selected_channel_reserve_satoshis == 0
6606+
{
6607+
// 0-reserve is not allowed on legacy channels
6608+
return Err(());
6609+
}
65796610

65806611
self.feerate_per_kw =
65816612
selected_commitment_sat_per_1000_weight(&fee_estimator, &next_channel_type);

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3617,6 +3617,8 @@ pub enum TrustedChannelFeatures {
36173617
/// with a revoked commitment transaction *for free*.
36183618
///
36193619
/// Note that there is no guarantee that the counterparty accepts such a channel themselves.
3620+
///
3621+
/// The zero-reserve feature is not allowed on legacy / anchorless channels.
36203622
ZeroReserve,
36213623
/// Sets the combination of [`TrustedChannelFeatures::ZeroConf`] and [`TrustedChannelFeatures::ZeroReserve`]
36223624
ZeroConfZeroReserve,
@@ -3873,6 +3875,8 @@ impl<
38733875
/// transaction *for free*.
38743876
///
38753877
/// Note that there is no guarantee that the counterparty accepts such a channel.
3878+
///
3879+
/// The zero-reserve feature is not allowed on legacy / anchorless channels.
38763880
pub fn create_channel_to_trusted_peer_0reserve(
38773881
&self, their_network_key: PublicKey, channel_value_satoshis: u64, push_msat: u64,
38783882
user_channel_id: u128, temporary_channel_id: Option<ChannelId>,

0 commit comments

Comments
 (0)