Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopting local node to use reth #15

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`.
Expand All @@ -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

Expand Down
3 changes: 1 addition & 2 deletions clear.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env bash

docker-compose down --volumes
docker-compose pull
docker compose down --volumes
62 changes: 32 additions & 30 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
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:${INSTANCE_TYPE}
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
- 127.0.0.1:3050:3050 # JSON RPC HTTP port
- 127.0.0.1:3051:3051 # JSON RPC WS port
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:
86 changes: 86 additions & 0 deletions reth_chaindata/reth_config
Original file line number Diff line number Diff line change
@@ -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
}
30 changes: 29 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
#!/usr/bin/env bash
# docker compose up -d

docker-compose up
# 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!"
Loading