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 4 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
28 changes: 12 additions & 16 deletions node/consensus/src/lib.rs
Expand Up @@ -53,10 +53,14 @@ 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 mempool reserved for deployments.
const CAPACITY_FOR_DEPLOYMENTS: usize = 1 << 5;
/// The capacity of the mempool reserved for executions.
const CAPACITY_FOR_EXECUTIONS: usize = 1 << 10;
/// The capacity of the mempool reserved for solutions.
const CAPACITY_FOR_SOLUTIONS: usize = 1 << 10;
/// The percentage of the transmissions being processed that are deployments.
const DEPLOYMENT_VERIFICATION_RATE: usize = 15;

/// Helper struct to track incoming transactions.
struct TransactionsQueue<N: Network> {
Expand All @@ -67,14 +71,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 +122,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 +301,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 * DEPLOYMENT_VERIFICATION_RATE / 100);
// 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