Skip to content

Commit 3412ddb

Browse files
committed
Remove config knob to access defaults and use constant instead.
Responding to PR feedback on naming
1 parent 9d7bfa8 commit 3412ddb

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

lightning/src/ln/channel.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ pub(super) struct Channel<Signer: ChannelSigner> {
530530
cur_holder_commitment_transaction_number: u64,
531531
cur_counterparty_commitment_transaction_number: u64,
532532
value_to_self_msat: u64, // Excluding all pending_htlcs, excluding fees
533-
max_accepted_htlcs: u16,
534533
pending_inbound_htlcs: Vec<InboundHTLCOutput>,
535534
pending_outbound_htlcs: Vec<OutboundHTLCOutput>,
536535
holding_cell_htlc_updates: Vec<HTLCUpdateAwaitingACK>,
@@ -654,6 +653,7 @@ pub(super) struct Channel<Signer: ChannelSigner> {
654653
pub counterparty_max_accepted_htlcs: u16,
655654
#[cfg(not(test))]
656655
counterparty_max_accepted_htlcs: u16,
656+
holder_max_accepted_htlcs: u16,
657657
minimum_depth: Option<u32>,
658658

659659
counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
@@ -756,6 +756,7 @@ struct CommitmentTxInfoCached {
756756
feerate: u32,
757757
}
758758

759+
pub const DEFAULT_MAX_HTLCS: u16 = 50;
759760

760761
pub(crate) fn commitment_tx_base_weight(opt_anchors: bool) -> u64 {
761762
const COMMITMENT_TX_BASE_WEIGHT: u64 = 724;
@@ -1026,7 +1027,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
10261027
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
10271028
value_to_self_msat,
10281029

1029-
max_accepted_htlcs: config.channel_handshake_config.max_accepted_htlcs,
10301030
pending_inbound_htlcs: Vec::new(),
10311031
pending_outbound_htlcs: Vec::new(),
10321032
holding_cell_htlc_updates: Vec::new(),
@@ -1072,6 +1072,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
10721072
counterparty_htlc_minimum_msat: 0,
10731073
holder_htlc_minimum_msat: if config.channel_handshake_config.our_htlc_minimum_msat == 0 { 1 } else { config.channel_handshake_config.our_htlc_minimum_msat },
10741074
counterparty_max_accepted_htlcs: 0,
1075+
holder_max_accepted_htlcs: config.channel_handshake_config.our_max_accepted_htlcs,
10751076
minimum_depth: None, // Filled in in accept_channel
10761077

10771078
counterparty_forwarding_info: None,
@@ -1373,7 +1374,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
13731374
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
13741375
value_to_self_msat: msg.push_msat,
13751376

1376-
max_accepted_htlcs: config.channel_handshake_config.max_accepted_htlcs,
13771377
pending_inbound_htlcs: Vec::new(),
13781378
pending_outbound_htlcs: Vec::new(),
13791379
holding_cell_htlc_updates: Vec::new(),
@@ -1420,6 +1420,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
14201420
counterparty_htlc_minimum_msat: msg.htlc_minimum_msat,
14211421
holder_htlc_minimum_msat: if config.channel_handshake_config.our_htlc_minimum_msat == 0 { 1 } else { config.channel_handshake_config.our_htlc_minimum_msat },
14221422
counterparty_max_accepted_htlcs: msg.max_accepted_htlcs,
1423+
holder_max_accepted_htlcs: config.channel_handshake_config.our_max_accepted_htlcs,
14231424
minimum_depth: Some(cmp::max(config.channel_handshake_config.minimum_depth, 1)),
14241425

14251426
counterparty_forwarding_info: None,
@@ -2875,8 +2876,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
28752876

28762877
let inbound_stats = self.get_inbound_pending_htlc_stats(None);
28772878
let outbound_stats = self.get_outbound_pending_htlc_stats(None);
2878-
if inbound_stats.pending_htlcs + 1 > self.max_accepted_htlcs as u32 {
2879-
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.max_accepted_htlcs)));
2879+
if inbound_stats.pending_htlcs + 1 > self.holder_max_accepted_htlcs as u32 {
2880+
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.holder_max_accepted_htlcs)));
28802881
}
28812882
if inbound_stats.pending_htlcs_value_msat + msg.amount_msat > self.holder_max_htlc_value_in_flight_msat {
28822883
return Err(ChannelError::Close(format!("Remote HTLC add would put them over our max HTLC value ({})", self.holder_max_htlc_value_in_flight_msat)));
@@ -5314,7 +5315,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53145315
htlc_minimum_msat: self.holder_htlc_minimum_msat,
53155316
feerate_per_kw: self.feerate_per_kw as u32,
53165317
to_self_delay: self.get_holder_selected_contest_delay(),
5317-
max_accepted_htlcs: self.max_accepted_htlcs,
5318+
max_accepted_htlcs: self.holder_max_accepted_htlcs,
53185319
funding_pubkey: keys.funding_pubkey,
53195320
revocation_basepoint: keys.revocation_basepoint,
53205321
payment_point: keys.payment_point,
@@ -5381,7 +5382,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53815382
htlc_minimum_msat: self.holder_htlc_minimum_msat,
53825383
minimum_depth: self.minimum_depth.unwrap(),
53835384
to_self_delay: self.get_holder_selected_contest_delay(),
5384-
max_accepted_htlcs: self.max_accepted_htlcs,
5385+
max_accepted_htlcs: self.holder_max_accepted_htlcs,
53855386
funding_pubkey: keys.funding_pubkey,
53865387
revocation_basepoint: keys.revocation_basepoint,
53875388
payment_point: keys.payment_point,
@@ -6497,7 +6498,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
64976498
// we write the high bytes as an option here.
64986499
let user_id_high_opt = Some((self.user_id >> 64) as u64);
64996500

6500-
let max_accepted_htlcs = if self.max_accepted_htlcs == 50 { None } else { Some(self.max_accepted_htlcs) };
6501+
let holder_max_accepted_htlcs = if self.holder_max_accepted_htlcs == 50 { None } else { Some(self.holder_max_accepted_htlcs) };
65016502

65026503
write_tlv_fields!(writer, {
65036504
(0, self.announcement_sigs, option),
@@ -6524,7 +6525,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
65246525
(23, channel_ready_event_emitted, option),
65256526
(25, user_id_high_opt, option),
65266527
(27, self.channel_keys_id, required),
6527-
(28, max_accepted_htlcs, option),
6528+
(28, holder_max_accepted_htlcs, option),
65286529
(29, self.temporary_channel_id, option),
65296530
(31, channel_pending_event_emitted, option),
65306531
});
@@ -6594,9 +6595,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65946595

65956596
let pending_inbound_htlc_count: u64 = Readable::read(reader)?;
65966597

6597-
let channel_handshake_config = ChannelHandshakeConfig::default();
6598-
6599-
let mut pending_inbound_htlcs = Vec::with_capacity(cmp::min(pending_inbound_htlc_count as usize, channel_handshake_config.max_accepted_htlcs as usize));
6598+
let mut pending_inbound_htlcs = Vec::with_capacity(cmp::min(pending_inbound_htlc_count as usize, DEFAULT_MAX_HTLCS as usize));
66006599
for _ in 0..pending_inbound_htlc_count {
66016600
pending_inbound_htlcs.push(InboundHTLCOutput {
66026601
htlc_id: Readable::read(reader)?,
@@ -6614,7 +6613,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66146613
}
66156614

66166615
let pending_outbound_htlc_count: u64 = Readable::read(reader)?;
6617-
let mut pending_outbound_htlcs = Vec::with_capacity(cmp::min(pending_outbound_htlc_count as usize, channel_handshake_config.max_accepted_htlcs as usize));
6616+
let mut pending_outbound_htlcs = Vec::with_capacity(cmp::min(pending_outbound_htlc_count as usize, DEFAULT_MAX_HTLCS as usize));
66186617
for _ in 0..pending_outbound_htlc_count {
66196618
pending_outbound_htlcs.push(OutboundHTLCOutput {
66206619
htlc_id: Readable::read(reader)?,
@@ -6643,7 +6642,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66436642
}
66446643

66456644
let holding_cell_htlc_update_count: u64 = Readable::read(reader)?;
6646-
let mut holding_cell_htlc_updates = Vec::with_capacity(cmp::min(holding_cell_htlc_update_count as usize, channel_handshake_config.max_accepted_htlcs as usize*2));
6645+
let mut holding_cell_htlc_updates = Vec::with_capacity(cmp::min(holding_cell_htlc_update_count as usize, DEFAULT_MAX_HTLCS as usize*2));
66476646
for _ in 0..holding_cell_htlc_update_count {
66486647
holding_cell_htlc_updates.push(match <u8 as Readable>::read(reader)? {
66496648
0 => HTLCUpdateAwaitingACK::AddHTLC {
@@ -6676,13 +6675,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66766675
let monitor_pending_commitment_signed = Readable::read(reader)?;
66776676

66786677
let monitor_pending_forwards_count: u64 = Readable::read(reader)?;
6679-
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, channel_handshake_config.max_accepted_htlcs as usize));
6678+
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, DEFAULT_MAX_HTLCS as usize));
66806679
for _ in 0..monitor_pending_forwards_count {
66816680
monitor_pending_forwards.push((Readable::read(reader)?, Readable::read(reader)?));
66826681
}
66836682

66846683
let monitor_pending_failures_count: u64 = Readable::read(reader)?;
6685-
let mut monitor_pending_failures = Vec::with_capacity(cmp::min(monitor_pending_failures_count as usize, channel_handshake_config.max_accepted_htlcs as usize));
6684+
let mut monitor_pending_failures = Vec::with_capacity(cmp::min(monitor_pending_failures_count as usize, DEFAULT_MAX_HTLCS as usize));
66866685
for _ in 0..monitor_pending_failures_count {
66876686
monitor_pending_failures.push((Readable::read(reader)?, Readable::read(reader)?, Readable::read(reader)?));
66886687
}
@@ -6803,7 +6802,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68036802
let mut user_id_high_opt: Option<u64> = None;
68046803
let mut channel_keys_id: Option<[u8; 32]> = None;
68056804
let mut temporary_channel_id: Option<[u8; 32]> = None;
6806-
let mut max_accepted_htlcs: Option<u16> = None;
6805+
let mut holder_max_accepted_htlcs: Option<u16> = None;
68076806

68086807
read_tlv_fields!(reader, {
68096808
(0, announcement_sigs, option),
@@ -6824,7 +6823,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68246823
(23, channel_ready_event_emitted, option),
68256824
(25, user_id_high_opt, option),
68266825
(27, channel_keys_id, option),
6827-
(28, max_accepted_htlcs, option),
6826+
(28, holder_max_accepted_htlcs, option),
68286827
(29, temporary_channel_id, option),
68296828
(31, channel_pending_event_emitted, option),
68306829
});
@@ -6879,7 +6878,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68796878
// separate u64 values.
68806879
let user_id = user_id_low as u128 + ((user_id_high_opt.unwrap_or(0) as u128) << 64);
68816880

6882-
let max_accepted_htlcs = max_accepted_htlcs.unwrap_or(channel_handshake_config.max_accepted_htlcs);
6881+
let holder_max_accepted_htlcs = holder_max_accepted_htlcs.unwrap_or(DEFAULT_MAX_HTLCS);
68836882

68846883
Ok(Channel {
68856884
user_id,
@@ -6909,7 +6908,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
69096908
cur_counterparty_commitment_transaction_number,
69106909
value_to_self_msat,
69116910

6912-
max_accepted_htlcs,
6911+
holder_max_accepted_htlcs,
69136912
pending_inbound_htlcs,
69146913
pending_outbound_htlcs,
69156914
holding_cell_htlc_updates,

lightning/src/util/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ pub struct ChannelHandshakeConfig {
170170
/// [`DecodeError::InvalidValue`]: crate::ln::msgs::DecodeError::InvalidValue
171171
/// [`SIGHASH_SINGLE + update_fee Considered Harmful`]: https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-September/002796.html
172172
pub negotiate_anchors_zero_fee_htlc_tx: bool,
173+
173174
/// Default value: 50
174-
pub max_accepted_htlcs: u16,
175+
pub our_max_accepted_htlcs: u16,
175176
}
176177

177178
impl Default for ChannelHandshakeConfig {
@@ -187,7 +188,7 @@ impl Default for ChannelHandshakeConfig {
187188
their_channel_reserve_proportional_millionths: 10_000,
188189
#[cfg(anchors)]
189190
negotiate_anchors_zero_fee_htlc_tx: false,
190-
max_accepted_htlcs: 50,
191+
our_max_accepted_htlcs: 50,
191192
}
192193
}
193194
}

0 commit comments

Comments
 (0)