Skip to content

Commit 44fc174

Browse files
committed
Only keep track of recently used stacks in memory.
This should - as far as we know - eliminate unbounded memory growth. To avoid memory leaks, we only evict "root" stacks from the cache.
1 parent be48f30 commit 44fc174

File tree

42 files changed

+1761
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1761
-246
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console/network/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ pub trait Network:
194194

195195
/// The maximum number of certificates in a batch.
196196
const MAX_CERTIFICATES: u16;
197+
/// The maximum number of transmissions per batch.
198+
/// Note: This limit is set to 50 as part of safety measures to prevent DoS attacks.
199+
/// This limit can be increased in the future as performance improves. Alternatively,
200+
/// the rate of block production can be sped up to compensate for the limit set here.
201+
const MAX_TRANSMISSIONS_PER_BATCH: u16 = 50;
202+
203+
/// The maximum number of stacks in the process
204+
/// Allows for fast processing for blocks made from 4 maximally full rounds.
205+
const MAX_STACKS: usize = Self::MAX_PROGRAM_DEPTH * Self::MAX_IMPORTS * 10;
197206

198207
/// The maximum number of bytes in a transaction.
199208
// Note: This value must **not** be decreased as it would invalidate existing transactions.

ledger/block/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ pub mod test_helpers {
656656
let inputs = [address.to_string(), format!("{amount}_u64")];
657657

658658
// Initialize the process.
659-
let process = Process::load().unwrap();
659+
let process = Process::load_testing_only().unwrap();
660660
// Authorize the function.
661661
let authorization =
662662
process.authorize::<CurrentAleo, _>(&private_key, locator.0, locator.1, inputs.iter(), rng).unwrap();

ledger/block/src/transaction/deployment/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function compute:
198198
assert!(string.is_empty(), "Parser did not consume all of the string: '{string}'");
199199

200200
// Construct the process.
201-
let process = Process::load().unwrap();
201+
let process = Process::load_testing_only().unwrap();
202202
// Compute the deployment.
203203
let deployment = process.deploy::<CurrentAleo, _>(&program, rng).unwrap();
204204
// Return the deployment.

ledger/block/src/transaction/fee/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub mod test_helpers {
241241
let priority_fee_in_microcredits = 1_000;
242242

243243
// Initialize the process.
244-
let process = Process::load().unwrap();
244+
let process = Process::load_testing_only().unwrap();
245245
// Authorize the fee.
246246
let authorization = process
247247
.authorize_fee_private::<CurrentAleo, _>(
@@ -298,7 +298,7 @@ pub mod test_helpers {
298298
let priority_fee = 1_000;
299299

300300
// Initialize the process.
301-
let process = Process::load().unwrap();
301+
let process = Process::load_testing_only().unwrap();
302302
// Authorize the fee.
303303
let authorization = process
304304
.authorize_fee_public::<CurrentAleo, _>(

ledger/narwhal/batch-header/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ impl<N: Network> BatchHeader<N> {
6666
/// The maximum number of rounds to store before garbage collecting.
6767
pub const MAX_GC_ROUNDS: usize = 100;
6868
/// The maximum number of transmissions in a batch.
69-
/// Note: This limit is set to 50 as part of safety measures to prevent DoS attacks.
70-
/// This limit can be increased in the future as performance improves. Alternatively,
71-
/// the rate of block production can be sped up to compensate for the limit set here.
72-
pub const MAX_TRANSMISSIONS_PER_BATCH: usize = 50;
69+
pub const MAX_TRANSMISSIONS_PER_BATCH: usize = N::MAX_TRANSMISSIONS_PER_BATCH as usize;
7370
}
7471

7572
impl<N: Network> BatchHeader<N> {

ledger/puzzle/epoch/src/synthesis/program/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function synthesize:
104104
let program = Program::from_str(&program_string)?;
105105

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

ledger/query/src/query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<N: Network, B: BlockStorage<N>> QueryTrait<N> for Query<N, B> {
140140
}
141141
}
142142

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

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

0 commit comments

Comments
 (0)