Skip to content

Commit

Permalink
Only keep track of recently used stacks in memory.
Browse files Browse the repository at this point in the history
This should - as far as we know - eliminate unbounded memory growth.
To avoid memory leaks, we only evict "root" stacks from the cache.
  • Loading branch information
vicsn committed Jan 10, 2025
1 parent be48f30 commit 44fc174
Show file tree
Hide file tree
Showing 42 changed files with 1,761 additions and 246 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions console/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ pub trait Network:

/// The maximum number of certificates in a batch.
const MAX_CERTIFICATES: u16;
/// The maximum number of transmissions per batch.
/// Note: This limit is set to 50 as part of safety measures to prevent DoS attacks.
/// This limit can be increased in the future as performance improves. Alternatively,
/// the rate of block production can be sped up to compensate for the limit set here.
const MAX_TRANSMISSIONS_PER_BATCH: u16 = 50;

/// The maximum number of stacks in the process
/// Allows for fast processing for blocks made from 4 maximally full rounds.
const MAX_STACKS: usize = Self::MAX_PROGRAM_DEPTH * Self::MAX_IMPORTS * 10;

/// The maximum number of bytes in a transaction.
// Note: This value must **not** be decreased as it would invalidate existing transactions.
Expand Down
2 changes: 1 addition & 1 deletion ledger/block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ pub mod test_helpers {
let inputs = [address.to_string(), format!("{amount}_u64")];

// Initialize the process.
let process = Process::load().unwrap();
let process = Process::load_testing_only().unwrap();
// Authorize the function.
let authorization =
process.authorize::<CurrentAleo, _>(&private_key, locator.0, locator.1, inputs.iter(), rng).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion ledger/block/src/transaction/deployment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function compute:
assert!(string.is_empty(), "Parser did not consume all of the string: '{string}'");

// Construct the process.
let process = Process::load().unwrap();
let process = Process::load_testing_only().unwrap();
// Compute the deployment.
let deployment = process.deploy::<CurrentAleo, _>(&program, rng).unwrap();
// Return the deployment.
Expand Down
4 changes: 2 additions & 2 deletions ledger/block/src/transaction/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub mod test_helpers {
let priority_fee_in_microcredits = 1_000;

// Initialize the process.
let process = Process::load().unwrap();
let process = Process::load_testing_only().unwrap();
// Authorize the fee.
let authorization = process
.authorize_fee_private::<CurrentAleo, _>(
Expand Down Expand Up @@ -298,7 +298,7 @@ pub mod test_helpers {
let priority_fee = 1_000;

// Initialize the process.
let process = Process::load().unwrap();
let process = Process::load_testing_only().unwrap();
// Authorize the fee.
let authorization = process
.authorize_fee_public::<CurrentAleo, _>(
Expand Down
5 changes: 1 addition & 4 deletions ledger/narwhal/batch-header/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ impl<N: Network> BatchHeader<N> {
/// The maximum number of rounds to store before garbage collecting.
pub const MAX_GC_ROUNDS: usize = 100;
/// The maximum number of transmissions in a batch.
/// Note: This limit is set to 50 as part of safety measures to prevent DoS attacks.
/// This limit can be increased in the future as performance improves. Alternatively,
/// the rate of block production can be sped up to compensate for the limit set here.
pub const MAX_TRANSMISSIONS_PER_BATCH: usize = 50;
pub const MAX_TRANSMISSIONS_PER_BATCH: usize = N::MAX_TRANSMISSIONS_PER_BATCH as usize;
}

impl<N: Network> BatchHeader<N> {
Expand Down
2 changes: 1 addition & 1 deletion ledger/puzzle/epoch/src/synthesis/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function synthesize:
let program = Program::from_str(&program_string)?;

// Initialize a new process.
let process = Process::<N>::load()?;
let process = Process::<N>::load_no_storage()?;
// Initialize the stack with the synthesis challenge program.
let stack = Stack::new(&process, &program)?;

Expand Down
4 changes: 2 additions & 2 deletions ledger/query/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<N: Network, B: BlockStorage<N>> QueryTrait<N> for Query<N, B> {
}
}

/// Returns a state path for the given `commitment`.
/// Returns the current block height.
fn current_block_height(&self) -> Result<u32> {
match self {
Self::VM(block_store) => Ok(block_store.max_height().unwrap_or_default()),
Expand All @@ -159,7 +159,7 @@ impl<N: Network, B: BlockStorage<N>> QueryTrait<N> for Query<N, B> {
}
}

/// Returns a state path for the given `commitment`.
/// Returns the current block height.
#[cfg(feature = "async")]
async fn current_block_height_async(&self) -> Result<u32> {
match self {
Expand Down
Loading

0 comments on commit 44fc174

Please sign in to comment.