Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Increase the inbound queue capacity (that leads into the memory pool) #3124

Merged
merged 6 commits into from Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions node/consensus/src/lib.rs
Expand Up @@ -53,10 +53,18 @@ use tokio::{
task::JoinHandle,
};

/// Percentage of mempool transactions capacity reserved for deployments.
const CAPACITY_FOR_DEPLOYMENTS: usize = 20;
/// Percentage of mempool transactions capacity reserved for executions.
const CAPACITY_FOR_EXECUTIONS: usize = 80;
/// The capacity of the queue reserved for deployments.
/// Note: This is an inbound queue capacity, not a Narwhal-enforced capacity.
const CAPACITY_FOR_DEPLOYMENTS: usize = 1 << 10;
/// The capacity of the queue reserved for executions.
/// Note: This is an inbound queue capacity, not a Narwhal-enforced capacity.
const CAPACITY_FOR_EXECUTIONS: usize = 1 << 10;
/// The capacity of the queue reserved for solutions.
/// Note: This is an inbound queue capacity, not a Narwhal-enforced capacity.
const CAPACITY_FOR_SOLUTIONS: usize = 1 << 10;
/// The **suggested** maximum number of deployments in each interval.
/// Note: This is an inbound queue limit, not a Narwhal-enforced limit.
const MAX_DEPLOYMENTS_PER_INTERVAL: usize = 1;

/// Helper struct to track incoming transactions.
struct TransactionsQueue<N: Network> {
Expand All @@ -67,14 +75,8 @@ struct TransactionsQueue<N: Network> {
impl<N: Network> Default for TransactionsQueue<N> {
fn default() -> Self {
Self {
deployments: LruCache::new(
NonZeroUsize::new(BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH * CAPACITY_FOR_DEPLOYMENTS / 100)
.unwrap(),
),
executions: LruCache::new(
NonZeroUsize::new(BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH * CAPACITY_FOR_EXECUTIONS / 100)
.unwrap(),
),
deployments: LruCache::new(NonZeroUsize::new(CAPACITY_FOR_DEPLOYMENTS).unwrap()),
executions: LruCache::new(NonZeroUsize::new(CAPACITY_FOR_EXECUTIONS).unwrap()),
}
}
}
Expand Down Expand Up @@ -124,9 +126,7 @@ impl<N: Network> Consensus<N> {
ledger,
bft,
primary_sender: Default::default(),
solutions_queue: Arc::new(Mutex::new(LruCache::new(
NonZeroUsize::new(BatchHeader::<N>::MAX_TRANSMISSIONS_PER_BATCH).unwrap(),
))),
solutions_queue: Arc::new(Mutex::new(LruCache::new(NonZeroUsize::new(CAPACITY_FOR_SOLUTIONS).unwrap()))),
transactions_queue: Default::default(),
seen_solutions: Arc::new(Mutex::new(LruCache::new(NonZeroUsize::new(1 << 16).unwrap()))),
seen_transactions: Arc::new(Mutex::new(LruCache::new(NonZeroUsize::new(1 << 16).unwrap()))),
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<N: Network> Consensus<N> {
// Acquire the lock on the transactions queue.
let mut tx_queue = self.transactions_queue.lock();
// Determine the number of deployments to send.
let num_deployments = tx_queue.deployments.len().min(capacity * CAPACITY_FOR_DEPLOYMENTS / 100);
let num_deployments = tx_queue.deployments.len().min(capacity).min(MAX_DEPLOYMENTS_PER_INTERVAL);
// Determine the number of executions to send.
let num_executions = tx_queue.executions.len().min(capacity.saturating_sub(num_deployments));
// Create an iterator which will select interleaved deployments and executions within the capacity.
Expand Down