Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🩹 Solve issues for successfully running a local hyperchain (matt…
…er-labs#893) ## What ❔ This PR solves the following issues encountered when trying to run a hyperchain locally, according to [this quickstart tutorial](https://zkstack.io/quickstart#deploying-and-running-locally): 1. TypeScript not compiling in Remote Server. This was due to the `yarn.lock` file not being locked when installing the dependencies. The `zk` and `zk stack init` scripts both run `yarn` at some point, but without the `--frozen-lockfile`, meaning each machine would modify the `yarn.lock` file and the dependencies would be slightly different. In the Mac machine, this didn't cause any issues, but in the Ubuntu it made the TypeScript compiler fail. The solution was to run `yarn install --frozen-lockfile` in the `zk` and `zk` stack init scripts, which is added in [this commit](ffarall@a936768). Below, the compile error: ``` scripts/utils.ts:201:93 - error TS2339: Property ‘zksolc’ does not exist on type ‘HardhatConfig’. 201 const url = getZksolcUrl(“https://github.com/matter-labs/zksolc-prerelease”, hre. config.zksolc.version); ``` 2. After setting up a new hyperchain for the first time with `zk stack init` (let’s call it `my-hyperchain`) if you execute `zk clean —-all` it deletes `my-hyperchain.env` (among others). However, as soon as you run another `zk` command, the file is regenerated with the old content. For example, running `zk down`, regenerates the `my-hyperchain.env` that was just deleted. This is not really an issue, but it is a bit confusing/annoying. It is solved by also having `zk clean` delete the `.current` file, as done in [this commit](ffarall@a912b2b). 3. When executing the server, which is Rust code running in the local machine, the script tries to use `sqlx` to access the PostgreSQL database (which was running in a docker container named `postgres`), using the `URL DATABASE_URL=postgres://postgres:notsecurepassword@postgres:5432/zksync_local`. That is the environment variable that is autogenerated in `hyperchain_wizards.ts`, in this line: ```typescript wrapEnvModify('DATABASE_URL', 'postgres://postgres:notsecurepassword@postgres:5432/zksync_local'); ``` The problem is that the local machine cannot resolve the path `postgres:5432` by name, as it does not have the IP of the `postgres` container. That is why it could not find the database. Luckily, the container is forwarding the ports, so changing `hyperchain_wizards.ts` to generate the env variable as `DATABASE_URL=postgres://postgres:notsecurepassword@postgres:5432/zksync_local` solves the problem. There is a similar issue when the server tries to find `geth:8545`, the docker container running the Ethereum node. Both issues are solved in [this commit](ffarall@c6150ce). Interestingly enough, manually modifying the `DATABASE_URL` env variable after executing `zk stack init` would not work, as running `zk server` again would still use the autogenerated value. This is because some env variables are duplicated in the `my-hyperchain.env` and `.init.env`, and this is the case of `DATABASE_URL`. When loading the environment, `my-hyperchain.env` is loaded first, and then `.init.env` overwrites such variables. Manually modifying the variables on `.init.env` however, works. 4. Running `zk stack init` after doing `zk down` for stopping the docker containers doesn't boot the same containers again, but other ones. Running `zk up --docker-file` has a bug that interprets `--docker-file` as a boolean flag. This is fixed in [this commit](ffarall@13ddeee), which makes it possible to restart the containers that were just deleted with `zk down`, by running `zk up --docker-file ./docker-compose-zkstack-common.yml`. It is not a definitive fix for the issue, but improves the situation. ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. _(Doesn't apply, it has been tested to work manually, which it didn't before)_ - [ ] Documentation comments have been added / updated. _(Doesn't apply, no comments needed updating)_ - [x] Code has been formatted via `zk fmt` and `zk lint`. - [x] Spellcheck has been run via `zk spellcheck`. --------- Co-authored-by: Fedor Sakharov <[email protected]>
- Loading branch information