Skip to content

Commit d2909e5

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

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
@@ -530,6 +530,7 @@ 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,
533534
pending_inbound_htlcs: Vec<InboundHTLCOutput>,
534535
pending_outbound_htlcs: Vec<OutboundHTLCOutput>,
535536
holding_cell_htlc_updates: Vec<HTLCUpdateAwaitingACK>,
@@ -653,7 +654,6 @@ pub(super) struct Channel<Signer: ChannelSigner> {
653654
pub counterparty_max_accepted_htlcs: u16,
654655
#[cfg(not(test))]
655656
counterparty_max_accepted_htlcs: u16,
656-
//implied by OUR_MAX_HTLCS: max_accepted_htlcs: u16,
657657
minimum_depth: Option<u32>,
658658

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

759-
pub const OUR_MAX_HTLCS: u16 = 50; //TODO
760759

761760
pub(crate) fn commitment_tx_base_weight(opt_anchors: bool) -> u64 {
762761
const COMMITMENT_TX_BASE_WEIGHT: u64 = 724;
@@ -1027,6 +1026,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
10271026
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
10281027
value_to_self_msat,
10291028

1029+
max_accepted_htlcs: 50,
10301030
pending_inbound_htlcs: Vec::new(),
10311031
pending_outbound_htlcs: Vec::new(),
10321032
holding_cell_htlc_updates: Vec::new(),
@@ -1373,6 +1373,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
13731373
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
13741374
value_to_self_msat: msg.push_msat,
13751375

1376+
max_accepted_htlcs: msg.max_accepted_htlcs,
13761377
pending_inbound_htlcs: Vec::new(),
13771378
pending_outbound_htlcs: Vec::new(),
13781379
holding_cell_htlc_updates: Vec::new(),
@@ -2874,8 +2875,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
28742875

28752876
let inbound_stats = self.get_inbound_pending_htlc_stats(None);
28762877
let outbound_stats = self.get_outbound_pending_htlc_stats(None);
2877-
if inbound_stats.pending_htlcs + 1 > OUR_MAX_HTLCS as u32 {
2878-
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", OUR_MAX_HTLCS)));
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)));
28792880
}
28802881
if inbound_stats.pending_htlcs_value_msat + msg.amount_msat > self.holder_max_htlc_value_in_flight_msat {
28812882
return Err(ChannelError::Close(format!("Remote HTLC add would put them over our max HTLC value ({})", self.holder_max_htlc_value_in_flight_msat)));
@@ -5313,7 +5314,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53135314
htlc_minimum_msat: self.holder_htlc_minimum_msat,
53145315
feerate_per_kw: self.feerate_per_kw as u32,
53155316
to_self_delay: self.get_holder_selected_contest_delay(),
5316-
max_accepted_htlcs: OUR_MAX_HTLCS,
5317+
max_accepted_htlcs: self.max_accepted_htlcs,
53175318
funding_pubkey: keys.funding_pubkey,
53185319
revocation_basepoint: keys.revocation_basepoint,
53195320
payment_point: keys.payment_point,
@@ -5380,7 +5381,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53805381
htlc_minimum_msat: self.holder_htlc_minimum_msat,
53815382
minimum_depth: self.minimum_depth.unwrap(),
53825383
to_self_delay: self.get_holder_selected_contest_delay(),
5383-
max_accepted_htlcs: OUR_MAX_HTLCS,
5384+
max_accepted_htlcs: self.max_accepted_htlcs,
53845385
funding_pubkey: keys.funding_pubkey,
53855386
revocation_basepoint: keys.revocation_basepoint,
53865387
payment_point: keys.payment_point,
@@ -6275,6 +6276,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
62756276
self.cur_counterparty_commitment_transaction_number.write(writer)?;
62766277
self.value_to_self_msat.write(writer)?;
62776278

6279+
self.max_accepted_htlcs.write(writer)?;
62786280
let mut dropped_inbound_htlcs = 0;
62796281
for htlc in self.pending_inbound_htlcs.iter() {
62806282
if let InboundHTLCState::RemoteAnnounced(_) = htlc.state {
@@ -6521,6 +6523,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
65216523
(23, channel_ready_event_emitted, option),
65226524
(25, user_id_high_opt, option),
65236525
(27, self.channel_keys_id, required),
6526+
(28, Some(self.max_accepted_htlcs), option),
65246527
(29, self.temporary_channel_id, option),
65256528
(31, channel_pending_event_emitted, option),
65266529
});
@@ -6588,8 +6591,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65886591
let cur_counterparty_commitment_transaction_number = Readable::read(reader)?;
65896592
let value_to_self_msat = Readable::read(reader)?;
65906593

6594+
let max_accepted_htlcs = Readable::read(reader)?;
65916595
let pending_inbound_htlc_count: u64 = Readable::read(reader)?;
6592-
let mut pending_inbound_htlcs = Vec::with_capacity(cmp::min(pending_inbound_htlc_count as usize, OUR_MAX_HTLCS as usize));
6596+
6597+
let mut pending_inbound_htlcs = Vec::with_capacity(cmp::min(pending_inbound_htlc_count as usize, max_accepted_htlcs as usize));
65936598
for _ in 0..pending_inbound_htlc_count {
65946599
pending_inbound_htlcs.push(InboundHTLCOutput {
65956600
htlc_id: Readable::read(reader)?,
@@ -6607,7 +6612,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66076612
}
66086613

66096614
let pending_outbound_htlc_count: u64 = Readable::read(reader)?;
6610-
let mut pending_outbound_htlcs = Vec::with_capacity(cmp::min(pending_outbound_htlc_count as usize, OUR_MAX_HTLCS as usize));
6615+
let mut pending_outbound_htlcs = Vec::with_capacity(cmp::min(pending_outbound_htlc_count as usize, max_accepted_htlcs as usize));
66116616
for _ in 0..pending_outbound_htlc_count {
66126617
pending_outbound_htlcs.push(OutboundHTLCOutput {
66136618
htlc_id: Readable::read(reader)?,
@@ -6636,7 +6641,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66366641
}
66376642

66386643
let holding_cell_htlc_update_count: u64 = Readable::read(reader)?;
6639-
let mut holding_cell_htlc_updates = Vec::with_capacity(cmp::min(holding_cell_htlc_update_count as usize, OUR_MAX_HTLCS as usize*2));
6644+
let mut holding_cell_htlc_updates = Vec::with_capacity(cmp::min(holding_cell_htlc_update_count as usize, max_accepted_htlcs as usize*2));
66406645
for _ in 0..holding_cell_htlc_update_count {
66416646
holding_cell_htlc_updates.push(match <u8 as Readable>::read(reader)? {
66426647
0 => HTLCUpdateAwaitingACK::AddHTLC {
@@ -6669,13 +6674,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66696674
let monitor_pending_commitment_signed = Readable::read(reader)?;
66706675

66716676
let monitor_pending_forwards_count: u64 = Readable::read(reader)?;
6672-
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, OUR_MAX_HTLCS as usize));
6677+
let mut monitor_pending_forwards = Vec::with_capacity(cmp::min(monitor_pending_forwards_count as usize, max_accepted_htlcs as usize));
66736678
for _ in 0..monitor_pending_forwards_count {
66746679
monitor_pending_forwards.push((Readable::read(reader)?, Readable::read(reader)?));
66756680
}
66766681

66776682
let monitor_pending_failures_count: u64 = Readable::read(reader)?;
6678-
let mut monitor_pending_failures = Vec::with_capacity(cmp::min(monitor_pending_failures_count as usize, OUR_MAX_HTLCS as usize));
6683+
let mut monitor_pending_failures = Vec::with_capacity(cmp::min(monitor_pending_failures_count as usize, max_accepted_htlcs as usize));
66796684
for _ in 0..monitor_pending_failures_count {
66806685
monitor_pending_failures.push((Readable::read(reader)?, Readable::read(reader)?, Readable::read(reader)?));
66816686
}
@@ -6898,6 +6903,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68986903
cur_counterparty_commitment_transaction_number,
68996904
value_to_self_msat,
69006905

6906+
max_accepted_htlcs,
69016907
pending_inbound_htlcs,
69026908
pending_outbound_htlcs,
69036909
holding_cell_htlc_updates,

lightning/src/ln/functional_tests.rs

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

11091109
let mut payments = Vec::new();
1110-
for _ in 0..crate::ln::channel::OUR_MAX_HTLCS {
1110+
for _ in 0..50 {
11111111
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[2], 100000);
11121112
nodes[1].node.send_payment_with_route(&route, payment_hash,
11131113
RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)).unwrap();
@@ -6278,11 +6278,11 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
62786278
onion_routing_packet: onion_packet.clone(),
62796279
};
62806280

6281-
for i in 0..super::channel::OUR_MAX_HTLCS {
6281+
for i in 0..50 {
62826282
msg.htlc_id = i as u64;
62836283
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
62846284
}
6285-
msg.htlc_id = (super::channel::OUR_MAX_HTLCS) as u64;
6285+
msg.htlc_id = (50) as u64;
62866286
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
62876287

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

0 commit comments

Comments
 (0)