From 6468e97d63625522c3f78349b0b82aa4e9ff1f5d Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 17 Apr 2024 11:06:41 +0200 Subject: [PATCH 1/2] basic setup --- README.md | 15 +++---- clear.sh | 3 +- docker-compose.yml | 57 +++++++++++++------------ reth_chaindata/reth_config | 86 ++++++++++++++++++++++++++++++++++++++ start.sh | 4 +- 5 files changed, 123 insertions(+), 42 deletions(-) create mode 100644 reth_chaindata/reth_config diff --git a/README.md b/README.md index 6903980..dd0cb2c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This repository contains the tooling necessary to bootstrap zkSync locally. +By default, it doesn't use any docker volumes, so all the data is lost when docker is stopped. + ## Dependencies To run zkSync locally, you must have `docker compose` and `Docker` installed on your machine. @@ -11,12 +13,12 @@ To run zkSync locally, you must have `docker compose` and `Docker` installed on To bootstrap zkSync locally, just run: ``` -> docker compose up +> ./start.sh ``` This command will bootstrap three docker containers: - Postgres (used as the database for zkSync). -- Local Geth node (used as L1 for zkSync). +- Local Reth node (used as L1 for zkSync). - zkSync server itself. By default, the HTTP JSON-RPC API will run on port `3050`, while WS API will run on port `3051`. @@ -28,16 +30,9 @@ By default, the HTTP JSON-RPC API will run on port `3050`, while WS API will run To reset the zkSync state, just run: ``` -> docker compose down --volumes +> ./clear.sh ``` -This command will stop and remove all of the pods and named volumes that contains the network state - -After this, you can run again: - -``` -> docker compose up -``` ## Rich wallets diff --git a/clear.sh b/clear.sh index febd3f9..fbdaded 100755 --- a/clear.sh +++ b/clear.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash -docker-compose down --volumes -docker-compose pull +docker compose down --volumes diff --git a/docker-compose.yml b/docker-compose.yml index 9a689d0..a498398 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,43 +1,46 @@ version: '3.2' services: - geth: - image: "matterlabs/geth:latest" - logging: - driver: none - ports: - - "8545:8545" - - "8546:8546" + reth: + restart: always + image: "ghcr.io/paradigmxyz/reth:v0.2.0-beta.2" volumes: - - geth:/var/lib/geth/data + - type: bind + source: ./reth_chaindata + target: /chaindata + + command: node --dev --datadir /rethdata --http --http.addr 0.0.0.0 --http.port 8545 --dev.block-time 300ms --chain /chaindata/reth_config + environment: + - RUST_LOG=warn + ports: + - 127.0.0.1:8545:8545 postgres: - image: "postgres:12" - logging: - driver: none - volumes: - - postgres:/var/lib/postgresql/data + image: "postgres:14" + command: postgres -c 'max_connections=200' + ports: + - 127.0.0.1:5432:5432 environment: - - POSTGRES_HOST_AUTH_METHOD=trust + # We bind only to 127.0.0.1, so setting insecure password is acceptable here + - POSTGRES_PASSWORD=notsecurepassword zksync: stdin_open: true tty: true - image: matterlabs/local-node:latest2.0 + image: matterlabs/local-node:mmzk_0416-1 + healthcheck: + test: curl --fail http://localhost:3071/health || exit 1 + interval: 10s + timeout: 5s + retries: 20 + start_period: 30s depends_on: - - geth + - reth - postgres ports: - "3050:3050" # JSON RPC HTTP port - "3051:3051" # JSON RPC WS port - volumes: - # Configs folder bind - - zksync-config:/etc/env/ - # Storage folder bind - - zksync-data:/var/lib/zksync/data environment: - - DATABASE_URL=postgres://postgres@postgres/zksync_local - - ETH_CLIENT_WEB3_URL=http://geth:8545 + - DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@postgres/prover_local + - DATABASE_URL=postgres://postgres:notsecurepassword@postgres/zksync_local + - ETH_CLIENT_WEB3_URL=http://reth:8545 volumes: - geth: - postgres: - zksync-config: - zksync-data: + reth: diff --git a/reth_chaindata/reth_config b/reth_chaindata/reth_config new file mode 100644 index 0000000..8c4a53f --- /dev/null +++ b/reth_chaindata/reth_config @@ -0,0 +1,86 @@ +{ + "config": { + "chainId": 9, + "homesteadBlock": 0, + "eip150Block": 0, + "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "eip155Block": 0, + "eip158Block": 0, + "daoForkBlock": 0, + "frontierBlock": 0, + "byzantiumBlock": 0, + "constantinopleBlock": 0, + "petersburgBlock": 0, + "muirGlacierBlock": 0, + "istanbulBlock": 0, + "berlinBlock": 0, + "londonBlock": 0, + "terminalTotalDifficulty": "0x0", + "mergeNetsplitBlock": 0, + "shanghaiTime": 0, + "cancunTime": 0, + "clique": { + "period": 0, + "epoch": 30000 + } + }, + "nonce": "0x0", + "timestamp": "0x5ca9158b", + "gasLimit": "0x1c9c380", + "difficulty": "0x0", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "alloc": { + "0000000000000000000000000000000000000000": { + "balance": "0x1" + }, + "8a91dc2d28b689474298d91899f0c1baf62cb85b": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "de03a0b5963f75f1c8485b355ff6d30f3093bde7": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "52312AD6f01657413b2eaE9287f6B9ADaD93D5FE": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "36615Cf349d7F6344891B1e7CA7C72883F5dc049": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "a61464658AfeAf65CccaaFD3a512b69A83B77618": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "0D43eB5B8a47bA8900d84AA36656c92024e9772e": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "A13c10C0D5bd6f79041B9835c63f91de35A15883": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "8002cD98Cfb563492A6fB3E7C8243b7B9Ad4cc92": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "4F9133D1d3F50011A6859807C837bdCB31Aaab13": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "bd29A1B981925B94eEc5c4F1125AF02a2Ec4d1cA": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "edB6F5B4aab3dD95C7806Af42881FF12BE7e9daa": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "e706e60ab5Dc512C36A4646D719b889F398cbBcB": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "E90E12261CCb0F3F7976Ae611A29e84a6A85f424": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + }, + "e706e60ab5dc512c36a4646d719b889f398cbbcb": { + "balance": "0x4B3B4CA85A86C47A098A224000000000" + } + }, + "number": "0x0", + "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "baseFeePerGas": 1, + "excessBlobGas": "0x0", + "blobGasUsed": 0 +} \ No newline at end of file diff --git a/start.sh b/start.sh index a59b045..39a9706 100755 --- a/start.sh +++ b/start.sh @@ -1,4 +1,2 @@ #!/usr/bin/env bash - -docker-compose up - +docker compose up -d From d90c36c49e0f76493be5cfd0343ca75e22bcb1c6 Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 17 Apr 2024 11:50:44 +0200 Subject: [PATCH 2/2] support custom names --- docker-compose.yml | 7 +++---- start.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a498398..44b215a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.2' services: reth: restart: always @@ -24,7 +23,7 @@ services: zksync: stdin_open: true tty: true - image: matterlabs/local-node:mmzk_0416-1 + image: matterlabs/local-node:${INSTANCE_TYPE} healthcheck: test: curl --fail http://localhost:3071/health || exit 1 interval: 10s @@ -35,8 +34,8 @@ services: - reth - postgres ports: - - "3050:3050" # JSON RPC HTTP port - - "3051:3051" # JSON RPC WS port + - 127.0.0.1:3050:3050 # JSON RPC HTTP port + - 127.0.0.1:3051:3051 # JSON RPC WS port environment: - DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@postgres/prover_local - DATABASE_URL=postgres://postgres:notsecurepassword@postgres/zksync_local diff --git a/start.sh b/start.sh index 39a9706..2af1be1 100755 --- a/start.sh +++ b/start.sh @@ -1,2 +1,32 @@ #!/usr/bin/env bash +# docker compose up -d + +# usage: ./start.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. + +INSTANCE_TYPE=${1:-latest2.0} + +export INSTANCE_TYPE=$INSTANCE_TYPE docker compose up -d + + +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 +} + + +# Loop until all services are healthy +while ! check_all_services_healthy; do + echo "Services are not yet healthy, waiting..." + sleep 10 # Check every 10 seconds +done + +echo "All services are healthy!" \ No newline at end of file