@@ -529,6 +529,7 @@ 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 ,
532
533
pending_inbound_htlcs : Vec < InboundHTLCOutput > ,
533
534
pending_outbound_htlcs : Vec < OutboundHTLCOutput > ,
534
535
holding_cell_htlc_updates : Vec < HTLCUpdateAwaitingACK > ,
@@ -652,7 +653,6 @@ pub(super) struct Channel<Signer: ChannelSigner> {
652
653
pub counterparty_max_accepted_htlcs : u16 ,
653
654
#[ cfg( not( test) ) ]
654
655
counterparty_max_accepted_htlcs : u16 ,
655
- //implied by OUR_MAX_HTLCS: max_accepted_htlcs: u16,
656
656
minimum_depth : Option < u32 > ,
657
657
658
658
counterparty_forwarding_info : Option < CounterpartyForwardingInfo > ,
@@ -752,7 +752,6 @@ struct CommitmentTxInfoCached {
752
752
feerate : u32 ,
753
753
}
754
754
755
- pub const OUR_MAX_HTLCS : u16 = 50 ; //TODO
756
755
757
756
pub ( crate ) fn commitment_tx_base_weight ( opt_anchors : bool ) -> u64 {
758
757
const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
@@ -1020,6 +1019,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1020
1019
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1021
1020
value_to_self_msat,
1022
1021
1022
+ max_accepted_htlcs : 50 ,
1023
1023
pending_inbound_htlcs : Vec :: new ( ) ,
1024
1024
pending_outbound_htlcs : Vec :: new ( ) ,
1025
1025
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -1364,6 +1364,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1364
1364
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1365
1365
value_to_self_msat : msg. push_msat ,
1366
1366
1367
+ max_accepted_htlcs : msg. max_accepted_htlcs ,
1367
1368
pending_inbound_htlcs : Vec :: new ( ) ,
1368
1369
pending_outbound_htlcs : Vec :: new ( ) ,
1369
1370
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -2862,8 +2863,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2862
2863
2863
2864
let inbound_stats = self . get_inbound_pending_htlc_stats ( None ) ;
2864
2865
let outbound_stats = self . get_outbound_pending_htlc_stats ( None ) ;
2865
- if inbound_stats. pending_htlcs + 1 > OUR_MAX_HTLCS as u32 {
2866
- return Err ( ChannelError :: Close ( format ! ( "Remote tried to push more than our max accepted HTLCs ({})" , OUR_MAX_HTLCS ) ) ) ;
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
2868
}
2868
2869
if inbound_stats. pending_htlcs_value_msat + msg. amount_msat > self . holder_max_htlc_value_in_flight_msat {
2869
2870
return Err ( ChannelError :: Close ( format ! ( "Remote HTLC add would put them over our max HTLC value ({})" , self . holder_max_htlc_value_in_flight_msat) ) ) ;
@@ -5253,7 +5254,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5253
5254
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5254
5255
feerate_per_kw : self . feerate_per_kw as u32 ,
5255
5256
to_self_delay : self . get_holder_selected_contest_delay ( ) ,
5256
- max_accepted_htlcs : OUR_MAX_HTLCS ,
5257
+ max_accepted_htlcs : self . max_accepted_htlcs ,
5257
5258
funding_pubkey : keys. funding_pubkey ,
5258
5259
revocation_basepoint : keys. revocation_basepoint ,
5259
5260
payment_point : keys. payment_point ,
@@ -5320,7 +5321,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5320
5321
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5321
5322
minimum_depth : self . minimum_depth . unwrap ( ) ,
5322
5323
to_self_delay : self . get_holder_selected_contest_delay ( ) ,
5323
- max_accepted_htlcs : OUR_MAX_HTLCS ,
5324
+ max_accepted_htlcs : self . max_accepted_htlcs ,
5324
5325
funding_pubkey : keys. funding_pubkey ,
5325
5326
revocation_basepoint : keys. revocation_basepoint ,
5326
5327
payment_point : keys. payment_point ,
@@ -6207,6 +6208,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6207
6208
self . cur_counterparty_commitment_transaction_number . write ( writer) ?;
6208
6209
self . value_to_self_msat . write ( writer) ?;
6209
6210
6211
+ self . max_accepted_htlcs . write ( writer) ?;
6210
6212
let mut dropped_inbound_htlcs = 0 ;
6211
6213
for htlc in self . pending_inbound_htlcs . iter ( ) {
6212
6214
if let InboundHTLCState :: RemoteAnnounced ( _) = htlc. state {
@@ -6452,6 +6454,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6452
6454
( 23 , channel_ready_event_emitted, option) ,
6453
6455
( 25 , user_id_high_opt, option) ,
6454
6456
( 27 , self . channel_keys_id, required) ,
6457
+ ( 28 , Some ( self . max_accepted_htlcs) , option) ,
6455
6458
} ) ;
6456
6459
6457
6460
Ok ( ( ) )
@@ -6517,8 +6520,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6517
6520
let cur_counterparty_commitment_transaction_number = Readable :: read ( reader) ?;
6518
6521
let value_to_self_msat = Readable :: read ( reader) ?;
6519
6522
6523
+ let max_accepted_htlcs = Readable :: read ( reader) ?;
6520
6524
let pending_inbound_htlc_count: u64 = Readable :: read ( reader) ?;
6521
- let mut pending_inbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_inbound_htlc_count as usize , OUR_MAX_HTLCS as usize ) ) ;
6525
+
6526
+ let mut pending_inbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_inbound_htlc_count as usize , max_accepted_htlcs as usize ) ) ;
6522
6527
for _ in 0 ..pending_inbound_htlc_count {
6523
6528
pending_inbound_htlcs. push ( InboundHTLCOutput {
6524
6529
htlc_id : Readable :: read ( reader) ?,
@@ -6536,7 +6541,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6536
6541
}
6537
6542
6538
6543
let pending_outbound_htlc_count: u64 = Readable :: read ( reader) ?;
6539
- let mut pending_outbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_outbound_htlc_count as usize , OUR_MAX_HTLCS as usize ) ) ;
6544
+ let mut pending_outbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_outbound_htlc_count as usize , max_accepted_htlcs as usize ) ) ;
6540
6545
for _ in 0 ..pending_outbound_htlc_count {
6541
6546
pending_outbound_htlcs. push ( OutboundHTLCOutput {
6542
6547
htlc_id : Readable :: read ( reader) ?,
@@ -6565,7 +6570,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6565
6570
}
6566
6571
6567
6572
let holding_cell_htlc_update_count: u64 = Readable :: read ( reader) ?;
6568
- let mut holding_cell_htlc_updates = Vec :: with_capacity ( cmp:: min ( holding_cell_htlc_update_count as usize , OUR_MAX_HTLCS as usize * 2 ) ) ;
6573
+ let mut holding_cell_htlc_updates = Vec :: with_capacity ( cmp:: min ( holding_cell_htlc_update_count as usize , max_accepted_htlcs as usize * 2 ) ) ;
6569
6574
for _ in 0 ..holding_cell_htlc_update_count {
6570
6575
holding_cell_htlc_updates. push ( match <u8 as Readable >:: read ( reader) ? {
6571
6576
0 => HTLCUpdateAwaitingACK :: AddHTLC {
@@ -6598,13 +6603,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6598
6603
let monitor_pending_commitment_signed = Readable :: read ( reader) ?;
6599
6604
6600
6605
let monitor_pending_forwards_count: u64 = Readable :: read ( reader) ?;
6601
- let mut monitor_pending_forwards = Vec :: with_capacity ( cmp:: min ( monitor_pending_forwards_count as usize , OUR_MAX_HTLCS as usize ) ) ;
6606
+ let mut monitor_pending_forwards = Vec :: with_capacity ( cmp:: min ( monitor_pending_forwards_count as usize , max_accepted_htlcs as usize ) ) ;
6602
6607
for _ in 0 ..monitor_pending_forwards_count {
6603
6608
monitor_pending_forwards. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6604
6609
}
6605
6610
6606
6611
let monitor_pending_failures_count: u64 = Readable :: read ( reader) ?;
6607
- let mut monitor_pending_failures = Vec :: with_capacity ( cmp:: min ( monitor_pending_failures_count as usize , OUR_MAX_HTLCS as usize ) ) ;
6612
+ let mut monitor_pending_failures = Vec :: with_capacity ( cmp:: min ( monitor_pending_failures_count as usize , max_accepted_htlcs as usize ) ) ;
6608
6613
for _ in 0 ..monitor_pending_failures_count {
6609
6614
monitor_pending_failures. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6610
6615
}
@@ -6822,6 +6827,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6822
6827
cur_counterparty_commitment_transaction_number,
6823
6828
value_to_self_msat,
6824
6829
6830
+ max_accepted_htlcs,
6825
6831
pending_inbound_htlcs,
6826
6832
pending_outbound_htlcs,
6827
6833
holding_cell_htlc_updates,
0 commit comments