Skip to content

Commit

Permalink
Merge pull request #3124 from AleoHQ/increase-cache-size
Browse files Browse the repository at this point in the history
Increase the inbound queue capacity (that leads into the memory pool)
  • Loading branch information
howardwu committed Mar 12, 2024
2 parents 2a2c57f + 12cca35 commit f8d3c90
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions node/consensus/src/lib.rs
Original file line number Diff line number Diff line change
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 @@ -315,7 +315,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

0 comments on commit f8d3c90

Please sign in to comment.