-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## What ❔ * Fixing docker build and scripts for the local node/setup. ## Why ❔ * This will allow local node to work again - which is crucial before the bridgehub udpate. * This PR is only fixing it in the 'main' branch - there will be a followup PR to the bridgehub branch coming later.
- Loading branch information
Showing
8 changed files
with
168 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# local-node docker | ||
|
||
This docker container is used for 'local-node' - the fast way to bring up the fully working system (similar to what you | ||
get by running `zk init`). | ||
|
||
You can find more instructions (and docker compose files) in [https://github.com/matter-labs/local-setup] | ||
|
||
This directory is more focused on 'creating' the image rather than using it. | ||
|
||
## Testing & debugging | ||
|
||
To build the node locally run: | ||
|
||
```shell | ||
zk docker build local-node --custom-tag "my_custom_local_tag" | ||
``` | ||
|
||
Then you can quickly test it locally (assuming that you already have a postgres and reth docker running): | ||
|
||
```shell | ||
docker run --network host --env-file=docker-env.list --entrypoint /bin/bash -it --name my_local_zksync matterlabs/local-node:my_custom_local_tag | ||
``` | ||
|
||
The `docker-env.list` should contain environment variables: | ||
|
||
``` | ||
DATABASE_PROVER_URL=postgres://postgres:notsecurepassword@localhost/prover_local | ||
DATABASE_URL=postgres://postgres:notsecurepassword@localhost/zksync_local | ||
ETH_CLIENT_WEB3_URL=http://127.0.0.1:8545 | ||
``` | ||
|
||
The command above will start it in the 'bash' mode - where you can look around and modify things. If you want to start | ||
it with the default entrypoint - simply remove the '--entrypoint /bin/bash' from the command above. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,93 @@ | ||
#!/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. | ||
update_config() { | ||
# Assigning arguments to readable variable names | ||
local file="$1" | ||
local parameter="$2" | ||
local new_value="$3" | ||
local pattern="^${parameter} =.*$" | ||
|
||
# Check if the parameter exists in the file | ||
if grep -q "$pattern" "$file"; then | ||
# The parameter exists, so replace its value | ||
sed -i "s!$pattern!${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 | ||
} | ||
|
||
|
||
# wait till db service is ready | ||
until psql ${DATABASE_URL%/*} -c '\q'; do | ||
>&2 echo "Postgres is unavailable - sleeping" | ||
sleep 5 | ||
done | ||
|
||
# ensure database initialization | ||
if ! psql $DATABASE_URL -c '\q' 2>/dev/null; | ||
then | ||
echo "Initialing local environment" | ||
psql ${DATABASE_URL%/*} -c "create database ${DATABASE_URL##*/}" | ||
find /migrations -name "*up.sql" | sort | xargs printf -- ' -f %s' | xargs -t psql $DATABASE_URL | ||
|
||
cd /infrastructure/zk | ||
# Compile configs | ||
yarn start config compile | ||
# 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" | ||
|
||
# Override values for database URL and eth client in the toml config files | ||
# so they will be taken into account | ||
sed -i 's!^database_url=.*$!database_url="'"$DATABASE_URL"'"!' /etc/env/base/private.toml | ||
sed -i 's!^web3_url=.*$!web3_url="'"$ETH_CLIENT_WEB3_URL"'"!' /etc/env/base/eth_client.toml | ||
sed -i 's!^path=.*$!path="/var/lib/zksync/data"!' /etc/env/base/database.toml | ||
sed -i 's!^state_keeper_db_path=.*$!state_keeper_db_path="/var/lib/zksync/data/state_keeper"!' /etc/env/base/database.toml | ||
sed -i 's!^merkle_tree_backup_path=.*$!merkle_tree_backup_path="/var/lib/zksync/data/backups"!' /etc/env/base/database.toml | ||
if [ -f "$INIT_FILE" ]; then | ||
echo "Initialization was done in the past - simply starting server" | ||
else | ||
echo "Initialing local environment" | ||
|
||
# Switch zksolc compiler source from docker to binary | ||
sed -i "s!'docker'!'binary'!" /contracts/l2-contracts/hardhat.config.ts | ||
mkdir -p /var/lib/zksync/data | ||
|
||
# Compile configs again (with changed values) | ||
yarn start config compile | ||
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" | ||
|
||
zk config compile | ||
|
||
zk db reset | ||
|
||
# Perform initialization | ||
yarn start lightweight-init | ||
yarn start f yarn --cwd /infrastructure/local-setup-preparation start | ||
|
||
# Return to the root directory | ||
cd / | ||
zk contract deploy --only-verifier | ||
zk f zksync_server --genesis | ||
zk run deploy-erc20 dev # (created etc/tokens/localhost) | ||
zk contract deploy # (deploys rest of stuff) | ||
|
||
zk contract initialize-validator | ||
|
||
zk contract deploy-l2 | ||
zk contract initialize-governance | ||
|
||
zk f yarn --cwd /infrastructure/local-setup-preparation start | ||
|
||
# Create init file. | ||
echo "System initialized. Please remove this file if you want to reset the system" > $INIT_FILE | ||
|
||
fi | ||
|
||
# start server | ||
source /etc/env/dev.env | ||
source /etc/env/.init.env | ||
exec zksync_server | ||
zk f zksync_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters