Skip to content

Commit 94351a2

Browse files
commit docs to branch
1 parent 4fe3c30 commit 94351a2

File tree

6 files changed

+615
-89
lines changed

6 files changed

+615
-89
lines changed

docs/cdk/how-to/migrate/7-8.md

Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
## Summary
2+
3+
In progress.
4+
5+
## Build Docker dev geth with fork 7
6+
7+
1. Clone `zkevm-contracts`, checkout branch `v4.0.0-fork.7`, and install.
8+
9+
```sh
10+
git clone https://github.com/0xPolygonHermez/zkevm-contracts
11+
cd zkevm-contracts/
12+
git checkout v4.0.0-fork.7
13+
npm install
14+
```
15+
16+
2. Edit the `docker/scripts/v2/deploy_parameters_docker.json` file to change the following:
17+
18+
```json
19+
"minDelayTimelock": 3600, -> "minDelayTimelock": 1,
20+
```
21+
22+
3. Edit the `docker/scripts/v2/create_rollup_parameters_docker.json` file and change `"consensusContract": "PolygonZkEVMEtrog",` to the following:
23+
24+
```json
25+
"consensusContract": "PolygonValidiumEtrog",
26+
```
27+
28+
And add the following parameter:
29+
30+
```json
31+
"dataAvailabilityProtocol": "PolygonDataCommittee",
32+
```
33+
34+
4. Run the following command:
35+
36+
```sh
37+
cp docker/scripts/v2/hardhat.example.paris hardhat.config.ts
38+
```
39+
40+
5. Edit the `docker/scripts/v2/deploy-docker.sh` file to add the following line:
41+
42+
```sh
43+
sudo chmod -R go+rxw docker/gethData before docker build -t hermeznetwork/geth-zkevm-contracts -f docker/Dockerfile .
44+
```
45+
46+
6. Uncomment the following lines from `deployment/v2/4_createRollup.ts`:
47+
48+
```sh
49+
// Setup data commitee to 0
50+
await (await polygonDataCommittee?.setupCommittee(0, [], "0x")).wait();
51+
```
52+
53+
7. Build the image:
54+
55+
```sh
56+
npm run docker:contracts
57+
```
58+
59+
8. Tag the image:
60+
61+
```sh
62+
docker image tag hermeznetwork/geth-zkevm-contracts hermeznetwork/geth-zkevm-contracts:test-upgrade-7
63+
```
64+
65+
## Build the genesis file for the node
66+
67+
1. Clone the `cdk-validium-node` repo, `cd` into it, and checkout the `v0.5.13+cdk.6` branch.
68+
69+
```sh
70+
git clone https://github.com/0xPolygon/cdk-validium-node
71+
cd cdk-validium-node
72+
git checkout v0.5.13+cdk.6
73+
```
74+
75+
2. Edit the `test/config/test.genesis.config.json` file with values in the output files in the `zkevm-contracts/docker/deploymentOutput` directory.
76+
77+
- `l1Config.polygonZkEVMAddress` ==> `rollupAddress` @ create_rollup_output.json
78+
- `l1Config.polygonRollupManagerAddress` ==> `polygonRollupManager` @ deploy_output.json
79+
- `l1Config.polTokenAddress` ==> `polTokenAddress` @ deploy_output.json
80+
- `l1Config.polygonZkEVMGlobalExitRootAddress` ==> `polygonZkEVMGlobalExitRootAddress` @ deploy_output.json
81+
- `rollupCreationBlockNumber` ==> `createRollupBlock` @ create_rollup_output.json
82+
- `rollupManagerCreationBlockNumber` ==> `deploymentBlockNumber` @ deploy_output.json
83+
- `root` ==> `root` @ genesis.json
84+
- `genesis` ==> `genesis` @ genesis.json
85+
86+
## Run the network using fork 7
87+
88+
1. Build the docker: `make build-docker`.
89+
90+
2. Edit `test/docker-compose.yml` to use the geth image from the first step, replace:
91+
92+
- `hermeznetwork/geth-cdk-validium-contracts:v0.0.4` => `hermeznetwork/geth-zkevm-contracts:test-upgrade-7`
93+
94+
3. Run all the stack: `cd test` then `make run`.
95+
96+
4. Send a bunch of txs using metamask:
97+
98+
- Import private key `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80` which has funds on L2 since genesis.
99+
- chainID is 1001
100+
- port is 8123
101+
102+
## Stop the sequencer in a clean state (no WIP batch) to avoid reorgs
103+
104+
This explained in more detail and orientated to a prod env [here](?)
105+
106+
1. Make sure you are on the test directory
107+
108+
2. Stop sequencer
109+
110+
```sh
111+
docker compose stop zkevm-sequencer && docker compose rm -f zkevm-sequencer`
112+
```
113+
114+
3. Connect to StateDB using:
115+
116+
```psql
117+
psql -h localhost -p 5432 -U state_user state_db
118+
```
119+
then introduce password `state_password`
120+
121+
4. Get WIP batch number:
122+
123+
```sql
124+
SELECT batch_num, wip FROM state.batch WHERE wip IS true;`
125+
```
126+
127+
!!! danger
128+
→ X. Write down somewhere the value of X, as it's gonna be used ina. bunch of places
129+
130+
5. Edit node config (`test/config/test.node.config.toml`):
131+
132+
6. Change: `Sequencer.Finalizer.HaltOnBatchNumber = X+1 # wip batch_num+1`
133+
134+
For a prod env you may want to tweak other values, see the linked doc above, for the local dev env defaults are ok -> waiting for link
135+
136+
7. Restart sequencer:
137+
138+
```sh
139+
docker compose up -d zkevm-sequencer`
140+
```
141+
142+
8. Check sequencer halted when reaching batch X+1
143+
144+
```sh
145+
docker logs -f zkevm-sequencer`
146+
```
147+
148+
9. Wait until all pending batches are virtualized and verified (X). Note that this could be checked on etherscan or using custom RPC endpoint
149+
150+
```sql
151+
SELECT batch_num FROM state.virtual_batch ORDER BY batch_num DESC LIMIT 1; → X
152+
SELECT batch_num FROM state.verified_batch ORDER BY batch_num DESC LIMIT 1; → X
153+
```
154+
155+
10. Stop all the node components:
156+
157+
```sh
158+
make stop-node && make stop-zkprover`
159+
```
160+
161+
## L1 interactions to upgrade CDK to fork 8
162+
163+
On zkevm-contracts, checkout develop:
164+
165+
```sh
166+
git stash && git checkout develop && npm i`
167+
```
168+
169+
### Deploy verifier
170+
171+
1. Run
172+
173+
```sh
174+
cp tools/deployVerifier/deploy_verifier_parameters.example tools/deployVerifier/deploy_verifier_parameters.json`
175+
```
176+
177+
2. Edit `tools/deployVerifier/deploy_verifier_parameters.json`:
178+
179+
- `realVerifier` ==> `false`
180+
181+
3. Run
182+
183+
```sh
184+
cp docker/scripts/v2/hardhat.example.paris hardhat.config.ts`
185+
```
186+
187+
4. Deploy verifier:
188+
189+
```sh
190+
npx hardhat run tools/deployVerifier/deployVerifier.ts --network localhost`
191+
```
192+
193+
5. Write the deployed address somewhere (you will only get that on the logs, something similar to `verifierContract deployed to: 0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f`)
194+
195+
!!! warning
196+
On production this step should be skipped, as the fork 8 verifier should already be deployed (since it's already being used by Hermez)
197+
198+
### Add rollup type
199+
200+
1. Edit `tools/addRollupType/add_rollup_type.json` using values from the output files @ `docker/deploymentOutputs`
201+
202+
- `consensusContract` ==> `PolygonValidiumEtrog`
203+
- `polygonRollupManagerAddress` ==> `polygonRollupManager` @ deploy_output.json
204+
- `polygonZkEVMBridgeAddress` ==> `polygonZkEVMBridgeAddress` @ deploy_output.json
205+
- `polygonZkEVMGlobalExitRootAddress` ==> `polygonZkEVMGlobalExitRootAddress` @ deploy_output.json
206+
- `polTokenAddress` ==> `polTokenAddress` @ deploy_output.json
207+
- `verifierAddress` ==> value outputed on the logs of previous step
208+
- `timelockDelay` ==> `0`
209+
210+
2. Run
211+
212+
```sh
213+
npx hardhat run tools/addRollupType/addRollupType.ts --network localhost
214+
```
215+
216+
should output: Added new Rollup Type deployed
217+
218+
3. Write the type ID (you will only get that on the logs, something similar to `type: 2`,) THIS IS INCORRECT, LoL. Need a better way to detect the correct typeID
219+
220+
!!! warning
221+
The procedure is not the same when using timelocks!
222+
223+
### Update rollup
224+
225+
1. Run
226+
227+
```sh
228+
cp tools/updateRollup/updateRollup.json.example tools/updateRollup/updateRollup.json`
229+
```
230+
231+
2. Edit `tools/updateRollup/updateRollup.json` using values from the output files @ docker/deploymentOutputs:
232+
233+
- `rollupAddress` ==> `rollupAddress` @ create_rollup_output.json
234+
- `newRollupTypeID` ==> value outputed on the logs of previous step (put 2 if running with docker as per the instructions)
235+
- `polygonRollupManagerAddress` ==> `polygonRollupManager` @ deploy_output.json
236+
- `timelockDelay` ==> `minDelayTimelock` @ docker/scripts/v2/deploy_parameters_docker.json
237+
- (ADD) `timelockAddress` ==> `timelockContractAddress` @ deploy_output.json
238+
239+
#### With timelock (NOT TESTED)
240+
241+
1. Run
242+
243+
```sh
244+
npx hardhat run tools/updateRollup/updateRollup.ts --network localhost`
245+
```
246+
247+
2. Create `tools/updateRollup/executeUpdate.ts` and `tools/updateRollup/scheduleUpdate.ts`
248+
249+
3. Run
250+
251+
```sh
252+
npx hardhat run tools/updateRollup/scheduleUpdate.ts --network localhost`
253+
```
254+
255+
4. Wait for the timelock delay to be elapsed (just one second )
256+
257+
5. Run
258+
259+
```sh
260+
npx hardhat run tools/updateRollup/executeUpdate.ts --network localhost`
261+
```
262+
263+
#### Without timelock
264+
265+
1. Create `tools/updateRollup/noTimelock.ts`
266+
267+
2. Run
268+
269+
```sh
270+
npx hardhat run tools/updateRollup/noTimelock.ts --network localhost`
271+
```
272+
273+
3. Missing to implement something to verify that the tx went through…??
274+
275+
!!! warning
276+
After upgrade, the dataAvailabilityProtocol of the Validium contract is lost (set to 0x000…0), needed to set it up again using the script at the bottom of the doc
277+
278+
## Upgrade node to fork 8
279+
280+
!!! tip
281+
It is recommended to have log level set to debug until the upgrade is confirmed to be succesful
282+
283+
1. Make sure you are on the root directory of `cdk-validium-node`
284+
285+
2. Backup the genesis file so no need to re-write it:
286+
287+
```sh
288+
cp test/config/test.genesis.config.json /tmp`
289+
```
290+
291+
3. Update node version:
292+
293+
```sh
294+
git stash && git checkout v0.6.2+cdk`
295+
```
296+
297+
4. Build docker (on root directory):
298+
299+
```sh
300+
make build-docker`
301+
```
302+
303+
5. Backup genesis file:
304+
305+
```sh
306+
mv /tmp/test.genesis.config.json test/config`
307+
```
308+
309+
6. Run the synchronizer:
310+
311+
```sh
312+
cd test && make run-zkprover && docker compose up -d zkevm-sync`
313+
```
314+
315+
7. Connect to StateDB using:
316+
317+
```sql
318+
psql -h localhost -p 5432 -U state_user state_db,
319+
```
320+
then introduce password `state_password`
321+
322+
8. Query the registered fork IDs:
323+
324+
```sql
325+
SELECT * FROM state.fork_id;
326+
```
327+
You should get two rows, one with 7 and the other with 8 (it may take a bit)
328+
329+
9. Start the rest of the node components:
330+
331+
```sh
332+
make run-node
333+
```
334+
335+
10. Send a bunch of transactions using metamask
336+
337+
11. Wait until new batches are virtualized and verified (> X). Note that this could be checked on etherscan or using custom RPC endpoint
338+
339+
```sql
340+
SELECT batch_num FROM state.batch ORDER BY batch_num DESC LIMIT 1;> X
341+
SELECT batch_num FROM state.virtual_batch ORDER BY batch_num DESC LIMIT 1;> X
342+
SELECT batch_num FROM state.verified_batch ORDER BY batch_num DESC LIMIT 1;> X
343+
```

0 commit comments

Comments
 (0)