@@ -653,7 +653,7 @@ pub(super) struct Channel<Signer: ChannelSigner> {
653
653
pub counterparty_max_accepted_htlcs : u16 ,
654
654
#[ cfg( not( test) ) ]
655
655
counterparty_max_accepted_htlcs : u16 ,
656
- //implied by OUR_MAX_HTLCS: 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,7 +756,7 @@ struct CommitmentTxInfoCached {
756
756
feerate : u32 ,
757
757
}
758
758
759
- pub const OUR_MAX_HTLCS : u16 = 50 ; //TODO
759
+ pub const DEFAULT_MAX_HTLCS : u16 = 50 ;
760
760
761
761
pub ( crate ) fn commitment_tx_base_weight ( opt_anchors : bool ) -> u64 {
762
762
const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
@@ -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 ,
@@ -1419,6 +1420,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1419
1420
counterparty_htlc_minimum_msat : msg. htlc_minimum_msat ,
1420
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 } ,
1421
1422
counterparty_max_accepted_htlcs : msg. max_accepted_htlcs ,
1423
+ holder_max_accepted_htlcs : config. channel_handshake_config . our_max_accepted_htlcs ,
1422
1424
minimum_depth : Some ( cmp:: max ( config. channel_handshake_config . minimum_depth , 1 ) ) ,
1423
1425
1424
1426
counterparty_forwarding_info : None ,
@@ -2874,8 +2876,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2874
2876
2875
2877
let inbound_stats = self . get_inbound_pending_htlc_stats ( None ) ;
2876
2878
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 ) ) ) ;
2879
2881
}
2880
2882
if inbound_stats. pending_htlcs_value_msat + msg. amount_msat > self . holder_max_htlc_value_in_flight_msat {
2881
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) ) ) ;
@@ -5313,7 +5315,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5313
5315
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5314
5316
feerate_per_kw : self . feerate_per_kw as u32 ,
5315
5317
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 ,
5317
5319
funding_pubkey : keys. funding_pubkey ,
5318
5320
revocation_basepoint : keys. revocation_basepoint ,
5319
5321
payment_point : keys. payment_point ,
@@ -5380,7 +5382,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5380
5382
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5381
5383
minimum_depth : self . minimum_depth . unwrap ( ) ,
5382
5384
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 ,
5384
5386
funding_pubkey : keys. funding_pubkey ,
5385
5387
revocation_basepoint : keys. revocation_basepoint ,
5386
5388
payment_point : keys. payment_point ,
@@ -6496,6 +6498,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6496
6498
// we write the high bytes as an option here.
6497
6499
let user_id_high_opt = Some ( ( self . user_id >> 64 ) as u64 ) ;
6498
6500
6501
+ let holder_max_accepted_htlcs = if self . holder_max_accepted_htlcs == 50 { None } else { Some ( self . holder_max_accepted_htlcs ) } ;
6502
+
6499
6503
write_tlv_fields ! ( writer, {
6500
6504
( 0 , self . announcement_sigs, option) ,
6501
6505
// minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -6521,6 +6525,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6521
6525
( 23 , channel_ready_event_emitted, option) ,
6522
6526
( 25 , user_id_high_opt, option) ,
6523
6527
( 27 , self . channel_keys_id, required) ,
6528
+ ( 28 , holder_max_accepted_htlcs, option) ,
6524
6529
( 29 , self . temporary_channel_id, option) ,
6525
6530
( 31 , channel_pending_event_emitted, option) ,
6526
6531
} ) ;
@@ -6589,7 +6594,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6589
6594
let value_to_self_msat = Readable :: read ( reader) ?;
6590
6595
6591
6596
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 ) ) ;
6593
6599
for _ in 0 ..pending_inbound_htlc_count {
6594
6600
pending_inbound_htlcs. push ( InboundHTLCOutput {
6595
6601
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
6607
6613
}
6608
6614
6609
6615
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 ) ) ;
6611
6617
for _ in 0 ..pending_outbound_htlc_count {
6612
6618
pending_outbound_htlcs. push ( OutboundHTLCOutput {
6613
6619
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
6636
6642
}
6637
6643
6638
6644
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 ) ) ;
6640
6646
for _ in 0 ..holding_cell_htlc_update_count {
6641
6647
holding_cell_htlc_updates. push ( match <u8 as Readable >:: read ( reader) ? {
6642
6648
0 => HTLCUpdateAwaitingACK :: AddHTLC {
@@ -6669,13 +6675,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6669
6675
let monitor_pending_commitment_signed = Readable :: read ( reader) ?;
6670
6676
6671
6677
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 ) ) ;
6673
6679
for _ in 0 ..monitor_pending_forwards_count {
6674
6680
monitor_pending_forwards. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6675
6681
}
6676
6682
6677
6683
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 ) ) ;
6679
6685
for _ in 0 ..monitor_pending_failures_count {
6680
6686
monitor_pending_failures. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6681
6687
}
@@ -6796,6 +6802,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6796
6802
let mut user_id_high_opt: Option < u64 > = None ;
6797
6803
let mut channel_keys_id: Option < [ u8 ; 32 ] > = None ;
6798
6804
let mut temporary_channel_id: Option < [ u8 ; 32 ] > = None ;
6805
+ let mut holder_max_accepted_htlcs: Option < u16 > = None ;
6799
6806
6800
6807
read_tlv_fields ! ( reader, {
6801
6808
( 0 , announcement_sigs, option) ,
@@ -6816,6 +6823,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6816
6823
( 23 , channel_ready_event_emitted, option) ,
6817
6824
( 25 , user_id_high_opt, option) ,
6818
6825
( 27 , channel_keys_id, option) ,
6826
+ ( 28 , holder_max_accepted_htlcs, option) ,
6819
6827
( 29 , temporary_channel_id, option) ,
6820
6828
( 31 , channel_pending_event_emitted, option) ,
6821
6829
} ) ;
@@ -6870,6 +6878,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6870
6878
// separate u64 values.
6871
6879
let user_id = user_id_low as u128 + ( ( user_id_high_opt. unwrap_or ( 0 ) as u128 ) << 64 ) ;
6872
6880
6881
+ let holder_max_accepted_htlcs = holder_max_accepted_htlcs. unwrap_or ( DEFAULT_MAX_HTLCS ) ;
6882
+
6873
6883
Ok ( Channel {
6874
6884
user_id,
6875
6885
@@ -6898,6 +6908,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6898
6908
cur_counterparty_commitment_transaction_number,
6899
6909
value_to_self_msat,
6900
6910
6911
+ holder_max_accepted_htlcs,
6901
6912
pending_inbound_htlcs,
6902
6913
pending_outbound_htlcs,
6903
6914
holding_cell_htlc_updates,
0 commit comments