@@ -93,6 +93,11 @@ const DEFAULT_MAX_SCHEDULED_WORK_QUEUE_LEN: usize = 3 * DEFAULT_MAX_WORK_EVENT_Q
93
93
/// slightly, we don't need to adjust the queues during the lifetime of a process.
94
94
const ACTIVE_VALIDATOR_COUNT_OVERPROVISION_PERCENT : usize = 110 ;
95
95
96
+ /// Minimum size of dynamically sized queues. Due to integer division we don't want 0 length queues
97
+ /// as the processor won't process that message type. 128 is an arbitrary value value >= 1 that
98
+ /// seems reasonable.
99
+ const MIN_QUEUE_LEN : usize = 128 ;
100
+
96
101
/// Maximum number of queued items that will be stored before dropping them
97
102
pub struct BeaconProcessorQueueLengths {
98
103
aggregate_queue : usize ,
@@ -155,9 +160,15 @@ impl BeaconProcessorQueueLengths {
155
160
aggregate_queue : 4096 ,
156
161
unknown_block_aggregate_queue : 1024 ,
157
162
// Capacity for a full slot's worth of attestations if subscribed to all subnets
158
- attestation_queue : active_validator_count / slots_per_epoch,
163
+ attestation_queue : std:: cmp:: max (
164
+ active_validator_count / slots_per_epoch,
165
+ MIN_QUEUE_LEN ,
166
+ ) ,
159
167
// Capacity for a full slot's worth of attestations if subscribed to all subnets
160
- unknown_block_attestation_queue : active_validator_count / slots_per_epoch,
168
+ unknown_block_attestation_queue : std:: cmp:: max (
169
+ active_validator_count / slots_per_epoch,
170
+ MIN_QUEUE_LEN ,
171
+ ) ,
161
172
sync_message_queue : 2048 ,
162
173
sync_contribution_queue : 1024 ,
163
174
gossip_voluntary_exit_queue : 4096 ,
@@ -1686,3 +1697,21 @@ impl Drop for SendOnDrop {
1686
1697
}
1687
1698
}
1688
1699
}
1700
+
1701
+ #[ cfg( test) ]
1702
+ mod tests {
1703
+ use super :: * ;
1704
+ use types:: { BeaconState , ChainSpec , Eth1Data , ForkName , MainnetEthSpec } ;
1705
+
1706
+ #[ test]
1707
+ fn min_queue_len ( ) {
1708
+ // State with no validators.
1709
+ let spec = ForkName :: latest ( ) . make_genesis_spec ( ChainSpec :: mainnet ( ) ) ;
1710
+ let genesis_time = 0 ;
1711
+ let state = BeaconState :: < MainnetEthSpec > :: new ( genesis_time, Eth1Data :: default ( ) , & spec) ;
1712
+ assert_eq ! ( state. validators( ) . len( ) , 0 ) ;
1713
+ let queue_lengths = BeaconProcessorQueueLengths :: from_state ( & state, & spec) . unwrap ( ) ;
1714
+ assert_eq ! ( queue_lengths. attestation_queue, MIN_QUEUE_LEN ) ;
1715
+ assert_eq ! ( queue_lengths. unknown_block_attestation_queue, MIN_QUEUE_LEN ) ;
1716
+ }
1717
+ }
0 commit comments