diff --git a/start-zk-chains.sh b/start-zk-chains.sh index 4d67b17..63c2da1 100755 --- a/start-zk-chains.sh +++ b/start-zk-chains.sh @@ -1,28 +1,61 @@ #!/usr/bin/env bash -# usage: ./start-zk-chains.sh INSTANCE_TYPE -# Instance type is specifying the docker image to take: -# see https://hub.docker.com/r/matterlabs/local-node/tags for full list. -# latest2.0 - is the 'main' one. +set -e +# usage: ./start-network.sh INSTANCE_TYPE +# Instance type specifies the docker image to take. INSTANCE_TYPE=${1:-latest2.0} export INSTANCE_TYPE=$INSTANCE_TYPE -# Fetch the latest images +# Fetch the latest images and start all services docker compose -f zk-chains-docker-compose.yml pull +docker compose -f zk-chains-docker-compose.yml up -d zksync + +echo "Waiting for zkSync master node to be ready..." +until curl --fail http://localhost:15102/health; do + echo "zkSync not ready yet, sleeping..." + sleep 10 +done + +echo "zkSync is ready. Waiting for token deployment..." +until docker exec local-setup-zksync-1 test -f /configs/erc20.yaml; do + echo "Token config file not found yet, checking again in 5 seconds..." + sleep 5 +done + +echo "Extracting deployed token address from inside zksync container..." +CUSTOM_TOKEN_ADDRESS=$(docker exec local-setup-zksync-1 awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /WBTC:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' /configs/erc20.yaml) + +if [ -z "$CUSTOM_TOKEN_ADDRESS" ]; then + echo "❌ Error: Could not retrieve token address. Exiting." + exit 1 +fi + +echo "✅ CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" + +# ✅ Write to .env for docker-compose +echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" > .env + +# ✅ Restart zksync_custombase with the correct value +docker compose -f zk-chains-docker-compose.yml up -d zksync_custombase + +echo "✅ zksync_custombase started with CUSTOM_BASE_TOKEN=$CUSTOM_TOKEN_ADDRESS" + +# Ensure all services are running +echo "Starting all services..." docker compose -f zk-chains-docker-compose.yml up -d +# Function to check if all services are healthy check_all_services_healthy() { - service="zksync" - (docker compose ps $service | grep "(healthy)") - if [ $? -eq 0 ]; then - return 0 - else - return 1 # If any service is not healthy, return 1 - fi + services=("zksync" "zksync_custombase") + for service in "${services[@]}"; do + if ! docker compose -f zk-chains-docker-compose.yml ps "$service" | grep -q "(healthy)"; then + return 1 + fi + done + return 0 } - # Loop until all services are healthy while ! check_all_services_healthy; do echo "Services are not yet healthy, waiting..." diff --git a/zk-chains-docker-compose.yml b/zk-chains-docker-compose.yml index b47c0ac..e1c70f5 100644 --- a/zk-chains-docker-compose.yml +++ b/zk-chains-docker-compose.yml @@ -38,6 +38,7 @@ services: - RUST_LOG=warn ports: - 127.0.0.1:15045:8545 + - 8545:8545 # Make it accessible inside the network postgres: image: "postgres:14" @@ -68,7 +69,7 @@ services: zksync: stdin_open: true tty: true - image: matterlabs/local-node:hyperlocal + image: matterlabs/local-node:latest2.0_gateway_test healthcheck: test: curl --fail http://localhost:3071/health || exit 1 interval: 10s @@ -78,12 +79,14 @@ services: volumes: - shared_config:/etc/env/target - shared_tokens:/etc/tokens + - shared_configs:/configs # ✅ Share /configs volume with other services depends_on: - reth - postgres ports: - 127.0.0.1:15100:3050 # JSON RPC HTTP port - 127.0.0.1:15101:3051 # JSON RPC WS port + - 127.0.0.1:15102:3071 # ✅ Expose health check port on host environment: - DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@postgres/prover_local - DATABASE_URL=postgres://postgres:notsecurepassword@postgres/zksync_local @@ -95,7 +98,7 @@ services: zksync_custombase: stdin_open: true tty: true - image: matterlabs/local-node:hyperlocal + image: matterlabs/local-node:latest2.0_gateway_test depends_on: reth: condition: service_started @@ -104,7 +107,7 @@ services: zksync: condition: service_healthy healthcheck: - test: curl --fail http://localhost:3071/health || exit 1 + test: curl --fail http://localhost:3171/health || exit 1 interval: 10s timeout: 5s retries: 200 @@ -112,56 +115,57 @@ services: volumes: - shared_config:/etc/master_env - shared_tokens:/etc/tokens:ro + - shared_configs:/configs # ✅ Mount /configs from zksync (era) into zksync_custombase ports: - - 127.0.0.1:15200:3050 # JSON RPC HTTP port - - 127.0.0.1:15201:3051 # JSON RPC WS port + - 127.0.0.1:15200:3150 # JSON RPC HTTP port + - 127.0.0.1:15201:3151 # JSON RPC WS port environment: - DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@postgres/prover_custombase - DATABASE_URL=postgres://postgres:notsecurepassword@postgres/zksync_custombase - ETH_CLIENT_WEB3_URL=http://reth:8545 - - CHAIN_ETH_ZKSYNC_NETWORK_ID=272 + - CHAIN_ETH_ZKSYNC_NETWORK_ID=277 - IN_DOCKER=true - MASTER_URL=http://zksync:3050 - MASTER_HEALTH_URL=http://zksync:3071/health - MASTER_ENV_FILE=/etc/master_env/dev.env - - CUSTOM_BASE_TOKEN=BAT - - zksync_validium: - stdin_open: true - tty: true - image: matterlabs/local-node:hyperlocal - depends_on: - reth: - condition: service_started - postgres: - condition: service_started - zksync: - condition: service_healthy - zksync_custombase: # daisy chain - condition: service_healthy - healthcheck: - test: curl --fail http://localhost:3071/health || exit 1 - interval: 10s - timeout: 5s - retries: 200 - start_period: 30s - volumes: - - shared_config:/etc/master_env - - shared_tokens:/etc/tokens:ro - ports: - - 127.0.0.1:15300:3050 # JSON RPC HTTP port - - 127.0.0.1:15301:3051 # JSON RPC WS port - environment: - - DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@postgres/prover_validium - - DATABASE_URL=postgres://postgres:notsecurepassword@postgres/zksync_validium - - ETH_CLIENT_WEB3_URL=http://reth:8545 - - CHAIN_ETH_ZKSYNC_NETWORK_ID=273 - - IN_DOCKER=true - - MASTER_URL=http://zksync:3050 - - MASTER_HEALTH_URL=http://zksync_custombase:3071/health ## daisy chain - - MASTER_ENV_FILE=/etc/master_env/dev.env - - CHAIN_STATE_KEEPER_L1_BATCH_COMMIT_DATA_GENERATOR_MODE=Validium - - VALIDIUM_MODE=1 + - CUSTOM_TOKEN_ADDRESS=${CUSTOM_TOKEN_ADDRESS} + + # zksync_validium: + # stdin_open: true + # tty: true + # image: matterlabs/local-node:hyperlocal + # depends_on: + # reth: + # condition: service_started + # postgres: + # condition: service_started + # zksync: + # condition: service_healthy + # zksync_custombase: # daisy chain + # condition: service_healthy + # healthcheck: + # test: curl --fail http://localhost:3071/health || exit 1 + # interval: 10s + # timeout: 5s + # retries: 200 + # start_period: 30s + # volumes: + # - shared_config:/etc/master_env + # - shared_tokens:/etc/tokens:ro + # ports: + # - 127.0.0.1:15300:3050 # JSON RPC HTTP port + # - 127.0.0.1:15301:3051 # JSON RPC WS port + # environment: + # - DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@postgres/prover_validium + # - DATABASE_URL=postgres://postgres:notsecurepassword@postgres/zksync_validium + # - ETH_CLIENT_WEB3_URL=http://reth:8545 + # - CHAIN_ETH_ZKSYNC_NETWORK_ID=273 + # - IN_DOCKER=true + # - MASTER_URL=http://zksync:3050 + # - MASTER_HEALTH_URL=http://zksync_custombase:3071/health ## daisy chain + # - MASTER_ENV_FILE=/etc/master_env/dev.env + # - CHAIN_STATE_KEEPER_L1_BATCH_COMMIT_DATA_GENERATOR_MODE=Validium + # - VALIDIUM_MODE=1 data-fetcher_main: platform: linux/amd64 @@ -183,15 +187,15 @@ services: - BLOCKCHAIN_RPC_URL=http://zksync_custombase:3050 restart: unless-stopped - data-fetcher_validium: - platform: linux/amd64 - image: "matterlabs/block-explorer-data-fetcher:latest" - environment: - - PORT=3040 - - LOG_LEVEL=verbose - - NODE_ENV=development - - BLOCKCHAIN_RPC_URL=http://zksync_validium:3050 - restart: unless-stopped + # data-fetcher_validium: + # platform: linux/amd64 + # image: "matterlabs/block-explorer-data-fetcher:latest" + # environment: + # - PORT=3040 + # - LOG_LEVEL=verbose + # - NODE_ENV=development + # - BLOCKCHAIN_RPC_URL=http://zksync_validium:3050 + # restart: unless-stopped @@ -228,21 +232,21 @@ services: restart: unless-stopped - worker_validium: - platform: linux/amd64 - image: "matterlabs/block-explorer-worker:latest" - environment: - - PORT=3001 - - LOG_LEVEL=verbose - - NODE_ENV=development - - DATABASE_HOST=postgres - - DATABASE_USER=postgres - - DATABASE_PASSWORD=notsecurepassword - - DATABASE_NAME=block-explorer_validium - - BLOCKCHAIN_RPC_URL=http://zksync_validium:3050 - - DATA_FETCHER_URL=http://data-fetcher_validium:3040 - - BATCHES_PROCESSING_POLLING_INTERVAL=1000 - restart: unless-stopped + # worker_validium: + # platform: linux/amd64 + # image: "matterlabs/block-explorer-worker:latest" + # environment: + # - PORT=3001 + # - LOG_LEVEL=verbose + # - NODE_ENV=development + # - DATABASE_HOST=postgres + # - DATABASE_USER=postgres + # - DATABASE_PASSWORD=notsecurepassword + # - DATABASE_NAME=block-explorer_validium + # - BLOCKCHAIN_RPC_URL=http://zksync_validium:3050 + # - DATA_FETCHER_URL=http://data-fetcher_validium:3040 + # - BATCHES_PROCESSING_POLLING_INTERVAL=1000 + # restart: unless-stopped api_main: @@ -255,7 +259,7 @@ services: - NODE_ENV=development - DATABASE_URL=postgres://postgres:notsecurepassword@postgres:5432/block-explorer ports: - - '127.0.0.1:15102:3020' + - '127.0.0.1:15103:3020' depends_on: - worker_main restart: unless-stopped @@ -277,20 +281,20 @@ services: restart: unless-stopped - api_validium: - platform: linux/amd64 - image: "matterlabs/block-explorer-api:latest" - environment: - - PORT=3020 - - METRICS_PORT=3005 - - LOG_LEVEL=verbose - - NODE_ENV=development - - DATABASE_URL=postgres://postgres:notsecurepassword@postgres:5432/block-explorer_validium - ports: - - '127.0.0.1:15302:3020' - depends_on: - - worker_validium - restart: unless-stopped + # api_validium: + # platform: linux/amd64 + # image: "matterlabs/block-explorer-api:latest" + # environment: + # - PORT=3020 + # - METRICS_PORT=3005 + # - LOG_LEVEL=verbose + # - NODE_ENV=development + # - DATABASE_URL=postgres://postgres:notsecurepassword@postgres:5432/block-explorer_validium + # ports: + # - '127.0.0.1:15302:3020' + # depends_on: + # - worker_validium + # restart: unless-stopped app: platform: linux/amd64 @@ -303,8 +307,8 @@ services: - '127.0.0.1:15005:3010' depends_on: - api_main - - api_custombase - - api_validium + # - api_custombase + # - api_validium restart: unless-stopped @@ -385,8 +389,8 @@ services: depends_on: zksync: condition: service_healthy - zksync_validium: - condition: service_healthy + # zksync_validium: + # condition: service_healthy zksync_custombase: condition: service_healthy image: ghcr.io/mm-zk/zksync_tools:latest @@ -400,3 +404,4 @@ volumes: reth: shared_config: shared_tokens: + shared_configs: # ✅ Shared volume for /configs