Skip to content

Commit 244a460

Browse files
authored
Bound min size of dynamic processor queues (#6466)
* Bound min size of dynamic processor queues * Use max * Add test
1 parent 352a9cf commit 244a460

File tree

1 file changed

+31
-2
lines changed
  • beacon_node/beacon_processor/src

1 file changed

+31
-2
lines changed

beacon_node/beacon_processor/src/lib.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ const DEFAULT_MAX_SCHEDULED_WORK_QUEUE_LEN: usize = 3 * DEFAULT_MAX_WORK_EVENT_Q
9393
/// slightly, we don't need to adjust the queues during the lifetime of a process.
9494
const ACTIVE_VALIDATOR_COUNT_OVERPROVISION_PERCENT: usize = 110;
9595

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+
96101
/// Maximum number of queued items that will be stored before dropping them
97102
pub struct BeaconProcessorQueueLengths {
98103
aggregate_queue: usize,
@@ -155,9 +160,15 @@ impl BeaconProcessorQueueLengths {
155160
aggregate_queue: 4096,
156161
unknown_block_aggregate_queue: 1024,
157162
// 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+
),
159167
// 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+
),
161172
sync_message_queue: 2048,
162173
sync_contribution_queue: 1024,
163174
gossip_voluntary_exit_queue: 4096,
@@ -1686,3 +1697,21 @@ impl Drop for SendOnDrop {
16861697
}
16871698
}
16881699
}
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

Comments
 (0)