Skip to content

Commit

Permalink
disable factory-dep batching by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Jul 15, 2024
1 parent 238f330 commit 7885d53
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/zksync/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ zksync_state.workspace = true
ansi_term = "0.12.1"
once_cell = "1"
eyre = "0.6"
url = "2"
url = "2"
lazy_static = "1.5.0"
18 changes: 13 additions & 5 deletions crates/zksync/core/src/vm/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,18 @@ where
.unwrap_or_default()
}

/// 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
pub const MAX_FACTORY_DEPENDENCIES_SIZE_BYTES: usize = 100000; // 100kB
lazy_static::lazy_static! {
/// 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.
///
/// TODO: This feature is disabled by default via `usize::MAX` due to inconsistencies
/// with determining a value that works in all cases.
static ref MAX_FACTORY_DEPENDENCIES_SIZE_BYTES: usize = std::env::var("MAX_FACTORY_DEPENDENCIES_SIZE_BYTES")
.ok()
.and_then(|value| value.parse::<usize>().ok())
.unwrap_or(usize::MAX);
}

/// Batch factory deps on the basis of size.
///
Expand All @@ -523,7 +531,7 @@ pub fn batch_factory_dependencies(mut factory_deps: Vec<Vec<u8>>) -> Vec<Vec<Vec
for dep in factory_deps {
let len = dep.len();
let new_len = current_batch_len + len;
if new_len > MAX_FACTORY_DEPENDENCIES_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;
Expand Down
24 changes: 13 additions & 11 deletions zk-tests/src/LargeFactoryDependencies.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import "forge-std/Test.sol";
import "forge-std/Script.sol";
import {LargeContract} from "./LargeContracts.sol";

contract ZkLargeFactoryDependenciesTest is Test {
function testLargeFactoryDependenciesAreDeployedInBatches() public {
new LargeContract();
}
}
// Temporarily disabled due to issues with batching

contract ZkLargeFactoryDependenciesScript is Script {
function run() external {
vm.broadcast();
new LargeContract();
}
}
// contract ZkLargeFactoryDependenciesTest is Test {
// function testLargeFactoryDependenciesAreDeployedInBatches() public {
// new LargeContract();
// }
// }

// contract ZkLargeFactoryDependenciesScript is Script {
// function run() external {
// vm.broadcast();
// new LargeContract();
// }
// }

0 comments on commit 7885d53

Please sign in to comment.