@@ -530,7 +530,6 @@ pub(super) struct Channel<Signer: ChannelSigner> {
530
530
cur_holder_commitment_transaction_number : u64 ,
531
531
cur_counterparty_commitment_transaction_number : u64 ,
532
532
value_to_self_msat : u64 , // Excluding all pending_htlcs, excluding fees
533
- max_accepted_htlcs : u16 ,
534
533
pending_inbound_htlcs : Vec < InboundHTLCOutput > ,
535
534
pending_outbound_htlcs : Vec < OutboundHTLCOutput > ,
536
535
holding_cell_htlc_updates : Vec < HTLCUpdateAwaitingACK > ,
@@ -654,6 +653,7 @@ pub(super) struct Channel<Signer: ChannelSigner> {
654
653
pub counterparty_max_accepted_htlcs : u16 ,
655
654
#[ cfg( not( test) ) ]
656
655
counterparty_max_accepted_htlcs : u16 ,
656
+ holder_max_accepted_htlcs : u16 ,
657
657
minimum_depth : Option < u32 > ,
658
658
659
659
counterparty_forwarding_info : Option < CounterpartyForwardingInfo > ,
@@ -756,6 +756,7 @@ struct CommitmentTxInfoCached {
756
756
feerate : u32 ,
757
757
}
758
758
759
+ pub const DEFAULT_MAX_HTLCS : u16 = 50 ;
759
760
760
761
pub ( crate ) fn commitment_tx_base_weight ( opt_anchors : bool ) -> u64 {
761
762
const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
@@ -1026,7 +1027,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1026
1027
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1027
1028
value_to_self_msat,
1028
1029
1029
- max_accepted_htlcs : config. channel_handshake_config . max_accepted_htlcs ,
1030
1030
pending_inbound_htlcs : Vec :: new ( ) ,
1031
1031
pending_outbound_htlcs : Vec :: new ( ) ,
1032
1032
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -1072,6 +1072,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1072
1072
counterparty_htlc_minimum_msat : 0 ,
1073
1073
holder_htlc_minimum_msat : if config. channel_handshake_config . our_htlc_minimum_msat == 0 { 1 } else { config. channel_handshake_config . our_htlc_minimum_msat } ,
1074
1074
counterparty_max_accepted_htlcs : 0 ,
1075
+ holder_max_accepted_htlcs : config. channel_handshake_config . our_max_accepted_htlcs ,
1075
1076
minimum_depth : None , // Filled in in accept_channel
1076
1077
1077
1078
counterparty_forwarding_info : None ,
@@ -1373,7 +1374,6 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1373
1374
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1374
1375
value_to_self_msat : msg. push_msat ,
1375
1376
1376
- max_accepted_htlcs : config. channel_handshake_config . max_accepted_htlcs ,
1377
1377
pending_inbound_htlcs : Vec :: new ( ) ,
1378
1378
pending_outbound_htlcs : Vec :: new ( ) ,
1379
1379
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -1420,6 +1420,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1420
1420
counterparty_htlc_minimum_msat : msg. htlc_minimum_msat ,
1421
1421
holder_htlc_minimum_msat : if config. channel_handshake_config . our_htlc_minimum_msat == 0 { 1 } else { config. channel_handshake_config . our_htlc_minimum_msat } ,
1422
1422
counterparty_max_accepted_htlcs : msg. max_accepted_htlcs ,
1423
+ holder_max_accepted_htlcs : config. channel_handshake_config . our_max_accepted_htlcs ,
1423
1424
minimum_depth : Some ( cmp:: max ( config. channel_handshake_config . minimum_depth , 1 ) ) ,
1424
1425
1425
1426
counterparty_forwarding_info : None ,
@@ -2875,8 +2876,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2875
2876
2876
2877
let inbound_stats = self . get_inbound_pending_htlc_stats ( None ) ;
2877
2878
let outbound_stats = self . get_outbound_pending_htlc_stats ( None ) ;
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 ) ) ) ;
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 ) ) ) ;
2880
2881
}
2881
2882
if inbound_stats. pending_htlcs_value_msat + msg. amount_msat > self . holder_max_htlc_value_in_flight_msat {
2882
2883
return Err ( ChannelError :: Close ( format ! ( "Remote HTLC add would put them over our max HTLC value ({})" , self . holder_max_htlc_value_in_flight_msat) ) ) ;
@@ -5314,7 +5315,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5314
5315
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5315
5316
feerate_per_kw : self . feerate_per_kw as u32 ,
5316
5317
to_self_delay : self . get_holder_selected_contest_delay ( ) ,
5317
- max_accepted_htlcs : self . max_accepted_htlcs ,
5318
+ max_accepted_htlcs : self . holder_max_accepted_htlcs ,
5318
5319
funding_pubkey : keys. funding_pubkey ,
5319
5320
revocation_basepoint : keys. revocation_basepoint ,
5320
5321
payment_point : keys. payment_point ,
@@ -5381,7 +5382,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5381
5382
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5382
5383
minimum_depth : self . minimum_depth . unwrap ( ) ,
5383
5384
to_self_delay : self . get_holder_selected_contest_delay ( ) ,
5384
- max_accepted_htlcs : self . max_accepted_htlcs ,
5385
+ max_accepted_htlcs : self . holder_max_accepted_htlcs ,
5385
5386
funding_pubkey : keys. funding_pubkey ,
5386
5387
revocation_basepoint : keys. revocation_basepoint ,
5387
5388
payment_point : keys. payment_point ,
@@ -6497,7 +6498,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6497
6498
// we write the high bytes as an option here.
6498
6499
let user_id_high_opt = Some ( ( self . user_id >> 64 ) as u64 ) ;
6499
6500
6500
- let max_accepted_htlcs = if self . max_accepted_htlcs == 50 { None } else { Some ( self . max_accepted_htlcs ) } ;
6501
+ let holder_max_accepted_htlcs = if self . holder_max_accepted_htlcs == 50 { None } else { Some ( self . holder_max_accepted_htlcs ) } ;
6501
6502
6502
6503
write_tlv_fields ! ( writer, {
6503
6504
( 0 , self . announcement_sigs, option) ,
@@ -6524,7 +6525,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6524
6525
( 23 , channel_ready_event_emitted, option) ,
6525
6526
( 25 , user_id_high_opt, option) ,
6526
6527
( 27 , self . channel_keys_id, required) ,
6527
- ( 28 , max_accepted_htlcs , option) ,
6528
+ ( 28 , holder_max_accepted_htlcs , option) ,
6528
6529
( 29 , self . temporary_channel_id, option) ,
6529
6530
( 31 , channel_pending_event_emitted, option) ,
6530
6531
} ) ;
@@ -6594,9 +6595,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6594
6595
6595
6596
let pending_inbound_htlc_count: u64 = Readable :: read ( reader) ?;
6596
6597
6597
- let channel_handshake_config = ChannelHandshakeConfig :: default ( ) ;
6598
-
6599
- let mut pending_inbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_inbound_htlc_count as usize , channel_handshake_config. max_accepted_htlcs as usize ) ) ;
6598
+ let mut pending_inbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_inbound_htlc_count as usize , DEFAULT_MAX_HTLCS as usize ) ) ;
6600
6599
for _ in 0 ..pending_inbound_htlc_count {
6601
6600
pending_inbound_htlcs. push ( InboundHTLCOutput {
6602
6601
htlc_id : Readable :: read ( reader) ?,
@@ -6614,7 +6613,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6614
6613
}
6615
6614
6616
6615
let pending_outbound_htlc_count: u64 = Readable :: read ( reader) ?;
6617
- let mut pending_outbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_outbound_htlc_count as usize , channel_handshake_config . max_accepted_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 ) ) ;
6618
6617
for _ in 0 ..pending_outbound_htlc_count {
6619
6618
pending_outbound_htlcs. push ( OutboundHTLCOutput {
6620
6619
htlc_id : Readable :: read ( reader) ?,
@@ -6643,7 +6642,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6643
6642
}
6644
6643
6645
6644
let holding_cell_htlc_update_count: u64 = Readable :: read ( reader) ?;
6646
- 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 ) ) ;
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 ) ) ;
6647
6646
for _ in 0 ..holding_cell_htlc_update_count {
6648
6647
holding_cell_htlc_updates. push ( match <u8 as Readable >:: read ( reader) ? {
6649
6648
0 => HTLCUpdateAwaitingACK :: AddHTLC {
@@ -6676,13 +6675,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6676
6675
let monitor_pending_commitment_signed = Readable :: read ( reader) ?;
6677
6676
6678
6677
let monitor_pending_forwards_count: u64 = Readable :: read ( reader) ?;
6679
- let mut monitor_pending_forwards = Vec :: with_capacity ( cmp:: min ( monitor_pending_forwards_count as usize , channel_handshake_config . max_accepted_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 ) ) ;
6680
6679
for _ in 0 ..monitor_pending_forwards_count {
6681
6680
monitor_pending_forwards. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6682
6681
}
6683
6682
6684
6683
let monitor_pending_failures_count: u64 = Readable :: read ( reader) ?;
6685
- let mut monitor_pending_failures = Vec :: with_capacity ( cmp:: min ( monitor_pending_failures_count as usize , channel_handshake_config . max_accepted_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 ) ) ;
6686
6685
for _ in 0 ..monitor_pending_failures_count {
6687
6686
monitor_pending_failures. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6688
6687
}
@@ -6803,7 +6802,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6803
6802
let mut user_id_high_opt: Option < u64 > = None ;
6804
6803
let mut channel_keys_id: Option < [ u8 ; 32 ] > = None ;
6805
6804
let mut temporary_channel_id: Option < [ u8 ; 32 ] > = None ;
6806
- let mut max_accepted_htlcs : Option < u16 > = None ;
6805
+ let mut holder_max_accepted_htlcs : Option < u16 > = None ;
6807
6806
6808
6807
read_tlv_fields ! ( reader, {
6809
6808
( 0 , announcement_sigs, option) ,
@@ -6824,7 +6823,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6824
6823
( 23 , channel_ready_event_emitted, option) ,
6825
6824
( 25 , user_id_high_opt, option) ,
6826
6825
( 27 , channel_keys_id, option) ,
6827
- ( 28 , max_accepted_htlcs , option) ,
6826
+ ( 28 , holder_max_accepted_htlcs , option) ,
6828
6827
( 29 , temporary_channel_id, option) ,
6829
6828
( 31 , channel_pending_event_emitted, option) ,
6830
6829
} ) ;
@@ -6879,7 +6878,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6879
6878
// separate u64 values.
6880
6879
let user_id = user_id_low as u128 + ( ( user_id_high_opt. unwrap_or ( 0 ) as u128 ) << 64 ) ;
6881
6880
6882
- let max_accepted_htlcs = max_accepted_htlcs . unwrap_or ( channel_handshake_config . max_accepted_htlcs ) ;
6881
+ let holder_max_accepted_htlcs = holder_max_accepted_htlcs . unwrap_or ( DEFAULT_MAX_HTLCS ) ;
6883
6882
6884
6883
Ok ( Channel {
6885
6884
user_id,
@@ -6909,7 +6908,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6909
6908
cur_counterparty_commitment_transaction_number,
6910
6909
value_to_self_msat,
6911
6910
6912
- max_accepted_htlcs ,
6911
+ holder_max_accepted_htlcs ,
6913
6912
pending_inbound_htlcs,
6914
6913
pending_outbound_htlcs,
6915
6914
holding_cell_htlc_updates,
0 commit comments