@@ -530,6 +530,7 @@ 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 ,
533
534
pending_inbound_htlcs : Vec < InboundHTLCOutput > ,
534
535
pending_outbound_htlcs : Vec < OutboundHTLCOutput > ,
535
536
holding_cell_htlc_updates : Vec < HTLCUpdateAwaitingACK > ,
@@ -653,7 +654,6 @@ pub(super) struct Channel<Signer: ChannelSigner> {
653
654
pub counterparty_max_accepted_htlcs : u16 ,
654
655
#[ cfg( not( test) ) ]
655
656
counterparty_max_accepted_htlcs : u16 ,
656
- //implied by OUR_MAX_HTLCS: max_accepted_htlcs: u16,
657
657
minimum_depth : Option < u32 > ,
658
658
659
659
counterparty_forwarding_info : Option < CounterpartyForwardingInfo > ,
@@ -756,7 +756,6 @@ struct CommitmentTxInfoCached {
756
756
feerate : u32 ,
757
757
}
758
758
759
- pub const OUR_MAX_HTLCS : u16 = 50 ; //TODO
760
759
761
760
pub ( crate ) fn commitment_tx_base_weight ( opt_anchors : bool ) -> u64 {
762
761
const COMMITMENT_TX_BASE_WEIGHT : u64 = 724 ;
@@ -1027,6 +1026,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1027
1026
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1028
1027
value_to_self_msat,
1029
1028
1029
+ max_accepted_htlcs : 50 ,
1030
1030
pending_inbound_htlcs : Vec :: new ( ) ,
1031
1031
pending_outbound_htlcs : Vec :: new ( ) ,
1032
1032
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -1373,6 +1373,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
1373
1373
cur_counterparty_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
1374
1374
value_to_self_msat : msg. push_msat ,
1375
1375
1376
+ max_accepted_htlcs : msg. max_accepted_htlcs ,
1376
1377
pending_inbound_htlcs : Vec :: new ( ) ,
1377
1378
pending_outbound_htlcs : Vec :: new ( ) ,
1378
1379
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -2874,8 +2875,8 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
2874
2875
2875
2876
let inbound_stats = self . get_inbound_pending_htlc_stats ( None ) ;
2876
2877
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 ) ) ) ;
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
2880
}
2880
2881
if inbound_stats. pending_htlcs_value_msat + msg. amount_msat > self . holder_max_htlc_value_in_flight_msat {
2881
2882
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 +5314,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5313
5314
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5314
5315
feerate_per_kw : self . feerate_per_kw as u32 ,
5315
5316
to_self_delay : self . get_holder_selected_contest_delay ( ) ,
5316
- max_accepted_htlcs : OUR_MAX_HTLCS ,
5317
+ max_accepted_htlcs : self . max_accepted_htlcs ,
5317
5318
funding_pubkey : keys. funding_pubkey ,
5318
5319
revocation_basepoint : keys. revocation_basepoint ,
5319
5320
payment_point : keys. payment_point ,
@@ -5380,7 +5381,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
5380
5381
htlc_minimum_msat : self . holder_htlc_minimum_msat ,
5381
5382
minimum_depth : self . minimum_depth . unwrap ( ) ,
5382
5383
to_self_delay : self . get_holder_selected_contest_delay ( ) ,
5383
- max_accepted_htlcs : OUR_MAX_HTLCS ,
5384
+ max_accepted_htlcs : self . max_accepted_htlcs ,
5384
5385
funding_pubkey : keys. funding_pubkey ,
5385
5386
revocation_basepoint : keys. revocation_basepoint ,
5386
5387
payment_point : keys. payment_point ,
@@ -6275,6 +6276,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6275
6276
self . cur_counterparty_commitment_transaction_number . write ( writer) ?;
6276
6277
self . value_to_self_msat . write ( writer) ?;
6277
6278
6279
+ self . max_accepted_htlcs . write ( writer) ?;
6278
6280
let mut dropped_inbound_htlcs = 0 ;
6279
6281
for htlc in self . pending_inbound_htlcs . iter ( ) {
6280
6282
if let InboundHTLCState :: RemoteAnnounced ( _) = htlc. state {
@@ -6521,6 +6523,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
6521
6523
( 23 , channel_ready_event_emitted, option) ,
6522
6524
( 25 , user_id_high_opt, option) ,
6523
6525
( 27 , self . channel_keys_id, required) ,
6526
+ ( 28 , Some ( self . max_accepted_htlcs) , option) ,
6524
6527
( 29 , self . temporary_channel_id, option) ,
6525
6528
( 31 , channel_pending_event_emitted, option) ,
6526
6529
} ) ;
@@ -6588,8 +6591,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6588
6591
let cur_counterparty_commitment_transaction_number = Readable :: read ( reader) ?;
6589
6592
let value_to_self_msat = Readable :: read ( reader) ?;
6590
6593
6594
+ let max_accepted_htlcs = Readable :: read ( reader) ?;
6591
6595
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 ) ) ;
6596
+
6597
+ let mut pending_inbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_inbound_htlc_count as usize , max_accepted_htlcs as usize ) ) ;
6593
6598
for _ in 0 ..pending_inbound_htlc_count {
6594
6599
pending_inbound_htlcs. push ( InboundHTLCOutput {
6595
6600
htlc_id : Readable :: read ( reader) ?,
@@ -6607,7 +6612,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6607
6612
}
6608
6613
6609
6614
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 ) ) ;
6615
+ let mut pending_outbound_htlcs = Vec :: with_capacity ( cmp:: min ( pending_outbound_htlc_count as usize , max_accepted_htlcs as usize ) ) ;
6611
6616
for _ in 0 ..pending_outbound_htlc_count {
6612
6617
pending_outbound_htlcs. push ( OutboundHTLCOutput {
6613
6618
htlc_id : Readable :: read ( reader) ?,
@@ -6636,7 +6641,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6636
6641
}
6637
6642
6638
6643
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 ) ) ;
6644
+ let mut holding_cell_htlc_updates = Vec :: with_capacity ( cmp:: min ( holding_cell_htlc_update_count as usize , max_accepted_htlcs as usize * 2 ) ) ;
6640
6645
for _ in 0 ..holding_cell_htlc_update_count {
6641
6646
holding_cell_htlc_updates. push ( match <u8 as Readable >:: read ( reader) ? {
6642
6647
0 => HTLCUpdateAwaitingACK :: AddHTLC {
@@ -6669,13 +6674,13 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6669
6674
let monitor_pending_commitment_signed = Readable :: read ( reader) ?;
6670
6675
6671
6676
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 ) ) ;
6677
+ let mut monitor_pending_forwards = Vec :: with_capacity ( cmp:: min ( monitor_pending_forwards_count as usize , max_accepted_htlcs as usize ) ) ;
6673
6678
for _ in 0 ..monitor_pending_forwards_count {
6674
6679
monitor_pending_forwards. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6675
6680
}
6676
6681
6677
6682
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 ) ) ;
6683
+ let mut monitor_pending_failures = Vec :: with_capacity ( cmp:: min ( monitor_pending_failures_count as usize , max_accepted_htlcs as usize ) ) ;
6679
6684
for _ in 0 ..monitor_pending_failures_count {
6680
6685
monitor_pending_failures. push ( ( Readable :: read ( reader) ?, Readable :: read ( reader) ?, Readable :: read ( reader) ?) ) ;
6681
6686
}
@@ -6898,6 +6903,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
6898
6903
cur_counterparty_commitment_transaction_number,
6899
6904
value_to_self_msat,
6900
6905
6906
+ max_accepted_htlcs,
6901
6907
pending_inbound_htlcs,
6902
6908
pending_outbound_htlcs,
6903
6909
holding_cell_htlc_updates,
0 commit comments