Skip to content

Commit

Permalink
feat: disable batch factory deps by default (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec authored Jul 15, 2024
1 parent ab00f2e commit 0fc17fd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 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 @@ -44,4 +44,5 @@ zksync_state.workspace = true
ansi_term = "0.12.1"
once_cell = "1"
eyre = "0.6"
url = "2"
url = "2"
lazy_static = "1.4.0"
20 changes: 14 additions & 6 deletions crates/zksync/core/src/vm/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,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 @@ -516,7 +524,7 @@ pub fn batch_factory_dependencies(mut factory_deps: Vec<Vec<u8>>) -> Vec<Vec<Vec
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::<usize>();
tracing::debug!(count=factory_deps_count, total=factory_deps_total_size, sizes=?factory_deps_sizes, "optimizing factory_deps");
tracing::info!(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![];
Expand All @@ -527,7 +535,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();
// }
// }
5 changes: 3 additions & 2 deletions zk-tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ echo "Running script..."
RUST_LOG=warn "${FORGE}" script ./script/Deploy.s.sol:DeployScript --broadcast --private-key "$PRIVATE_KEY" --chain 260 --gas-estimate-multiplier 310 --rpc-url "$RPC_URL" --use "./${SOLC}" --slow -vvv --zk-compile || fail "forge script failed"
RUST_LOG=warn "${FORGE}" script ./script/Deploy.s.sol:DeployScript --broadcast --private-key "$PRIVATE_KEY" --chain 260 --gas-estimate-multiplier 310 --rpc-url "$RPC_URL" --use "./${SOLC}" --slow -vvv --zk-compile || fail "forge script failed on 2nd deploy"

echo "Running factory deps script..."
RUST_LOG=warn "${FORGE}" script ./src/LargeFactoryDependencies.t.sol:ZkLargeFactoryDependenciesScript --broadcast --private-key "$PRIVATE_KEY" --chain 260 --gas-estimate-multiplier 310 --rpc-url "$RPC_URL" --use "./${SOLC}" --slow -vvv --zk-startup || fail "forge script failed"
# Temporarily disabled
# echo "Running factory deps script..."
# RUST_LOG=warn "${FORGE}" script ./src/LargeFactoryDependencies.t.sol:ZkLargeFactoryDependenciesScript --broadcast --private-key "$PRIVATE_KEY" --chain 260 --gas-estimate-multiplier 310 --rpc-url "$RPC_URL" --use "./${SOLC}" --slow -vvv --zk-startup || fail "forge script failed"

echo "Running NFT script"
RUST_LOG=warn "${FORGE}" script ./script/NFT.s.sol:MyScript --broadcast --private-key $PRIVATE_KEY --rpc-url $RPC_URL --use 0.8.20 --zk-startup || fail "forge script failed"
Expand Down

0 comments on commit 0fc17fd

Please sign in to comment.