diff --git a/crates/zksync/core/src/vm/inspect.rs b/crates/zksync/core/src/vm/inspect.rs index 23ddc8c29..b64a2e906 100644 --- a/crates/zksync/core/src/vm/inspect.rs +++ b/crates/zksync/core/src/vm/inspect.rs @@ -32,7 +32,11 @@ use zksync_types::{ }; use zksync_utils::{be_words_to_bytes, h256_to_account_address, h256_to_u256, u256_to_h256}; -use std::{collections::HashMap, fmt::Debug, sync::Arc}; +use std::{ + collections::HashMap, + fmt::Debug, + sync::{Arc, LazyLock}, +}; use crate::{ convert::{ConvertAddress, ConvertH160, ConvertH256, ConvertRU256, ConvertU256}, @@ -756,10 +760,15 @@ where .unwrap_or_default() } -/// Default maximum size allowed for factory_deps during create. +/// Maximum size allowed for factory_deps during create. /// We batch factory_deps till this upper limit if there are multiple deps. /// These batches are then deployed individually. -const DEFAULT_MAX_FACTORY_DEPENDENCIES_SIZE_BYTES: usize = 100_000; +static MAX_FACTORY_DEPENDENCIES_SIZE_BYTES: LazyLock = LazyLock::new(|| { + std::env::var("MAX_FACTORY_DEPENDENCIES_SIZE_BYTES") + .ok() + .and_then(|value| value.parse::().ok()) + .unwrap_or(100_000) +}); /// Batch factory deps on the basis of size. /// @@ -767,14 +776,10 @@ const DEFAULT_MAX_FACTORY_DEPENDENCIES_SIZE_BYTES: usize = 100_000; /// on the basis of the max factory dependencies size and deploy all but the last batch /// via empty transactions, with the last one deployed normally via create. pub fn batch_factory_dependencies(mut factory_deps: Vec>) -> Vec>> { - let max_factory_deps_size_bytes = std::env::var("MAX_FACTORY_DEPENDENCIES_SIZE_BYTES") - .ok() - .and_then(|value| value.parse::().ok()) - .unwrap_or(DEFAULT_MAX_FACTORY_DEPENDENCIES_SIZE_BYTES); let factory_deps_count = factory_deps.len(); let factory_deps_sizes = factory_deps.iter().map(|dep| dep.len()).collect_vec(); let factory_deps_total_size = factory_deps_sizes.iter().sum::(); - tracing::debug!(count=factory_deps_count, total=factory_deps_total_size, sizes=?factory_deps_sizes, max=max_factory_deps_size_bytes, "optimizing factory_deps"); + tracing::debug!(count=factory_deps_count, total=factory_deps_total_size, sizes=?factory_deps_sizes, max=*MAX_FACTORY_DEPENDENCIES_SIZE_BYTES, "optimizing factory_deps"); let mut batches = vec![]; let mut current_batch = vec![]; @@ -785,7 +790,7 @@ pub fn batch_factory_dependencies(mut factory_deps: Vec>) -> Vec max_factory_deps_size_bytes && !current_batch.is_empty() { + if new_len > *MAX_FACTORY_DEPENDENCIES_SIZE_BYTES && !current_batch.is_empty() { batches.push(current_batch); current_batch = vec![]; current_batch_len = 0;