@@ -529,7 +529,6 @@ pub(super) struct Channel<Signer: ChannelSigner> {
529
529
cur_holder_commitment_transaction_number : u64 ,
530
530
cur_counterparty_commitment_transaction_number : u64 ,
531
531
value_to_self_msat : u64 , // Excluding all pending_htlcs, excluding fees
532
- max_accepted_htlcs : u16 ,
533
532
pending_inbound_htlcs : Vec < InboundHTLCOutput > ,
534
533
pending_outbound_htlcs : Vec < OutboundHTLCOutput > ,
535
534
holding_cell_htlc_updates : Vec < HTLCUpdateAwaitingACK > ,
@@ -653,6 +652,7 @@ pub(super) struct Channel<Signer: ChannelSigner> {
653
652
pub counterparty_max_accepted_htlcs : u16 ,
654
653
#[ cfg( not( test) ) ]
655
654
counterparty_max_accepted_htlcs : u16 ,
655
+ holder_max_accepted_htlcs : u16 ,
656
656
minimum_depth : Option < u32 > ,
657
657
658
658
counterparty_forwarding_info : Option < CounterpartyForwardingInfo > ,
@@ -752,6 +752,7 @@ struct CommitmentTxInfoCached {
752
752
feerate : u32 ,
753
753
}
754
754
755
+ pub const DEFAULT_MAX_HTLCS : u16 = 50 ;
755
756
756
757
pub ( crate ) fn commitment_tx_base_weight ( opt_anchors : bool ) -> u64 {
757
758
const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
@@ -1019,7 +1020,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1019
1020
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1020
1021
value_to_self_msat,
1021
1022
1022
- max_accepted_htlcs : config. channel_handshake_config . max_accepted_htlcs ,
1023
1023
pending_inbound_htlcs : Vec :: new ( ) ,
1024
1024
pending_outbound_htlcs : Vec :: new ( ) ,
1025
1025
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -1065,6 +1065,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1065
1065
counterparty_htlc_minimum_msat : 0 ,
1066
1066
holder_htlc_minimum_msat : if config. channel_handshake_config . our_htlc_minimum_msat == 0 { 1 } else { config. channel_handshake_config . our_htlc_minimum_msat } ,
1067
1067
counterparty_max_accepted_htlcs : 0 ,
1068
+ holder_max_accepted_htlcs : config. channel_handshake_config . our_max_accepted_htlcs ,
1068
1069
minimum_depth : None , // Filled in in accept_channel
1069
1070
1070
1071
counterparty_forwarding_info : None ,
@@ -1364,7 +1365,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1364
1365
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1365
1366
value_to_self_msat : msg. push_msat ,
1366
1367
1367
- max_accepted_htlcs : config. channel_handshake_config . max_accepted_htlcs ,
1368
1368
pending_inbound_htlcs : Vec :: new ( ) ,
1369
1369
pending_outbound_htlcs : Vec :: new ( ) ,
1370
1370
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -1411,6 +1411,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1411
1411
counterparty_htlc_minimum_msat : msg. htlc_minimum_msat ,
1412
1412
holder_htlc_minimum_msat : if config. channel_handshake_config . our_htlc_minimum_msat == 0 { 1 } else { config. channel_handshake_config . our_htlc_minimum_msat } ,
1413
1413
counterparty_max_accepted_htlcs : msg. max_accepted_htlcs ,
1414
+ holder_max_accepted_htlcs : config. channel_handshake_config . our_max_accepted_htlcs ,
1414
1415
minimum_depth : Some ( cmp:: max ( config. channel_handshake_config . minimum_depth , 1 ) ) ,
1415
1416
1416
1417
counterparty_forwarding_info : None ,
@@ -2863,8 +2864,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2863
2864
2864
2865
let inbound_stats = self . get_inbound_pending_htlc_stats ( None ) ;
2865
2866
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 ) ) ) ;
2868
2869
}
2869
2870
if inbound_stats. pending_htlcs_value_msat + msg. amount_msat > self . holder_max_htlc_value_in_flight_msat {
2870
2871
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> {
5254
5255
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5255
5256
feerate_per_kw : self . feerate_per_kw as u32 ,
5256
5257
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 ,
5258
5259
funding_pubkey : keys. funding_pubkey ,
5259
5260
revocation_basepoint : keys. revocation_basepoint ,
5260
5261
payment_point : keys. payment_point ,
@@ -5321,7 +5322,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5321
5322
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5322
5323
minimum_depth : self . minimum_depth . unwrap ( ) ,
5323
5324
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 ,
5325
5326
funding_pubkey : keys. funding_pubkey ,
5326
5327
revocation_basepoint : keys. revocation_basepoint ,
5327
5328
payment_point : keys. payment_point ,
@@ -6428,7 +6429,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6428
6429
// we write the high bytes as an option here.
6429
6430
let user_id_high_opt = Some ( ( self . user_id >> 64 ) as u64 ) ;
6430
6431
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 ) } ;
6432
6433
6433
6434
write_tlv_fields ! ( writer, {
6434
6435
( 0 , self . announcement_sigs, option) ,
@@ -6455,7 +6456,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6455
6456
( 23 , channel_ready_event_emitted, option) ,
6456
6457
( 25 , user_id_high_opt, option) ,
6457
6458
( 27 , self . channel_keys_id, required) ,
6458
- ( 28 , max_accepted_htlcs , option) ,
6459
+ ( 28 , holder_max_accepted_htlcs , option) ,
6459
6460
} ) ;
6460
6461
6461
6462
Ok ( ( ) )
@@ -6523,9 +6524,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6523
6524
6524
6525
let pending_inbound_htlc_count: u64 = Readable :: read ( reader) ?;
6525
6526
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 ) ) ;
6529
6528
for _ in 0 ..pending_inbound_htlc_count {
6530
6529
pending_inbound_htlcs. push ( InboundHTLCOutput {
6531
6530
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
6543
6542
}
6544
6543
6545
6544
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 ) ) ;
6547
6546
for _ in 0 ..pending_outbound_htlc_count {
6548
6547
pending_outbound_htlcs. push ( OutboundHTLCOutput {
6549
6548
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
6572
6571
}
6573
6572
6574
6573
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 ) ) ;
6576
6575
for _ in 0 ..holding_cell_htlc_update_count {
6577
6576
holding_cell_htlc_updates. push ( match <u8 as Readable >:: read ( reader) ? {
6578
6577
0 => HTLCUpdateAwaitingACK :: AddHTLC {
@@ -6605,13 +6604,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6605
6604
let monitor_pending_commitment_signed = Readable :: read ( reader) ?;
6606
6605
6607
6606
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 ) ) ;
6609
6608
for _ in 0 ..monitor_pending_forwards_count {
6610
6609
monitor_pending_forwards. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6611
6610
}
6612
6611
6613
6612
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 ) ) ;
6615
6614
for _ in 0 ..monitor_pending_failures_count {
6616
6615
monitor_pending_failures. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6617
6616
}
@@ -6730,7 +6729,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6730
6729
6731
6730
let mut user_id_high_opt: Option < u64 > = None ;
6732
6731
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 ;
6734
6733
6735
6734
read_tlv_fields ! ( reader, {
6736
6735
( 0 , announcement_sigs, option) ,
@@ -6751,7 +6750,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6751
6750
( 23 , channel_ready_event_emitted, option) ,
6752
6751
( 25 , user_id_high_opt, option) ,
6753
6752
( 27 , channel_keys_id, option) ,
6754
- ( 28 , max_accepted_htlcs , option) ,
6753
+ ( 28 , holder_max_accepted_htlcs , option) ,
6755
6754
} ) ;
6756
6755
6757
6756
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
6804
6803
// separate u64 values.
6805
6804
let user_id = user_id_low as u128 + ( ( user_id_high_opt. unwrap_or ( 0 ) as u128 ) << 64 ) ;
6806
6805
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 ) ;
6808
6807
6809
6808
Ok ( Channel {
6810
6809
user_id,
@@ -6833,7 +6832,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6833
6832
cur_counterparty_commitment_transaction_number,
6834
6833
value_to_self_msat,
6835
6834
6836
- max_accepted_htlcs ,
6835
+ holder_max_accepted_htlcs ,
6837
6836
pending_inbound_htlcs,
6838
6837
pending_outbound_htlcs,
6839
6838
holding_cell_htlc_updates,
0 commit comments