@@ -653,7 +653,7 @@ pub(super) struct Channel<Signer: ChannelSigner> {
653653 pub counterparty_max_accepted_htlcs : u16 ,
654654 #[ cfg( not( test) ) ]
655655 counterparty_max_accepted_htlcs : u16 ,
656- //implied by OUR_MAX_HTLCS: max_accepted_htlcs : u16,
656+ holder_max_accepted_htlcs : u16 ,
657657 minimum_depth : Option < u32 > ,
658658
659659 counterparty_forwarding_info : Option < CounterpartyForwardingInfo > ,
@@ -756,7 +756,7 @@ struct CommitmentTxInfoCached {
756756 feerate : u32 ,
757757}
758758
759- pub const OUR_MAX_HTLCS : u16 = 50 ; //TODO
759+ pub const DEFAULT_MAX_HTLCS : u16 = 50 ;
760760
761761pub ( crate ) fn commitment_tx_base_weight ( opt_anchors : bool ) -> u64 {
762762 const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
@@ -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 : cmp:: min ( config. channel_handshake_config . our_max_accepted_htlcs , MAX_HTLCS ) ,
10751076 minimum_depth : None , // Filled in in accept_channel
10761077
10771078 counterparty_forwarding_info : None ,
@@ -1419,6 +1420,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
14191420 counterparty_htlc_minimum_msat : msg. htlc_minimum_msat ,
14201421 holder_htlc_minimum_msat : if config. channel_handshake_config . our_htlc_minimum_msat == 0 { 1 } else { config. channel_handshake_config . our_htlc_minimum_msat } ,
14211422 counterparty_max_accepted_htlcs : msg. max_accepted_htlcs ,
1423+ holder_max_accepted_htlcs : cmp:: min ( config. channel_handshake_config . our_max_accepted_htlcs , MAX_HTLCS ) ,
14221424 minimum_depth : Some ( cmp:: max ( config. channel_handshake_config . minimum_depth , 1 ) ) ,
14231425
14241426 counterparty_forwarding_info : None ,
@@ -2874,8 +2876,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
28742876
28752877 let inbound_stats = self . get_inbound_pending_htlc_stats ( None ) ;
28762878 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 ) ) ) ;
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 ) ) ) ;
28792881 }
28802882 if inbound_stats. pending_htlcs_value_msat + msg. amount_msat > self . holder_max_htlc_value_in_flight_msat {
28812883 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 +5315,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53135315 htlc_minimum_msat : self . holder_htlc_minimum_msat ,
53145316 feerate_per_kw : self . feerate_per_kw as u32 ,
53155317 to_self_delay : self . get_holder_selected_contest_delay ( ) ,
5316- max_accepted_htlcs : OUR_MAX_HTLCS ,
5318+ max_accepted_htlcs : self . holder_max_accepted_htlcs ,
53175319 funding_pubkey : keys. funding_pubkey ,
53185320 revocation_basepoint : keys. revocation_basepoint ,
53195321 payment_point : keys. payment_point ,
@@ -5380,7 +5382,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
53805382 htlc_minimum_msat : self . holder_htlc_minimum_msat ,
53815383 minimum_depth : self . minimum_depth . unwrap ( ) ,
53825384 to_self_delay : self . get_holder_selected_contest_delay ( ) ,
5383- max_accepted_htlcs : OUR_MAX_HTLCS ,
5385+ max_accepted_htlcs : self . holder_max_accepted_htlcs ,
53845386 funding_pubkey : keys. funding_pubkey ,
53855387 revocation_basepoint : keys. revocation_basepoint ,
53865388 payment_point : keys. payment_point ,
@@ -6496,6 +6498,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
64966498 // we write the high bytes as an option here.
64976499 let user_id_high_opt = Some ( ( self . user_id >> 64 ) as u64 ) ;
64986500
6501+ let holder_max_accepted_htlcs = if self . holder_max_accepted_htlcs == DEFAULT_MAX_HTLCS { None } else { Some ( self . holder_max_accepted_htlcs ) } ;
6502+
64996503 write_tlv_fields ! ( writer, {
65006504 ( 0 , self . announcement_sigs, option) ,
65016505 // minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -6521,6 +6525,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
65216525 ( 23 , channel_ready_event_emitted, option) ,
65226526 ( 25 , user_id_high_opt, option) ,
65236527 ( 27 , self . channel_keys_id, required) ,
6528+ ( 28 , holder_max_accepted_htlcs, option) ,
65246529 ( 29 , self . temporary_channel_id, option) ,
65256530 ( 31 , channel_pending_event_emitted, option) ,
65266531 } ) ;
@@ -6589,7 +6594,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
65896594 let value_to_self_msat = Readable :: read ( reader) ?;
65906595
65916596 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 ) ) ;
6597+
6598+ let mut pending_inbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_inbound_htlc_count as usize , DEFAULT_MAX_HTLCS as usize ) ) ;
65936599 for _ in 0 ..pending_inbound_htlc_count {
65946600 pending_inbound_htlcs. push ( InboundHTLCOutput {
65956601 htlc_id : Readable :: read ( reader) ?,
@@ -6607,7 +6613,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66076613 }
66086614
66096615 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 ) ) ;
6616+ let mut pending_outbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_outbound_htlc_count as usize , DEFAULT_MAX_HTLCS as usize ) ) ;
66116617 for _ in 0 ..pending_outbound_htlc_count {
66126618 pending_outbound_htlcs. push ( OutboundHTLCOutput {
66136619 htlc_id : Readable :: read ( reader) ?,
@@ -6636,7 +6642,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66366642 }
66376643
66386644 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 ) ) ;
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 ) ) ;
66406646 for _ in 0 ..holding_cell_htlc_update_count {
66416647 holding_cell_htlc_updates. push ( match <u8 as Readable >:: read ( reader) ? {
66426648 0 => HTLCUpdateAwaitingACK :: AddHTLC {
@@ -6669,13 +6675,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
66696675 let monitor_pending_commitment_signed = Readable :: read ( reader) ?;
66706676
66716677 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 ) ) ;
6678+ let mut monitor_pending_forwards = Vec :: with_capacity ( cmp:: min ( monitor_pending_forwards_count as usize , DEFAULT_MAX_HTLCS as usize ) ) ;
66736679 for _ in 0 ..monitor_pending_forwards_count {
66746680 monitor_pending_forwards. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
66756681 }
66766682
66776683 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 ) ) ;
6684+ let mut monitor_pending_failures = Vec :: with_capacity ( cmp:: min ( monitor_pending_failures_count as usize , DEFAULT_MAX_HTLCS as usize ) ) ;
66796685 for _ in 0 ..monitor_pending_failures_count {
66806686 monitor_pending_failures. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
66816687 }
@@ -6796,6 +6802,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
67966802 let mut user_id_high_opt: Option < u64 > = None ;
67976803 let mut channel_keys_id: Option < [ u8 ; 32 ] > = None ;
67986804 let mut temporary_channel_id: Option < [ u8 ; 32 ] > = None ;
6805+ let mut holder_max_accepted_htlcs: Option < u16 > = None ;
67996806
68006807 read_tlv_fields ! ( reader, {
68016808 ( 0 , announcement_sigs, option) ,
@@ -6816,6 +6823,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68166823 ( 23 , channel_ready_event_emitted, option) ,
68176824 ( 25 , user_id_high_opt, option) ,
68186825 ( 27 , channel_keys_id, option) ,
6826+ ( 28 , holder_max_accepted_htlcs, option) ,
68196827 ( 29 , temporary_channel_id, option) ,
68206828 ( 31 , channel_pending_event_emitted, option) ,
68216829 } ) ;
@@ -6870,6 +6878,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68706878 // separate u64 values.
68716879 let user_id = user_id_low as u128 + ( ( user_id_high_opt. unwrap_or ( 0 ) as u128 ) << 64 ) ;
68726880
6881+ let holder_max_accepted_htlcs = holder_max_accepted_htlcs. unwrap_or ( DEFAULT_MAX_HTLCS ) ;
6882+
68736883 Ok ( Channel {
68746884 user_id,
68756885
@@ -6898,6 +6908,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
68986908 cur_counterparty_commitment_transaction_number,
68996909 value_to_self_msat,
69006910
6911+ holder_max_accepted_htlcs,
69016912 pending_inbound_htlcs,
69026913 pending_outbound_htlcs,
69036914 holding_cell_htlc_updates,
0 commit comments