Skip to content

Commit faa6a0a

Browse files
committed
Remove config knob to access defaults and use constant instead.
Responding to PR feedback on naming
1 parent 13104a0 commit faa6a0a

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
@@ -529,7 +529,6 @@ pub(super) struct Channel<Signer: ChannelSigner> {
529529
cur_holder_commitment_transaction_number: u64,
530530
cur_counterparty_commitment_transaction_number: u64,
531531
value_to_self_msat: u64, // Excluding all pending_htlcs, excluding fees
532-
max_accepted_htlcs: u16,
533532
pending_inbound_htlcs: Vec<InboundHTLCOutput>,
534533
pending_outbound_htlcs: Vec<OutboundHTLCOutput>,
535534
holding_cell_htlc_updates: Vec<HTLCUpdateAwaitingACK>,
@@ -653,6 +652,7 @@ pub(super) struct Channel<Signer: ChannelSigner> {
653652
pub counterparty_max_accepted_htlcs: u16,
654653
#[cfg(not(test))]
655654
counterparty_max_accepted_htlcs: u16,
655+
holder_max_accepted_htlcs: u16,
656656
minimum_depth: Option<u32>,
657657

658658
counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
@@ -752,6 +752,7 @@ struct CommitmentTxInfoCached {
752752
feerate: u32,
753753
}
754754

755+
pub const DEFAULT_MAX_HTLCS: u16 = 50;
755756

756757
pub(crate) fn commitment_tx_base_weight(opt_anchors: bool) -> u64 {
757758
const COMMITMENT_TX_BASE_WEIGHT: u64 = 724;
@@ -1019,7 +1020,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
10191020
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
10201021
value_to_self_msat,
10211022

1022-
max_accepted_htlcs: config.channel_handshake_config.max_accepted_htlcs,
10231023
pending_inbound_htlcs: Vec::new(),
10241024
pending_outbound_htlcs: Vec::new(),
10251025
holding_cell_htlc_updates: Vec::new(),
@@ -1065,6 +1065,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
10651065
counterparty_htlc_minimum_msat: 0,
10661066
holder_htlc_minimum_msat: if config.channel_handshake_config.our_htlc_minimum_msat == 0 { 1 } else { config.channel_handshake_config.our_htlc_minimum_msat },
10671067
counterparty_max_accepted_htlcs: 0,
1068+
holder_max_accepted_htlcs: config.channel_handshake_config.our_max_accepted_htlcs,
10681069
minimum_depth: None, // Filled in in accept_channel
10691070

10701071
counterparty_forwarding_info: None,
@@ -1364,7 +1365,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
13641365
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
13651366
value_to_self_msat: msg.push_msat,
13661367

1367-
max_accepted_htlcs: config.channel_handshake_config.max_accepted_htlcs,
13681368
pending_inbound_htlcs: Vec::new(),
13691369
pending_outbound_htlcs: Vec::new(),
13701370
holding_cell_htlc_updates: Vec::new(),
@@ -1411,6 +1411,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
14111411
counterparty_htlc_minimum_msat: msg.htlc_minimum_msat,
14121412
holder_htlc_minimum_msat: if config.channel_handshake_config.our_htlc_minimum_msat == 0 { 1 } else { config.channel_handshake_config.our_htlc_minimum_msat },
14131413
counterparty_max_accepted_htlcs: msg.max_accepted_htlcs,
1414+
holder_max_accepted_htlcs: config.channel_handshake_config.our_max_accepted_htlcs,
14141415
minimum_depth: Some(cmp::max(config.channel_handshake_config.minimum_depth, 1)),
14151416

14161417
counterparty_forwarding_info: None,
@@ -2863,8 +2864,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
28632864

28642865
let inbound_stats = self.get_inbound_pending_htlc_stats(None);
28652866
let outbound_stats = self.get_outbound_pending_htlc_stats(None);
2866-
if inbound_stats.pending_htlcs + 1 > self.max_accepted_htlcs as u32 {
2867-
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.max_accepted_htlcs)));
2867+
if inbound_stats.pending_htlcs + 1 > self.holder_max_accepted_htlcs as u32 {
2868+
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", self.holder_max_accepted_htlcs)));
28682869
}
28692870
if inbound_stats.pending_htlcs_value_msat + msg.amount_msat > self.holder_max_htlc_value_in_flight_msat {
28702871
return Err(ChannelError::Close(format!("Remote HTLC add would put them over our max HTLC value ({})", self.holder_max_htlc_value_in_flight_msat)));
@@ -5254,7 +5255,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
52545255
htlc_minimum_msat: self.holder_htlc_minimum_msat,
52555256
feerate_per_kw: self.feerate_per_kw as u32,
52565257
to_self_delay: self.get_holder_selected_contest_delay(),
5257-
max_accepted_htlcs: self.max_accepted_htlcs,
5258+
max_accepted_htlcs: self.holder_max_accepted_htlcs,
52585259
funding_pubkey: keys.funding_pubkey,
52595260
revocation_basepoint: keys.revocation_basepoint,
52605261
payment_point: keys.payment_point,
@@ -5321,7 +5322,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53215322
htlc_minimum_msat: self.holder_htlc_minimum_msat,
53225323
minimum_depth: self.minimum_depth.unwrap(),
53235324
to_self_delay: self.get_holder_selected_contest_delay(),
5324-
max_accepted_htlcs: self.max_accepted_htlcs,
5325+
max_accepted_htlcs: self.holder_max_accepted_htlcs,
53255326
funding_pubkey: keys.funding_pubkey,
53265327
revocation_basepoint: keys.revocation_basepoint,
53275328
payment_point: keys.payment_point,
@@ -6428,7 +6429,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
64286429
// we write the high bytes as an option here.
64296430
let user_id_high_opt = Some((self.user_id >> 64) as u64);
64306431

6431-
let max_accepted_htlcs = if self.max_accepted_htlcs == 50 { None } else { Some(self.max_accepted_htlcs) };
6432+
let holder_max_accepted_htlcs = if self.holder_max_accepted_htlcs == 50 { None } else { Some(self.holder_max_accepted_htlcs) };
64326433

64336434
write_tlv_fields!(writer, {
64346435
(0, self.announcement_sigs, option),
@@ -6455,7 +6456,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
64556456
(23, channel_ready_event_emitted, option),
64566457
(25, user_id_high_opt, option),
64576458
(27, self.channel_keys_id, required),
6458-
(28, max_accepted_htlcs, option),
6459+
(28, holder_max_accepted_htlcs, option),
64596460
});
64606461

64616462
Ok(())
@@ -6523,9 +6524,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65236524

65246525
let pending_inbound_htlc_count: u64 = Readable::read(reader)?;
65256526

6526-
let channel_handshake_config = ChannelHandshakeConfig::default();
6527-
6528-
let mut pending_inbound_htlcs = Vec::with_capacity(cmp::min(pending_inbound_htlc_count as usize, channel_handshake_config.max_accepted_htlcs as usize));
6527+
let mut pending_inbound_htlcs = Vec::with_capacity(cmp::min(pending_inbound_htlc_count as usize, DEFAULT_MAX_HTLCS as usize));
65296528
for _ in 0..pending_inbound_htlc_count {
65306529
pending_inbound_htlcs.push(InboundHTLCOutput {
65316530
htlc_id: Readable::read(reader)?,
@@ -6543,7 +6542,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65436542
}
65446543

65456544
let pending_outbound_htlc_count: u64 = Readable::read(reader)?;
6546-
let mut pending_outbound_htlcs = Vec::with_capacity(cmp::min(pending_outbound_htlc_count as usize, channel_handshake_config.max_accepted_htlcs as usize));
6545+
let mut pending_outbound_htlcs = Vec::with_capacity(cmp::min(pending_outbound_htlc_count as usize, DEFAULT_MAX_HTLCS as usize));
65476546
for _ in 0..pending_outbound_htlc_count {
65486547
pending_outbound_htlcs.push(OutboundHTLCOutput {
65496548
htlc_id: Readable::read(reader)?,
@@ -6572,7 +6571,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65726571
}
65736572

65746573
let holding_cell_htlc_update_count: u64 = Readable::read(reader)?;
6575-
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));
6574+
let mut holding_cell_htlc_updates = Vec::with_capacity(cmp::min(holding_cell_htlc_update_count as usize, DEFAULT_MAX_HTLCS as usize*2));
65766575
for _ in 0..holding_cell_htlc_update_count {
65776576
holding_cell_htlc_updates.push(match <u8 as Readable>::read(reader)? {
65786577
0 => HTLCUpdateAwaitingACK::AddHTLC {
@@ -6605,13 +6604,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66056604
let monitor_pending_commitment_signed = Readable::read(reader)?;
66066605

66076606
let monitor_pending_forwards_count: u64 = Readable::read(reader)?;
6608-
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, channel_handshake_config.max_accepted_htlcs as usize));
6607+
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, DEFAULT_MAX_HTLCS as usize));
66096608
for _ in 0..monitor_pending_forwards_count {
66106609
monitor_pending_forwards.push((Readable::read(reader)?, Readable::read(reader)?));
66116610
}
66126611

66136612
let monitor_pending_failures_count: u64 = Readable::read(reader)?;
6614-
let mut monitor_pending_failures = Vec::with_capacity(cmp::min(monitor_pending_failures_count as usize, channel_handshake_config.max_accepted_htlcs as usize));
6613+
let mut monitor_pending_failures = Vec::with_capacity(cmp::min(monitor_pending_failures_count as usize, DEFAULT_MAX_HTLCS as usize));
66156614
for _ in 0..monitor_pending_failures_count {
66166615
monitor_pending_failures.push((Readable::read(reader)?, Readable::read(reader)?, Readable::read(reader)?));
66176616
}
@@ -6730,7 +6729,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
67306729

67316730
let mut user_id_high_opt: Option<u64> = None;
67326731
let mut channel_keys_id: Option<[u8; 32]> = None;
6733-
let mut max_accepted_htlcs: Option<u16> = None;
6732+
let mut holder_max_accepted_htlcs: Option<u16> = None;
67346733

67356734
read_tlv_fields!(reader, {
67366735
(0, announcement_sigs, option),
@@ -6751,7 +6750,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
67516750
(23, channel_ready_event_emitted, option),
67526751
(25, user_id_high_opt, option),
67536752
(27, channel_keys_id, option),
6754-
(28, max_accepted_htlcs, option),
6753+
(28, holder_max_accepted_htlcs, option),
67556754
});
67566755

67576756
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -6804,7 +6803,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68046803
// separate u64 values.
68056804
let user_id = user_id_low as u128 + ((user_id_high_opt.unwrap_or(0) as u128) << 64);
68066805

6807-
let max_accepted_htlcs = max_accepted_htlcs.unwrap_or(channel_handshake_config.max_accepted_htlcs);
6806+
let holder_max_accepted_htlcs = holder_max_accepted_htlcs.unwrap_or(DEFAULT_MAX_HTLCS);
68086807

68096808
Ok(Channel {
68106809
user_id,
@@ -6833,7 +6832,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68336832
cur_counterparty_commitment_transaction_number,
68346833
value_to_self_msat,
68356834

6836-
max_accepted_htlcs,
6835+
holder_max_accepted_htlcs,
68376836
pending_inbound_htlcs,
68386837
pending_outbound_htlcs,
68396838
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)