Skip to content

Commit aad39a8

Browse files
committed
Replace OUR_MAX_HTLCS with config knob
Writes an even TLV if the value isn't 50
1 parent a9534fe commit aad39a8

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ 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,
532533
pending_inbound_htlcs: Vec<InboundHTLCOutput>,
533534
pending_outbound_htlcs: Vec<OutboundHTLCOutput>,
534535
holding_cell_htlc_updates: Vec<HTLCUpdateAwaitingACK>,
@@ -652,7 +653,6 @@ pub(super) struct Channel<Signer: ChannelSigner> {
652653
pub counterparty_max_accepted_htlcs: u16,
653654
#[cfg(not(test))]
654655
counterparty_max_accepted_htlcs: u16,
655-
//implied by OUR_MAX_HTLCS: max_accepted_htlcs: u16,
656656
minimum_depth: Option<u32>,
657657

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

755-
pub const OUR_MAX_HTLCS: u16 = 50; //TODO
756755

757756
pub(crate) fn commitment_tx_base_weight(opt_anchors: bool) -> u64 {
758757
const COMMITMENT_TX_BASE_WEIGHT: u64 = 724;
@@ -1020,6 +1019,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
10201019
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
10211020
value_to_self_msat,
10221021

1022+
max_accepted_htlcs: 50,
10231023
pending_inbound_htlcs: Vec::new(),
10241024
pending_outbound_htlcs: Vec::new(),
10251025
holding_cell_htlc_updates: Vec::new(),
@@ -1364,6 +1364,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
13641364
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
13651365
value_to_self_msat: msg.push_msat,
13661366

1367+
max_accepted_htlcs: msg.max_accepted_htlcs,
13671368
pending_inbound_htlcs: Vec::new(),
13681369
pending_outbound_htlcs: Vec::new(),
13691370
holding_cell_htlc_updates: Vec::new(),
@@ -2862,8 +2863,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
28622863

28632864
let inbound_stats = self.get_inbound_pending_htlc_stats(None);
28642865
let outbound_stats = self.get_outbound_pending_htlc_stats(None);
2865-
if inbound_stats.pending_htlcs + 1 > OUR_MAX_HTLCS as u32 {
2866-
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", OUR_MAX_HTLCS)));
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)));
28672868
}
28682869
if inbound_stats.pending_htlcs_value_msat + msg.amount_msat > self.holder_max_htlc_value_in_flight_msat {
28692870
return Err(ChannelError::Close(format!("Remote HTLC add would put them over our max HTLC value ({})", self.holder_max_htlc_value_in_flight_msat)));
@@ -5253,7 +5254,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
52535254
htlc_minimum_msat: self.holder_htlc_minimum_msat,
52545255
feerate_per_kw: self.feerate_per_kw as u32,
52555256
to_self_delay: self.get_holder_selected_contest_delay(),
5256-
max_accepted_htlcs: OUR_MAX_HTLCS,
5257+
max_accepted_htlcs: self.max_accepted_htlcs,
52575258
funding_pubkey: keys.funding_pubkey,
52585259
revocation_basepoint: keys.revocation_basepoint,
52595260
payment_point: keys.payment_point,
@@ -5320,7 +5321,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53205321
htlc_minimum_msat: self.holder_htlc_minimum_msat,
53215322
minimum_depth: self.minimum_depth.unwrap(),
53225323
to_self_delay: self.get_holder_selected_contest_delay(),
5323-
max_accepted_htlcs: OUR_MAX_HTLCS,
5324+
max_accepted_htlcs: self.max_accepted_htlcs,
53245325
funding_pubkey: keys.funding_pubkey,
53255326
revocation_basepoint: keys.revocation_basepoint,
53265327
payment_point: keys.payment_point,
@@ -6207,6 +6208,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
62076208
self.cur_counterparty_commitment_transaction_number.write(writer)?;
62086209
self.value_to_self_msat.write(writer)?;
62096210

6211+
self.max_accepted_htlcs.write(writer)?;
62106212
let mut dropped_inbound_htlcs = 0;
62116213
for htlc in self.pending_inbound_htlcs.iter() {
62126214
if let InboundHTLCState::RemoteAnnounced(_) = htlc.state {
@@ -6452,6 +6454,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
64526454
(23, channel_ready_event_emitted, option),
64536455
(25, user_id_high_opt, option),
64546456
(27, self.channel_keys_id, required),
6457+
(28, Some(self.max_accepted_htlcs), option),
64556458
});
64566459

64576460
Ok(())
@@ -6517,8 +6520,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65176520
let cur_counterparty_commitment_transaction_number = Readable::read(reader)?;
65186521
let value_to_self_msat = Readable::read(reader)?;
65196522

6523+
let max_accepted_htlcs = Readable::read(reader)?;
65206524
let pending_inbound_htlc_count: u64 = Readable::read(reader)?;
6521-
let mut pending_inbound_htlcs = Vec::with_capacity(cmp::min(pending_inbound_htlc_count as usize, OUR_MAX_HTLCS as usize));
6525+
6526+
let mut pending_inbound_htlcs = Vec::with_capacity(cmp::min(pending_inbound_htlc_count as usize, max_accepted_htlcs as usize));
65226527
for _ in 0..pending_inbound_htlc_count {
65236528
pending_inbound_htlcs.push(InboundHTLCOutput {
65246529
htlc_id: Readable::read(reader)?,
@@ -6536,7 +6541,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65366541
}
65376542

65386543
let pending_outbound_htlc_count: u64 = Readable::read(reader)?;
6539-
let mut pending_outbound_htlcs = Vec::with_capacity(cmp::min(pending_outbound_htlc_count as usize, OUR_MAX_HTLCS as usize));
6544+
let mut pending_outbound_htlcs = Vec::with_capacity(cmp::min(pending_outbound_htlc_count as usize, max_accepted_htlcs as usize));
65406545
for _ in 0..pending_outbound_htlc_count {
65416546
pending_outbound_htlcs.push(OutboundHTLCOutput {
65426547
htlc_id: Readable::read(reader)?,
@@ -6565,7 +6570,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65656570
}
65666571

65676572
let holding_cell_htlc_update_count: u64 = Readable::read(reader)?;
6568-
let mut holding_cell_htlc_updates = Vec::with_capacity(cmp::min(holding_cell_htlc_update_count as usize, OUR_MAX_HTLCS as usize*2));
6573+
let mut holding_cell_htlc_updates = Vec::with_capacity(cmp::min(holding_cell_htlc_update_count as usize, max_accepted_htlcs as usize*2));
65696574
for _ in 0..holding_cell_htlc_update_count {
65706575
holding_cell_htlc_updates.push(match <u8 as Readable>::read(reader)? {
65716576
0 => HTLCUpdateAwaitingACK::AddHTLC {
@@ -6598,13 +6603,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65986603
let monitor_pending_commitment_signed = Readable::read(reader)?;
65996604

66006605
let monitor_pending_forwards_count: u64 = Readable::read(reader)?;
6601-
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, OUR_MAX_HTLCS as usize));
6606+
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, max_accepted_htlcs as usize));
66026607
for _ in 0..monitor_pending_forwards_count {
66036608
monitor_pending_forwards.push((Readable::read(reader)?, Readable::read(reader)?));
66046609
}
66056610

66066611
let monitor_pending_failures_count: u64 = Readable::read(reader)?;
6607-
let mut monitor_pending_failures = Vec::with_capacity(cmp::min(monitor_pending_failures_count as usize, OUR_MAX_HTLCS as usize));
6612+
let mut monitor_pending_failures = Vec::with_capacity(cmp::min(monitor_pending_failures_count as usize, max_accepted_htlcs as usize));
66086613
for _ in 0..monitor_pending_failures_count {
66096614
monitor_pending_failures.push((Readable::read(reader)?, Readable::read(reader)?, Readable::read(reader)?));
66106615
}
@@ -6822,6 +6827,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68226827
cur_counterparty_commitment_transaction_number,
68236828
value_to_self_msat,
68246829

6830+
max_accepted_htlcs,
68256831
pending_inbound_htlcs,
68266832
pending_outbound_htlcs,
68276833
holding_cell_htlc_updates,

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ fn holding_cell_htlc_counting() {
10991099
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2);
11001100

11011101
let mut payments = Vec::new();
1102-
for _ in 0..crate::ln::channel::OUR_MAX_HTLCS {
1102+
for _ in 0..50 {
11031103
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[2], 100000);
11041104
nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap();
11051105
payments.push((payment_preimage, payment_hash));
@@ -6209,11 +6209,11 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
62096209
onion_routing_packet: onion_packet.clone(),
62106210
};
62116211

6212-
for i in 0..super::channel::OUR_MAX_HTLCS {
6212+
for i in 0..50 {
62136213
msg.htlc_id = i as u64;
62146214
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
62156215
}
6216-
msg.htlc_id = (super::channel::OUR_MAX_HTLCS) as u64;
6216+
msg.htlc_id = (50) as u64;
62176217
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
62186218

62196219
assert!(nodes[1].node.list_channels().is_empty());

0 commit comments

Comments
 (0)