From 123ad0a1670b063459196d5cac09182f81b90a19 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 28 Jan 2025 17:10:08 +0400 Subject: [PATCH 01/10] (feat): image works --- .dockerignore | 8 +- docker/local-node/Dockerfile | 50 +++- docker/local-node/entrypoint.sh | 392 ++++++++++++++++---------------- 3 files changed, 251 insertions(+), 199 deletions(-) diff --git a/.dockerignore b/.dockerignore index 528c0ed9793a..523279722d29 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ * !docker/prover/prover-entry.sh !docker/local-node/entrypoint.sh +!docker/local-node/zkstack !docker/external-node/entrypoint.sh !docker/contract-verifier/install-all-solc.sh !etc/test_config @@ -25,7 +26,6 @@ keys/setup !contracts/ !setup_2\^26.key !setup_2\^24.key -!setup_compact.key # It's required to remove .git from contracts, # otherwise yarn tries to use .git parent directory that # doesn't exist. @@ -42,9 +42,15 @@ contracts/.git !bellman-cuda !prover/data/ !.github/release-please/manifest.json +!zkstack_cli +!chains +!usr/local/bin +!usr/local/bin/zkstack !etc/env/file_based !etc/env/dev.toml !etc/env/consensus_secrets.yaml !etc/env/consensus_config.yaml !rust-toolchain +!ZkStack.yaml +!docker-compose.yml \ No newline at end of file diff --git a/docker/local-node/Dockerfile b/docker/local-node/Dockerfile index fce2cd9a8218..ff6d28c27fe6 100644 --- a/docker/local-node/Dockerfile +++ b/docker/local-node/Dockerfile @@ -28,8 +28,7 @@ RUN cargo install sqlx-cli --version 0.8.0 # Copy required packages while preserving the folders structure from the repo # It's required because these packages use relative paths to the SDK -# Copy `zk` tool -COPY infrastructure/zk /infrastructure/zk + # Copy `local-setup-preparation` tool COPY infrastructure/local-setup-preparation /infrastructure/local-setup-preparation # Copy dev configs @@ -38,29 +37,34 @@ COPY etc/env /etc/env COPY etc/test_config /etc/test_config # Copy all the L1 contracts so they can be deployed COPY contracts /contracts/ - +COPY core/ /core # Set `ZKSYNC_HOME` to the root (required for `zk` tool) ENV ZKSYNC_HOME=/ # Set `LOCAL_SETUP` variable to modify `zk` tool behavior ENV ZKSYNC_LOCAL_SETUP=true # Disable all checks ENV ZKSYNC_ACTION=dont_ask - +# Env in Docker +ENV IN_DOCKER=1 # Build all the required TS packages -# Build `zk` tool -RUN cd /infrastructure/zk && yarn && yarn build && cd / # Build `local-setup-preparation` tool RUN cd /infrastructure/local-setup-preparation && yarn && cd / # Build L1 contracts package (contracts themselves should be already built) RUN cd /contracts/l1-contracts && yarn && cd / # Same for L2 contracts RUN cd /contracts/l2-contracts && yarn && cd / +# Same for L1-da contracts +RUN cd /contracts/da-contracts && yarn && cd / -# Copy the ZK tool binary -COPY bin/zk /bin/zk +# Copy the ZK stack tool Library +COPY zkstack_cli /zkstack_cli +# Copy the configs for chain +COPY chains/era /chains/era # Copy package json (which gives us yarn workspace - and makes commands more similar to what we normally run) COPY package.json / +# Copy rust toolchain (so the compilation can be done with correct nightly) +COPY rust-toolchain / # Copy DAL - needed to setup database schemas. COPY core/lib/dal core/lib/dal @@ -71,4 +75,34 @@ RUN mkdir /etc/env/l1-inits && mkdir /etc/env/l2-inits # setup entrypoint script COPY ./docker/local-node/entrypoint.sh /usr/bin/ +COPY ./docker-compose.yml /docker-compose.yml +COPY ./ZkStack.yaml /ZkStack.yaml + +# Install Docker +RUN apt-get update && apt-get install -y docker.io + +# Configure Docker repository +# RUN apt-get update && \ +# apt-get install -y ca-certificates curl gnupg && \ +# mkdir -m 0755 /etc/apt/keyrings && \ +# curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \ +# echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \ +# apt-get update && \ +# apt-get install -y docker-compose-plugin && \ +# \ +# # Install Foundry for zkSync +# curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash + +# Persist environment variables +# ENV PATH=$HOME/.foundry/bin:$PATH +# ENV LIBCLANG_PATH=/usr/lib/llvm-14/lib +ENV COMPOSE_PROJECT_NAME=my_project_name +ENV GITHUB_WORKSPACE=my_github_workspace + +# CMD ["/bin/bash"] + ENTRYPOINT ["entrypoint.sh"] + + + +# Root hash mismatched: From config: 0xd8c9be7efb705e7dcf529c14fce7048ea99dea9eab6a6b4e5f8de1ebf4f2ebf2, Calculated 0xb6779307f23867c798513845edb67ce0eca31a433e3c86f46a6961d0567a067d \ No newline at end of file diff --git a/docker/local-node/entrypoint.sh b/docker/local-node/entrypoint.sh index e57d849802ec..15e340b6bce9 100755 --- a/docker/local-node/entrypoint.sh +++ b/docker/local-node/entrypoint.sh @@ -1,194 +1,206 @@ #!/bin/bash set -ea - -# These 3 env variables must be provided. -if [ -z "$DATABASE_URL" ]; then - echo "ERROR: DATABASE_URL is not set." - exit 1 -fi - -if [ -z "$DATABASE_PROVER_URL" ]; then - echo "ERROR: DATABASE_PROVER_URL is not set." - exit 1 -fi - -if [ -z "$ETH_CLIENT_WEB3_URL" ]; then - echo "ERROR: ETH_CLIENT_WEB3_URL is not set." - exit 1 -fi - -# Updates the value in the .toml config or .env file. -update_config() { - # Assigning arguments to readable variable names - local file="$1" - local parameter="$2" - local new_value="$3" - local pattern_toml="^${parameter} =.*$" - local pattern_env="^${parameter}=.*$" - - # Check if the parameter exists in the file - if grep -q "$pattern_toml" "$file"; then - # The parameter exists in the .toml file, so replace its value - sed -i "s!$pattern_toml!${parameter} = \"$new_value\"!" "$file" - echo "Update successful for $parameter in $file." - elif grep -q "$pattern_env" "$file"; then - # The parameter exists in the .env file, so replace its value - sed -i "s!$pattern_env!${parameter}=$new_value!" "$file" - echo "Update successful for $parameter in $file." - else - # The parameter does not exist in the file, output error message and return non-zero status - echo "Error: '$parameter' not found in $file." - return 1 # Return with an error status - fi -} - -# Reads the value of the parameter from the .toml config or .env file. -read_value_from_config() { - local file="$1" - local parameter="$2" - local pattern_toml="^${parameter} =.*$" - local pattern_env="^${parameter}=.*$" - local res="" - - # Check if the parameter exists in the file - if grep -q "$pattern_toml" "$file"; then - # The parameter exists in the .toml file, so extract its value - res=$(grep "$pattern_toml" "$file" | sed "s/${parameter} = //; s/\"//g") - elif grep -q "$pattern_env" "$file"; then - # The parameter exists in the .env file, so extract its value - res=$(grep "$pattern_env" "$file" | sed "s/${parameter}=//; s/\"//g") - else - # The parameter does not exist in the file, output error message and return non-zero status - echo "Error: '$parameter' not found in $file." - return 1 # Return with an error status - fi - - if [ -z "$res" ]; then - echo "ERROR: $parameter is not set in $file." - exit 1 - fi - - echo $res -} - -# wait till db service is ready -until psql ${DATABASE_URL%/*} -c '\q'; do - echo >&2 "Postgres is unavailable - sleeping" - sleep 5 -done - -if [ -z "$MASTER_URL" ]; then - echo "Running as zksync master" -else - # If running in slave mode - wait for the master to be up and running. - echo "Waiting for zksync master to init hyperchain" - until curl --fail ${MASTER_HEALTH_URL}; do - echo >&2 "Master zksync not ready yet, sleeping" - sleep 5 - done -fi - -if [ -n "$LEGACY_BRIDGE_TESTING" ]; then - if [ -z "$MASTER_URL" ]; then - echo "Running in legacy bridge testing mode" - else - # LEGACY_BRIDGE_TESTING flag is for the master only - unset LEGACY_BRIDGE_TESTING - fi -fi - -# Normally, the /etc/env and /var/lib/zksync/data should be mapped to volumes -# so that they are persisted between docker restarts - which would allow even faster starts. - -# We use the existance of this init file to decide whether to restart or not. -INIT_FILE="/var/lib/zksync/data/INIT_COMPLETED.remove_to_reset" - -if [ -f "$INIT_FILE" ]; then - echo "Initialization was done in the past - simply starting server" -else - echo "Initialing local environment" - - mkdir -p /var/lib/zksync/data - - update_config "/etc/env/base/private.toml" "database_url" "$DATABASE_URL" - update_config "/etc/env/base/private.toml" "database_prover_url" "$DATABASE_PROVER_URL" - update_config "/etc/env/base/eth_client.toml" "web3_url" "$ETH_CLIENT_WEB3_URL" - # Put database in a special /var/lib directory so that it is persisted between docker runs. - update_config "/etc/env/base/database.toml" "path" "/var/lib/zksync/data" - update_config "/etc/env/base/database.toml" "state_keeper_db_path" "/var/lib/zksync/data/state_keeper" - update_config "/etc/env/base/database.toml" "backup_path" "/var/lib/zksync/data/backups" - - if [ -n "$LEGACY_BRIDGE_TESTING" ]; then - # making era chain id same as current chain id for legacy bridge testing - chain_eth_zksync_network_id=$(read_value_from_config "/etc/env/base/chain.toml" "zksync_network_id") - update_config "/etc/env/base/contracts.toml" "ERA_CHAIN_ID" "$chain_eth_zksync_network_id" - fi - - if [ -z "$MASTER_URL" ]; then - echo "Starting with hyperchain" - else - # Updates all the stuff (from the '/etc/master_env') - it assumes that it is mapped via docker compose. - zk f yarn --cwd /infrastructure/local-setup-preparation join - fi - - zk config compile - - zk db reset - - # Perform initialization (things needed to be done only if you're running in the master mode) - if [ -z "$MASTER_URL" ]; then - zk contract deploy-verifier - zk run deploy-erc20 dev # (created etc/tokens/localhost) - - ## init bridgehub state transition - zk contract deploy # (deploy L1) - zk contract initialize-governance - zk contract initialize-validator - fi - - - if [ -z "$CUSTOM_BASE_TOKEN" ]; then - echo "Starting chain with ETH as gas token" - - if [ -z "$VALIDIUM_MODE" ]; then - ## init hyperchain in rollup mode - zk contract register-hyperchain - else - zk contract register-hyperchain --deployment-mode 1 - fi - else - echo "Starting chain with custom gas token $CUSTOM_BASE_TOKEN" - zk contract register-hyperchain --base-token-name $CUSTOM_BASE_TOKEN - fi - - - zk f zksync_server --genesis - - deploy_l2_args="" - if [ -n "$LEGACY_BRIDGE_TESTING" ]; then - # setting the flag for legacy bridge testing - deploy_l2_args="--local-legacy-bridge-testing" - fi - - zk contract deploy-l2-through-l1 $deploy_l2_args - - if [ -z "$MASTER_URL" ]; then - zk f yarn --cwd /infrastructure/local-setup-preparation start - fi - - if [ -n "$LEGACY_BRIDGE_TESTING" ]; then - # making era address same as current address for legacy bridge testing - contracts_diamond_proxy_addr=$(read_value_from_config "/etc/env/target/dev.env" "CONTRACTS_DIAMOND_PROXY_ADDR") - update_config "/etc/env/target/dev.env" "CONTRACTS_ERA_DIAMOND_PROXY_ADDR" "$contracts_diamond_proxy_addr" - - # setup-legacy-bridge-era waits for the server to be ready, so starting it in the background - zk contract setup-legacy-bridge-era & - fi - - # Create init file. - echo "System initialized. Please remove this file if you want to reset the system" >$INIT_FILE - -fi +# RUST VERSION + CLANG?? +# dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.sock > /var/log/dockerd.log 2>&1 & + +apt update && apt install -y clang llvm-dev libclang-dev +# find /usr -name "libclang.so*" +export LIBCLANG_PATH=/usr/lib/llvm-14/lib +# apt install -y pkg-config libssl-dev + +./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup + +zkstackup -g --local --cargo-features gateway + +# apt-get update && apt-get install -y docker.io +# curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +# chmod +x /usr/local/bin/docker-compose +apt-get update && apt-get install -y ca-certificates curl gnupg +mkdir -m 0755 /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg +echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null +apt-get update +apt-get install -y docker-compose-plugin +curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash +export PATH=$HOME/.foundry/bin:$PATH + +# nohup dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.sock > /var/log/dockerd.log 2>&1 & + +# zkstack dev contracts + +# export COMPOSE_PROJECT_NAME=my_project_name +# export GITHUB_WORKSPACE=my_github_workspace + +# zkstack up -o false + +# docker cp /chaindata/reth_config my_project_name-reth-1:/chaindata/reth_config + +# socat TCP-LISTEN:5432,fork TCP:host.docker.internal:5432 & +# socat TCP-LISTEN:8545,fork TCP:host.docker.internal:8545 & + +# docker run --privileged -it docker:dind + +# DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@localhost/prover_local +# DATABASE_URL=postgres://postgres:notsecurepassword@localhost:5432/zksync_server_localhost_era +# DATABASE_URL=postgres://postgres:notsecurepassword@localhost/zksync_local +# DATABASE_URL=postgres://postgres://postgres:notsecurepassword@localhost:5432/zksync_server_localhost_era + +zkstack ecosystem init --deploy-paymaster --deploy-erc20 \ + --deploy-ecosystem --l1-rpc-url=http://localhost:8545 \ + --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ + --server-db-name=zksync_server_localhost_era \ + --ignore-prerequisites --verbose \ + --observability=false \ + --update-submodules=false + +# CUSTOM_TOKEN_ADDRESS=$(awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /DAI:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' ./configs/erc20.yaml) +# echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" +# echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" >> $GITHUB_ENV + +# zkstack chain create \ +# --chain-name validium \ +# --chain-id sequential \ +# --prover-mode no-proofs \ +# --wallet-creation localhost \ +# --l1-batch-commit-data-generator-mode validium \ +# --base-token-address 0x0000000000000000000000000000000000000001 \ +# --base-token-price-nominator 1 \ +# --base-token-price-denominator 1 \ +# --set-as-default false \ +# --ignore-prerequisites \ +# --evm-emulator false + +# zkstack chain init \ +# --deploy-paymaster \ +# --l1-rpc-url=http://localhost:8545 \ +# --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ +# --server-db-name=zksync_server_localhost_validium \ +# --chain validium \ +# --validium-type no-da + +# zkstack chain create \ +# --chain-name custom_token \ +# --chain-id sequential \ +# --prover-mode no-proofs \ +# --wallet-creation localhost \ +# --l1-batch-commit-data-generator-mode rollup \ +# --base-token-address ${{ env.CUSTOM_TOKEN_ADDRESS }} \ +# --base-token-price-nominator 314 \ +# --base-token-price-denominator 1000 \ +# --set-as-default false \ +# --ignore-prerequisites \ +# --evm-emulator false + +# zkstack chain init \ +# --deploy-paymaster \ +# --l1-rpc-url=http://localhost:8545 \ +# --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ +# --server-db-name=zksync_server_localhost_custom_token \ +# --chain custom_token \ +# --validium-type no-da + +# zkstack chain create \ +# --chain-name offline_chain \ +# --chain-id sequential \ +# --prover-mode no-proofs \ +# --wallet-creation localhost \ +# --l1-batch-commit-data-generator-mode rollup \ +# --base-token-address 0x0000000000000000000000000000000000000001 \ +# --base-token-price-nominator 1 \ +# --base-token-price-denominator 1 \ +# --set-as-default false \ +# --ignore-prerequisites \ +# --evm-emulator false + +# zkstack chain build-transactions --chain offline_chain --l1-rpc-url http://127.0.0.1:8545 + +# governor_pk=$(awk '/governor:/ {flag=1} flag && /private_key:/ {print $2; exit}' ./configs/wallets.yaml) + +# zkstack dev send-transactions \ +# --file ./transactions/chain/offline_chain/register-zk-chain-txns.json \ +# --l1-rpc-url http://127.0.0.1:8545 \ +# --private-key $governor_pk + +# bridge_hub=$(awk '/bridgehub_proxy_addr/ {print $2}' ./configs/contracts.yaml) +# chain_id=$(awk '/chain_id:/ {print $2}' ./chains/offline_chain/ZkStack.yaml) + +# hyperchain_output=$(ci_run cast call $bridge_hub "getHyperchain(uint256)" $chain_id) + +# if [[ $hyperchain_output == 0x* && ${#hyperchain_output} -eq 66 ]]; then +# echo "Chain successfully registered: $hyperchain_output" +# else +# echo "Failed to register chain: $hyperchain_output" +# exit 1 +# fi + +# zkstack chain create \ +# --chain-name consensus \ +# --chain-id sequential \ +# --prover-mode no-proofs \ +# --wallet-creation localhost \ +# --l1-batch-commit-data-generator-mode validium \ +# --base-token-address ${{ env.CUSTOM_TOKEN_ADDRESS }} \ +# --base-token-price-nominator 314 \ +# --base-token-price-denominator 1000 \ +# --set-as-default false \ +# --ignore-prerequisites \ +# --evm-emulator false + +# zkstack chain init \ +# --deploy-paymaster \ +# --l1-rpc-url=http://localhost:8545 \ +# --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ +# --server-db-name=zksync_server_localhost_consensus \ +# --chain consensus \ +# --validium-type no-da + +# CHAINS="era,validium,custom_token,consensus" +# echo "CHAINS=$CHAINS" + +# zkstack chain create \ +# --chain-name gateway \ +# --chain-id 505 \ +# --prover-mode no-proofs \ +# --wallet-creation localhost \ +# --l1-batch-commit-data-generator-mode rollup \ +# --base-token-address 0x0000000000000000000000000000000000000001 \ +# --base-token-price-nominator 1 \ +# --base-token-price-denominator 1 \ +# --set-as-default false \ +# --ignore-prerequisites \ +# --evm-emulator false + +# zkstack chain init \ +# --deploy-paymaster \ +# --l1-rpc-url=http://localhost:8545 \ +# --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ +# --server-db-name=zksync_server_localhost_gateway \ +# --chain gateway \ +# --validium-type no-da + +# zkstack chain convert-to-gateway --chain gateway --ignore-prerequisites + +# zkstack server --ignore-prerequisites --chain gateway &> ${{ env.SERVER_LOGS_DIR }}/gateway.log & +# zkstack server wait --ignore-prerequisites --verbose --chain gateway + +# zkstack chain migrate-to-gateway --chain era --gateway-chain-name gateway +# zkstack chain migrate-to-gateway --chain validium --gateway-chain-name gateway +# zkstack chain migrate-to-gateway --chain custom_token --gateway-chain-name gateway +# zkstack chain migrate-to-gateway --chain consensus --gateway-chain-name gateway + +# zkstack server --ignore-prerequisites --chain era &> ${{ env.SERVER_LOGS_DIR }}/rollup.log & +# zkstack server --ignore-prerequisites --chain validium &> ${{ env.SERVER_LOGS_DIR }}/validium.log & +# zkstack server --ignore-prerequisites --chain custom_token &> ${{ env.SERVER_LOGS_DIR }}/custom_token.log & +# zkstack server --ignore-prerequisites --chain consensus \ +# --components=api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,vm_playground,da_dispatcher,consensus \ +# &> ${{ env.SERVER_LOGS_DIR }}/consensus.log & + +# zkstack server wait --ignore-prerequisites --verbose --chain era +# zkstack server wait --ignore-prerequisites --verbose --chain validium +# zkstack server wait --ignore-prerequisites --verbose --chain custom_token +# zkstack server wait --ignore-prerequisites --verbose --chain consensus # start server -zk f zksync_server +zkstack server From 48d2e608e4b82b57bdce7eeceac78d5f1e08f108 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 28 Jan 2025 17:41:26 +0400 Subject: [PATCH 02/10] (test): entrypoint --- docker/local-node/entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/local-node/entrypoint.sh b/docker/local-node/entrypoint.sh index 15e340b6bce9..84f5a7b78ab3 100755 --- a/docker/local-node/entrypoint.sh +++ b/docker/local-node/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -ea +# set -ea # RUST VERSION + CLANG?? # dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.sock > /var/log/dockerd.log 2>&1 & @@ -16,7 +16,7 @@ zkstackup -g --local --cargo-features gateway # curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose # chmod +x /usr/local/bin/docker-compose apt-get update && apt-get install -y ca-certificates curl gnupg -mkdir -m 0755 /etc/apt/keyrings +# mkdir -m 0755 /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ From 52b8ba5f972f040e47d2d724bce06a0563d4cb54 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 28 Jan 2025 17:43:26 +0400 Subject: [PATCH 03/10] (test): entrypoint --- .githooks/pre-push | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/.githooks/pre-push b/.githooks/pre-push index ef5e77cbc796..d76ee5a8e3c4 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -1,34 +1,34 @@ -#!/bin/bash -# -# Pre-push hook verifying that inappropriate code will not be pushed. +# #!/bin/bash +# # +# # Pre-push hook verifying that inappropriate code will not be pushed. -# Colors for the terminal output -RED='\033[0;31m' -NC='\033[0m' # No Color +# # Colors for the terminal output +# RED='\033[0;31m' +# NC='\033[0m' # No Color -# Common prompts -INSTALL_PROPT="Please install ZK Stack CLI using zkstackup from https://github.com/matter-labs/zksync-era/tree/main/zkstack_cli/zkstackup" -FORMAT_PROMPT="Please format the code via 'zkstack dev fmt', cannot push unformatted code" +# # Common prompts +# INSTALL_PROPT="Please install ZK Stack CLI using zkstackup from https://github.com/matter-labs/zksync-era/tree/main/zkstack_cli/zkstackup" +# FORMAT_PROMPT="Please format the code via 'zkstack dev fmt', cannot push unformatted code" -# Check that prettier formatting rules are not violated. -if which zkstack >/dev/null; then - if ! zkstack dev fmt --check; then - echo -e "${RED}Push error!${NC}" - echo -e "${FORMAT_PROMPT}" - exit 1 - fi -else - if which zk_supervisor >/dev/null; then - echo -e "${RED}WARNING: zkup, zk_inception/zki, and zk_supervisor/zks are DEPRECATED.${NC}" - echo -e "${RED}${INSTALL_PROPT}${NC}" +# # Check that prettier formatting rules are not violated. +# if which zkstack >/dev/null; then +# if ! zkstack dev fmt --check; then +# echo -e "${RED}Push error!${NC}" +# echo -e "${FORMAT_PROMPT}" +# exit 1 +# fi +# else +# if which zk_supervisor >/dev/null; then +# echo -e "${RED}WARNING: zkup, zk_inception/zki, and zk_supervisor/zks are DEPRECATED.${NC}" +# echo -e "${RED}${INSTALL_PROPT}${NC}" - if ! zk_supervisor fmt --check; then - echo -e "${RED}Push error!${NC}" - echo -e "${FORMAT_PROMPT}" - exit 1 - fi - else - echo -e "${INSTALL_PROPT}" - exit 1 - fi -fi +# if ! zk_supervisor fmt --check; then +# echo -e "${RED}Push error!${NC}" +# echo -e "${FORMAT_PROMPT}" +# exit 1 +# fi +# else +# echo -e "${INSTALL_PROPT}" +# exit 1 +# fi +# fi From 79f728c3165ebf6c9b10481f7ab3b96597834396 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 28 Jan 2025 17:44:35 +0400 Subject: [PATCH 04/10] (fix): revert change --- .githooks/pre-push | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/.githooks/pre-push b/.githooks/pre-push index d76ee5a8e3c4..ef5e77cbc796 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -1,34 +1,34 @@ -# #!/bin/bash -# # -# # Pre-push hook verifying that inappropriate code will not be pushed. +#!/bin/bash +# +# Pre-push hook verifying that inappropriate code will not be pushed. -# # Colors for the terminal output -# RED='\033[0;31m' -# NC='\033[0m' # No Color +# Colors for the terminal output +RED='\033[0;31m' +NC='\033[0m' # No Color -# # Common prompts -# INSTALL_PROPT="Please install ZK Stack CLI using zkstackup from https://github.com/matter-labs/zksync-era/tree/main/zkstack_cli/zkstackup" -# FORMAT_PROMPT="Please format the code via 'zkstack dev fmt', cannot push unformatted code" +# Common prompts +INSTALL_PROPT="Please install ZK Stack CLI using zkstackup from https://github.com/matter-labs/zksync-era/tree/main/zkstack_cli/zkstackup" +FORMAT_PROMPT="Please format the code via 'zkstack dev fmt', cannot push unformatted code" -# # Check that prettier formatting rules are not violated. -# if which zkstack >/dev/null; then -# if ! zkstack dev fmt --check; then -# echo -e "${RED}Push error!${NC}" -# echo -e "${FORMAT_PROMPT}" -# exit 1 -# fi -# else -# if which zk_supervisor >/dev/null; then -# echo -e "${RED}WARNING: zkup, zk_inception/zki, and zk_supervisor/zks are DEPRECATED.${NC}" -# echo -e "${RED}${INSTALL_PROPT}${NC}" +# Check that prettier formatting rules are not violated. +if which zkstack >/dev/null; then + if ! zkstack dev fmt --check; then + echo -e "${RED}Push error!${NC}" + echo -e "${FORMAT_PROMPT}" + exit 1 + fi +else + if which zk_supervisor >/dev/null; then + echo -e "${RED}WARNING: zkup, zk_inception/zki, and zk_supervisor/zks are DEPRECATED.${NC}" + echo -e "${RED}${INSTALL_PROPT}${NC}" -# if ! zk_supervisor fmt --check; then -# echo -e "${RED}Push error!${NC}" -# echo -e "${FORMAT_PROMPT}" -# exit 1 -# fi -# else -# echo -e "${INSTALL_PROPT}" -# exit 1 -# fi -# fi + if ! zk_supervisor fmt --check; then + echo -e "${RED}Push error!${NC}" + echo -e "${FORMAT_PROMPT}" + exit 1 + fi + else + echo -e "${INSTALL_PROPT}" + exit 1 + fi +fi From a30307feb0b60dc3c6d4bcebe50bc47b1c1bb24a Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 29 Jan 2025 15:16:19 +0400 Subject: [PATCH 05/10] (fix): reduce entrypoint size --- docker/local-node/Dockerfile | 20 ++++++++++++++++++++ docker/local-node/entrypoint.sh | 24 ++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/docker/local-node/Dockerfile b/docker/local-node/Dockerfile index ff6d28c27fe6..1beef8f38824 100644 --- a/docker/local-node/Dockerfile +++ b/docker/local-node/Dockerfile @@ -99,6 +99,26 @@ RUN apt-get update && apt-get install -y docker.io ENV COMPOSE_PROJECT_NAME=my_project_name ENV GITHUB_WORKSPACE=my_github_workspace +# Install additional dependencies +RUN apt-get update && apt-get install -y \ + clang llvm-dev libclang-dev \ + ca-certificates curl gnupg \ + && curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash + +# Install required dependencies including Docker +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates curl gnupg lsb-release \ + && mkdir -p /etc/apt/keyrings \ + && curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \ + && apt-get update \ + && apt-get install -y docker-compose-plugin \ + && rm -rf /var/lib/apt/lists/* + +# Set persistent environment variables +ENV LIBCLANG_PATH=/usr/lib/llvm-14/lib +ENV PATH="/usr/local/cargo/bin:/root/.foundry/bin:$PATH" + # CMD ["/bin/bash"] ENTRYPOINT ["entrypoint.sh"] diff --git a/docker/local-node/entrypoint.sh b/docker/local-node/entrypoint.sh index 84f5a7b78ab3..1f131cb38466 100755 --- a/docker/local-node/entrypoint.sh +++ b/docker/local-node/entrypoint.sh @@ -3,9 +3,9 @@ # RUST VERSION + CLANG?? # dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.sock > /var/log/dockerd.log 2>&1 & -apt update && apt install -y clang llvm-dev libclang-dev +# apt update && apt install -y clang llvm-dev libclang-dev # find /usr -name "libclang.so*" -export LIBCLANG_PATH=/usr/lib/llvm-14/lib +# export LIBCLANG_PATH=/usr/lib/llvm-14/lib # apt install -y pkg-config libssl-dev ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup @@ -15,16 +15,16 @@ zkstackup -g --local --cargo-features gateway # apt-get update && apt-get install -y docker.io # curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose # chmod +x /usr/local/bin/docker-compose -apt-get update && apt-get install -y ca-certificates curl gnupg -# mkdir -m 0755 /etc/apt/keyrings -curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg -echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null -apt-get update -apt-get install -y docker-compose-plugin -curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash -export PATH=$HOME/.foundry/bin:$PATH +# apt-get update && apt-get install -y ca-certificates curl gnupg +# # mkdir -m 0755 /etc/apt/keyrings +# curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg +# echo \ +# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ +# $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null +# apt-get update +# apt-get install -y docker-compose-plugin +# curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash +# export PATH=$HOME/.foundry/bin:$PATH # nohup dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.sock > /var/log/dockerd.log 2>&1 & From 4c50b412d984fd35505670c225fda52ad1e7bc1c Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Wed, 29 Jan 2025 21:06:11 +0400 Subject: [PATCH 06/10] (test): entrypoint --- docker/local-node/Dockerfile | 4 + docker/local-node/entrypoint.sh | 155 +++++++++++++++++++++++++++++--- 2 files changed, 149 insertions(+), 10 deletions(-) diff --git a/docker/local-node/Dockerfile b/docker/local-node/Dockerfile index 1beef8f38824..bb1fb31b6ed3 100644 --- a/docker/local-node/Dockerfile +++ b/docker/local-node/Dockerfile @@ -119,6 +119,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ENV LIBCLANG_PATH=/usr/lib/llvm-14/lib ENV PATH="/usr/local/cargo/bin:/root/.foundry/bin:$PATH" +RUN ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup \ + && zkstackup -g --local --cargo-features gateway + + # CMD ["/bin/bash"] ENTRYPOINT ["entrypoint.sh"] diff --git a/docker/local-node/entrypoint.sh b/docker/local-node/entrypoint.sh index 1f131cb38466..638d73f328df 100755 --- a/docker/local-node/entrypoint.sh +++ b/docker/local-node/entrypoint.sh @@ -8,9 +8,9 @@ # export LIBCLANG_PATH=/usr/lib/llvm-14/lib # apt install -y pkg-config libssl-dev -./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup +# ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup -zkstackup -g --local --cargo-features gateway +# zkstackup -g --local --cargo-features gateway # apt-get update && apt-get install -y docker.io # curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose @@ -47,14 +47,6 @@ zkstackup -g --local --cargo-features gateway # DATABASE_URL=postgres://postgres:notsecurepassword@localhost/zksync_local # DATABASE_URL=postgres://postgres://postgres:notsecurepassword@localhost:5432/zksync_server_localhost_era -zkstack ecosystem init --deploy-paymaster --deploy-erc20 \ - --deploy-ecosystem --l1-rpc-url=http://localhost:8545 \ - --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ - --server-db-name=zksync_server_localhost_era \ - --ignore-prerequisites --verbose \ - --observability=false \ - --update-submodules=false - # CUSTOM_TOKEN_ADDRESS=$(awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /DAI:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' ./configs/erc20.yaml) # echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" # echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" >> $GITHUB_ENV @@ -202,5 +194,148 @@ zkstack ecosystem init --deploy-paymaster --deploy-erc20 \ # zkstack server wait --ignore-prerequisites --verbose --chain custom_token # zkstack server wait --ignore-prerequisites --verbose --chain consensus + +# These 3 env variables must be provided. +if [ -z "$DATABASE_URL" ]; then + echo "ERROR: DATABASE_URL is not set." + exit 1 +fi + +if [ -z "$DATABASE_PROVER_URL" ]; then + echo "ERROR: DATABASE_PROVER_URL is not set." + exit 1 +fi + +if [ -z "$ETH_CLIENT_WEB3_URL" ]; then + echo "ERROR: ETH_CLIENT_WEB3_URL is not set." + exit 1 +fi + +# Function to update a key in a YAML file +update_config() { + local file="$1" + local key="$2" + local new_value="$3" + + # Escape special characters for sed + local escaped_key=$(echo "$key" | sed 's/\./\\./g') + local pattern="^\\s*${escaped_key}:.*$" + + # Check if the key exists in the file + if grep -qE "$pattern" "$file"; then + # Update the existing key + sed -i "s|$pattern|${key}: $new_value|" "$file" + echo "Updated '$key' in $file." + else + # Append the key if it doesn't exist + echo "$key: $new_value" >> "$file" + echo "Added '$key' to $file." + fi +} + + +# wait till db service is ready +until psql ${DATABASE_URL%/*} -c '\q'; do + echo >&2 "Postgres is unavailable - sleeping" + sleep 5 +done + +echo "Initialing local environment" + +update_config "/chains/era/configs/secrets.yaml" "server_url" "$DATABASE_URL" +update_config "/chains/era/configs/secrets.yaml" "prover_url" "$DATABASE_PROVER_URL" +update_config "/chains/era/configs/secrets.yaml" "l1_rpc_url" "$ETH_CLIENT_WEB3_URL" + +# Extract the database name (everything after the last '/') +SERVER_DB_NAME="${DATABASE_URL##*/}" + +# Extract the database URL without the database name +SERVER_DB_URL="${DATABASE_URL%/*}" + +zkstack ecosystem init --deploy-paymaster --deploy-erc20 \ + --deploy-ecosystem --l1-rpc-url=$ETH_CLIENT_WEB3_URL \ + --server-db-url="$SERVER_DB_URL" \ + --server-db-name="$SERVER_DB_NAME" \ + --ignore-prerequisites --verbose \ + --observability=false \ + --update-submodules=false + +# if [ -z "$MASTER_URL" ]; then +# echo "Running as zksync master" +# else +# # If running in slave mode - wait for the master to be up and running. +# echo "Waiting for zksync master to init hyperchain" +# until curl --fail ${MASTER_HEALTH_URL}; do +# echo >&2 "Master zksync not ready yet, sleeping" +# sleep 5 +# done +# fi + +# if [ -n "$LEGACY_BRIDGE_TESTING" ]; then +# if [ -z "$MASTER_URL" ]; then +# echo "Running in legacy bridge testing mode" +# else +# # LEGACY_BRIDGE_TESTING flag is for the master only +# unset LEGACY_BRIDGE_TESTING +# fi +# fi + +# Normally, the /etc/env and /var/lib/zksync/data should be mapped to volumes +# so that they are persisted between docker restarts - which would allow even faster starts. + +# We use the existance of this init file to decide whether to restart or not. +# INIT_FILE="/var/lib/zksync/data/INIT_COMPLETED.remove_to_reset" + +# if [ -f "$INIT_FILE" ]; then +# echo "Initialization was done in the past - simply starting server" +# else +# echo "Initialing local environment" + +# mkdir -p /var/lib/zksync/data + +# update_config "/etc/env/base/private.toml" "database_url" "$DATABASE_URL" +# update_config "/etc/env/base/private.toml" "database_prover_url" "$DATABASE_PROVER_URL" +# update_config "/etc/env/base/eth_client.toml" "web3_url" "$ETH_CLIENT_WEB3_URL" +# # Put database in a special /var/lib directory so that it is persisted between docker runs. +# update_config "/etc/env/base/database.toml" "path" "/var/lib/zksync/data" +# update_config "/etc/env/base/database.toml" "state_keeper_db_path" "/var/lib/zksync/data/state_keeper" +# update_config "/etc/env/base/database.toml" "backup_path" "/var/lib/zksync/data/backups" + + # if [ -z "$MASTER_URL" ]; then + # echo "Starting with hyperchain" + # else + # # Updates all the stuff (from the '/etc/master_env') - it assumes that it is mapped via docker compose. + # zk f yarn --cwd /infrastructure/local-setup-preparation join + # fi + + # Perform initialization (things needed to be done only if you're running in the master mode) + # if [ -z "$MASTER_URL" ]; then + # zk contract deploy-verifier + # zk run deploy-erc20 dev # (created etc/tokens/localhost) + + # ## init bridgehub state transition + # zk contract deploy # (deploy L1) + # zk contract initialize-governance + # zk contract initialize-validator + # fi + + + # if [ -z "$CUSTOM_BASE_TOKEN" ]; then + # echo "Starting chain with ETH as gas token" + + # if [ -z "$VALIDIUM_MODE" ]; then + # ## init hyperchain in rollup mode + # zk contract register-hyperchain + # else + # zk contract register-hyperchain --deployment-mode 1 + # fi + # else + # echo "Starting chain with custom gas token $CUSTOM_BASE_TOKEN" + # zk contract register-hyperchain --base-token-name $CUSTOM_BASE_TOKEN + # fi + +# fi + + # start server zkstack server From 45419554391644fd052b90b672c4432f680ce0de Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 31 Jan 2025 14:23:44 +0400 Subject: [PATCH 07/10] (feat): update entrypoint for custom token --- docker/local-node/entrypoint.sh | 327 ++++++-------------------------- 1 file changed, 54 insertions(+), 273 deletions(-) diff --git a/docker/local-node/entrypoint.sh b/docker/local-node/entrypoint.sh index 638d73f328df..b9f0272e62d1 100755 --- a/docker/local-node/entrypoint.sh +++ b/docker/local-node/entrypoint.sh @@ -1,199 +1,4 @@ #!/bin/bash -# set -ea -# RUST VERSION + CLANG?? -# dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.sock > /var/log/dockerd.log 2>&1 & - -# apt update && apt install -y clang llvm-dev libclang-dev -# find /usr -name "libclang.so*" -# export LIBCLANG_PATH=/usr/lib/llvm-14/lib -# apt install -y pkg-config libssl-dev - -# ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup - -# zkstackup -g --local --cargo-features gateway - -# apt-get update && apt-get install -y docker.io -# curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose -# chmod +x /usr/local/bin/docker-compose -# apt-get update && apt-get install -y ca-certificates curl gnupg -# # mkdir -m 0755 /etc/apt/keyrings -# curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg -# echo \ -# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ -# $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null -# apt-get update -# apt-get install -y docker-compose-plugin -# curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash -# export PATH=$HOME/.foundry/bin:$PATH - -# nohup dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.sock > /var/log/dockerd.log 2>&1 & - -# zkstack dev contracts - -# export COMPOSE_PROJECT_NAME=my_project_name -# export GITHUB_WORKSPACE=my_github_workspace - -# zkstack up -o false - -# docker cp /chaindata/reth_config my_project_name-reth-1:/chaindata/reth_config - -# socat TCP-LISTEN:5432,fork TCP:host.docker.internal:5432 & -# socat TCP-LISTEN:8545,fork TCP:host.docker.internal:8545 & - -# docker run --privileged -it docker:dind - -# DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@localhost/prover_local -# DATABASE_URL=postgres://postgres:notsecurepassword@localhost:5432/zksync_server_localhost_era -# DATABASE_URL=postgres://postgres:notsecurepassword@localhost/zksync_local -# DATABASE_URL=postgres://postgres://postgres:notsecurepassword@localhost:5432/zksync_server_localhost_era - -# CUSTOM_TOKEN_ADDRESS=$(awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /DAI:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' ./configs/erc20.yaml) -# echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" -# echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" >> $GITHUB_ENV - -# zkstack chain create \ -# --chain-name validium \ -# --chain-id sequential \ -# --prover-mode no-proofs \ -# --wallet-creation localhost \ -# --l1-batch-commit-data-generator-mode validium \ -# --base-token-address 0x0000000000000000000000000000000000000001 \ -# --base-token-price-nominator 1 \ -# --base-token-price-denominator 1 \ -# --set-as-default false \ -# --ignore-prerequisites \ -# --evm-emulator false - -# zkstack chain init \ -# --deploy-paymaster \ -# --l1-rpc-url=http://localhost:8545 \ -# --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ -# --server-db-name=zksync_server_localhost_validium \ -# --chain validium \ -# --validium-type no-da - -# zkstack chain create \ -# --chain-name custom_token \ -# --chain-id sequential \ -# --prover-mode no-proofs \ -# --wallet-creation localhost \ -# --l1-batch-commit-data-generator-mode rollup \ -# --base-token-address ${{ env.CUSTOM_TOKEN_ADDRESS }} \ -# --base-token-price-nominator 314 \ -# --base-token-price-denominator 1000 \ -# --set-as-default false \ -# --ignore-prerequisites \ -# --evm-emulator false - -# zkstack chain init \ -# --deploy-paymaster \ -# --l1-rpc-url=http://localhost:8545 \ -# --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ -# --server-db-name=zksync_server_localhost_custom_token \ -# --chain custom_token \ -# --validium-type no-da - -# zkstack chain create \ -# --chain-name offline_chain \ -# --chain-id sequential \ -# --prover-mode no-proofs \ -# --wallet-creation localhost \ -# --l1-batch-commit-data-generator-mode rollup \ -# --base-token-address 0x0000000000000000000000000000000000000001 \ -# --base-token-price-nominator 1 \ -# --base-token-price-denominator 1 \ -# --set-as-default false \ -# --ignore-prerequisites \ -# --evm-emulator false - -# zkstack chain build-transactions --chain offline_chain --l1-rpc-url http://127.0.0.1:8545 - -# governor_pk=$(awk '/governor:/ {flag=1} flag && /private_key:/ {print $2; exit}' ./configs/wallets.yaml) - -# zkstack dev send-transactions \ -# --file ./transactions/chain/offline_chain/register-zk-chain-txns.json \ -# --l1-rpc-url http://127.0.0.1:8545 \ -# --private-key $governor_pk - -# bridge_hub=$(awk '/bridgehub_proxy_addr/ {print $2}' ./configs/contracts.yaml) -# chain_id=$(awk '/chain_id:/ {print $2}' ./chains/offline_chain/ZkStack.yaml) - -# hyperchain_output=$(ci_run cast call $bridge_hub "getHyperchain(uint256)" $chain_id) - -# if [[ $hyperchain_output == 0x* && ${#hyperchain_output} -eq 66 ]]; then -# echo "Chain successfully registered: $hyperchain_output" -# else -# echo "Failed to register chain: $hyperchain_output" -# exit 1 -# fi - -# zkstack chain create \ -# --chain-name consensus \ -# --chain-id sequential \ -# --prover-mode no-proofs \ -# --wallet-creation localhost \ -# --l1-batch-commit-data-generator-mode validium \ -# --base-token-address ${{ env.CUSTOM_TOKEN_ADDRESS }} \ -# --base-token-price-nominator 314 \ -# --base-token-price-denominator 1000 \ -# --set-as-default false \ -# --ignore-prerequisites \ -# --evm-emulator false - -# zkstack chain init \ -# --deploy-paymaster \ -# --l1-rpc-url=http://localhost:8545 \ -# --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ -# --server-db-name=zksync_server_localhost_consensus \ -# --chain consensus \ -# --validium-type no-da - -# CHAINS="era,validium,custom_token,consensus" -# echo "CHAINS=$CHAINS" - -# zkstack chain create \ -# --chain-name gateway \ -# --chain-id 505 \ -# --prover-mode no-proofs \ -# --wallet-creation localhost \ -# --l1-batch-commit-data-generator-mode rollup \ -# --base-token-address 0x0000000000000000000000000000000000000001 \ -# --base-token-price-nominator 1 \ -# --base-token-price-denominator 1 \ -# --set-as-default false \ -# --ignore-prerequisites \ -# --evm-emulator false - -# zkstack chain init \ -# --deploy-paymaster \ -# --l1-rpc-url=http://localhost:8545 \ -# --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ -# --server-db-name=zksync_server_localhost_gateway \ -# --chain gateway \ -# --validium-type no-da - -# zkstack chain convert-to-gateway --chain gateway --ignore-prerequisites - -# zkstack server --ignore-prerequisites --chain gateway &> ${{ env.SERVER_LOGS_DIR }}/gateway.log & -# zkstack server wait --ignore-prerequisites --verbose --chain gateway - -# zkstack chain migrate-to-gateway --chain era --gateway-chain-name gateway -# zkstack chain migrate-to-gateway --chain validium --gateway-chain-name gateway -# zkstack chain migrate-to-gateway --chain custom_token --gateway-chain-name gateway -# zkstack chain migrate-to-gateway --chain consensus --gateway-chain-name gateway - -# zkstack server --ignore-prerequisites --chain era &> ${{ env.SERVER_LOGS_DIR }}/rollup.log & -# zkstack server --ignore-prerequisites --chain validium &> ${{ env.SERVER_LOGS_DIR }}/validium.log & -# zkstack server --ignore-prerequisites --chain custom_token &> ${{ env.SERVER_LOGS_DIR }}/custom_token.log & -# zkstack server --ignore-prerequisites --chain consensus \ -# --components=api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,vm_playground,da_dispatcher,consensus \ -# &> ${{ env.SERVER_LOGS_DIR }}/consensus.log & - -# zkstack server wait --ignore-prerequisites --verbose --chain era -# zkstack server wait --ignore-prerequisites --verbose --chain validium -# zkstack server wait --ignore-prerequisites --verbose --chain custom_token -# zkstack server wait --ignore-prerequisites --verbose --chain consensus - # These 3 env variables must be provided. if [ -z "$DATABASE_URL" ]; then @@ -242,9 +47,17 @@ done echo "Initialing local environment" -update_config "/chains/era/configs/secrets.yaml" "server_url" "$DATABASE_URL" -update_config "/chains/era/configs/secrets.yaml" "prover_url" "$DATABASE_PROVER_URL" -update_config "/chains/era/configs/secrets.yaml" "l1_rpc_url" "$ETH_CLIENT_WEB3_URL" +# Determine the correct config path based on MASTER_URL +if [ -z "$MASTER_URL" ]; then + CONFIG_PATH="/chains/era/configs" + echo "Updating configuration for MASTER chain..." +else + CONFIG_PATH="/chains/custom_token/configs" + echo "Updating configuration for Custom Token chain..." +fi +# update_config "/chains/era/configs/secrets.yaml" "server_url" "$DATABASE_URL" +# update_config "/chains/era/configs/secrets.yaml" "prover_url" "$DATABASE_PROVER_URL" +# update_config "/chains/era/configs/secrets.yaml" "l1_rpc_url" "$ETH_CLIENT_WEB3_URL" # Extract the database name (everything after the last '/') SERVER_DB_NAME="${DATABASE_URL##*/}" @@ -252,90 +65,58 @@ SERVER_DB_NAME="${DATABASE_URL##*/}" # Extract the database URL without the database name SERVER_DB_URL="${DATABASE_URL%/*}" -zkstack ecosystem init --deploy-paymaster --deploy-erc20 \ +if [ -z "$MASTER_URL" ]; then + echo "Running as zksync master" + + update_config "$CONFIG_PATH/secrets.yaml" "server_url" "$DATABASE_URL" + update_config "$CONFIG_PATH/secrets.yaml" "prover_url" "$DATABASE_PROVER_URL" + update_config "$CONFIG_PATH/secrets.yaml" "l1_rpc_url" "$ETH_CLIENT_WEB3_URL" + + echo "Configuration updated successfully." + + zkstack ecosystem init --deploy-paymaster --deploy-erc20 \ --deploy-ecosystem --l1-rpc-url=$ETH_CLIENT_WEB3_URL \ --server-db-url="$SERVER_DB_URL" \ --server-db-name="$SERVER_DB_NAME" \ --ignore-prerequisites --verbose \ --observability=false \ --update-submodules=false +else + zkstack chain create \ + --chain-name custom_token \ + --chain-id sequential \ + --prover-mode no-proofs \ + --wallet-creation localhost \ + --l1-batch-commit-data-generator-mode rollup \ + --base-token-address ${CUSTOM_TOKEN_ADDRESS} \ + --base-token-price-nominator 314 \ + --base-token-price-denominator 1000 \ + --set-as-default false \ + --ignore-prerequisites \ + --evm-emulator false \ + --update-submodules=false -# if [ -z "$MASTER_URL" ]; then -# echo "Running as zksync master" -# else -# # If running in slave mode - wait for the master to be up and running. -# echo "Waiting for zksync master to init hyperchain" -# until curl --fail ${MASTER_HEALTH_URL}; do -# echo >&2 "Master zksync not ready yet, sleeping" -# sleep 5 -# done -# fi - -# if [ -n "$LEGACY_BRIDGE_TESTING" ]; then -# if [ -z "$MASTER_URL" ]; then -# echo "Running in legacy bridge testing mode" -# else -# # LEGACY_BRIDGE_TESTING flag is for the master only -# unset LEGACY_BRIDGE_TESTING -# fi -# fi - -# Normally, the /etc/env and /var/lib/zksync/data should be mapped to volumes -# so that they are persisted between docker restarts - which would allow even faster starts. - -# We use the existance of this init file to decide whether to restart or not. -# INIT_FILE="/var/lib/zksync/data/INIT_COMPLETED.remove_to_reset" - -# if [ -f "$INIT_FILE" ]; then -# echo "Initialization was done in the past - simply starting server" -# else -# echo "Initialing local environment" - -# mkdir -p /var/lib/zksync/data - -# update_config "/etc/env/base/private.toml" "database_url" "$DATABASE_URL" -# update_config "/etc/env/base/private.toml" "database_prover_url" "$DATABASE_PROVER_URL" -# update_config "/etc/env/base/eth_client.toml" "web3_url" "$ETH_CLIENT_WEB3_URL" -# # Put database in a special /var/lib directory so that it is persisted between docker runs. -# update_config "/etc/env/base/database.toml" "path" "/var/lib/zksync/data" -# update_config "/etc/env/base/database.toml" "state_keeper_db_path" "/var/lib/zksync/data/state_keeper" -# update_config "/etc/env/base/database.toml" "backup_path" "/var/lib/zksync/data/backups" - - # if [ -z "$MASTER_URL" ]; then - # echo "Starting with hyperchain" - # else - # # Updates all the stuff (from the '/etc/master_env') - it assumes that it is mapped via docker compose. - # zk f yarn --cwd /infrastructure/local-setup-preparation join - # fi - - # Perform initialization (things needed to be done only if you're running in the master mode) - # if [ -z "$MASTER_URL" ]; then - # zk contract deploy-verifier - # zk run deploy-erc20 dev # (created etc/tokens/localhost) - - # ## init bridgehub state transition - # zk contract deploy # (deploy L1) - # zk contract initialize-governance - # zk contract initialize-validator - # fi - - - # if [ -z "$CUSTOM_BASE_TOKEN" ]; then - # echo "Starting chain with ETH as gas token" - - # if [ -z "$VALIDIUM_MODE" ]; then - # ## init hyperchain in rollup mode - # zk contract register-hyperchain - # else - # zk contract register-hyperchain --deployment-mode 1 - # fi - # else - # echo "Starting chain with custom gas token $CUSTOM_BASE_TOKEN" - # zk contract register-hyperchain --base-token-name $CUSTOM_BASE_TOKEN - # fi + update_config "$CONFIG_PATH/secrets.yaml" "server_url" "$DATABASE_URL" + update_config "$CONFIG_PATH/secrets.yaml" "prover_url" "$DATABASE_PROVER_URL" + update_config "$CONFIG_PATH/secrets.yaml" "l1_rpc_url" "$ETH_CLIENT_WEB3_URL" -# fi + echo "Configuration updated successfully." + zkstack chain init \ + --deploy-paymaster \ + --l1-rpc-url=$ETH_CLIENT_WEB3_URL \ + --server-db-url="$SERVER_DB_URL" \ + --server-db-name="$SERVER_DB_NAME" \ + --chain custom_token \ + --validium-type no-da \ + --update-submodules=false + # # If running in slave mode - wait for the master to be up and running. + # echo "Waiting for zksync master to init hyperchain" + # until curl --fail ${MASTER_HEALTH_URL}; do + # echo >&2 "Master zksync not ready yet, sleeping" + # sleep 5 + # done +fi # start server zkstack server From 276033be16690e36f8cdefdcbdea80201808dbaa Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 31 Jan 2025 20:15:57 +0400 Subject: [PATCH 08/10] (fix): entrypoint for custom-base-token --- docker/local-node/entrypoint.sh | 12 +++++++----- zkstack_cli/crates/common/src/ethereum.rs | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docker/local-node/entrypoint.sh b/docker/local-node/entrypoint.sh index b9f0272e62d1..3cb082d824fb 100755 --- a/docker/local-node/entrypoint.sh +++ b/docker/local-node/entrypoint.sh @@ -81,10 +81,13 @@ if [ -z "$MASTER_URL" ]; then --ignore-prerequisites --verbose \ --observability=false \ --update-submodules=false + + # start server + zkstack server else zkstack chain create \ --chain-name custom_token \ - --chain-id sequential \ + --chain-id 275 \ --prover-mode no-proofs \ --wallet-creation localhost \ --l1-batch-commit-data-generator-mode rollup \ @@ -116,7 +119,6 @@ else # echo >&2 "Master zksync not ready yet, sleeping" # sleep 5 # done -fi - -# start server -zkstack server + # start server + zkstack server --chain custom_token +fi \ No newline at end of file diff --git a/zkstack_cli/crates/common/src/ethereum.rs b/zkstack_cli/crates/common/src/ethereum.rs index 96ec8b4f3597..eebaefccb578 100644 --- a/zkstack_cli/crates/common/src/ethereum.rs +++ b/zkstack_cli/crates/common/src/ethereum.rs @@ -8,6 +8,7 @@ use ethers::{ providers::Middleware, types::{Address, TransactionRequest}, }; +use tokio::time::sleep; use zkstack_cli_types::TokenInfo; use crate::{logger, wallets::Wallet}; @@ -102,6 +103,8 @@ pub async fn mint_token( let mut pending_txs = vec![]; for call in &pending_calls { + sleep(Duration::from_secs(2)).await; // ✅ Wait for 2 seconds + let call = call.send().await; match call { // It's safe to set such low number of confirmations and low interval for localhost From 207c90e64a983878d16dd3cc2966c37ee8c2aaa1 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Fri, 31 Jan 2025 20:28:16 +0400 Subject: [PATCH 09/10] (fix): entrypoint --- docker/local-node/entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/local-node/entrypoint.sh b/docker/local-node/entrypoint.sh index 3cb082d824fb..9987fcbb368d 100755 --- a/docker/local-node/entrypoint.sh +++ b/docker/local-node/entrypoint.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -ea # These 3 env variables must be provided. if [ -z "$DATABASE_URL" ]; then From 2e13bf6a910d202e1bb6948e5131c03e61309483 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 3 Feb 2025 16:15:22 +0400 Subject: [PATCH 10/10] (fix): remove zk tool being built --- docker/local-node/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/local-node/Dockerfile b/docker/local-node/Dockerfile index bb1fb31b6ed3..6a87500e0706 100644 --- a/docker/local-node/Dockerfile +++ b/docker/local-node/Dockerfile @@ -49,7 +49,7 @@ ENV IN_DOCKER=1 # Build all the required TS packages # Build `local-setup-preparation` tool -RUN cd /infrastructure/local-setup-preparation && yarn && cd / +# RUN cd /infrastructure/local-setup-preparation && yarn && cd / # Build L1 contracts package (contracts themselves should be already built) RUN cd /contracts/l1-contracts && yarn && cd / # Same for L2 contracts