forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
335 lines (226 loc) · 8.13 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
export CI_PIPELINE_ID ?= $(shell date +"%Y-%m-%d-%s")
export SERVER_DOCKER_IMAGE ?=matterlabs/server:$(IMAGE_TAG)
export PROVER_DOCKER_IMAGE ?=matterlabs/prover:$(IMAGE_TAG)
export NGINX_DOCKER_IMAGE ?= matterlabs/nginx:$(IMAGE_TAG)
export GETH_DOCKER_IMAGE ?= matterlabs/geth:latest
export CI_DOCKER_IMAGE ?= matterlabs/ci
# Getting started
# Check and change environment (listed here for autocomplete and documentation only)
env:
# Get everything up and running for the first time
init:
@bin/init
yarn:
@cd js/client && yarn
@cd js/explorer && yarn
@cd js/zksync.js && yarn
@cd contracts && yarn
@cd js/tests && yarn
# Helpers
# This will prompt user to confirm an action on production environment
confirm_action:
@bin/.confirm_action
rust-checks:
cargo fmt -- --check
@find core/ -type f -name "*.rs" -exec touch {} +
cargo clippy --tests --benches -- -D warnings
# Database tools
sql = psql "$(DATABASE_URL)" -c
db-test:
@bin/db-test.sh reset
db-test-no-reset:
@bin/db-test.sh no-reset
db-setup:
@bin/db-setup
db-insert-contract:
@bin/db-insert-contract.sh
db-reset: confirm_action db-wait db-drop db-setup db-insert-contract
@echo database is ready
db-migrate: confirm_action
@cd core/storage && diesel migration run
db-drop: confirm_action
@# this is used to clear the produciton db; cannot do `diesel database reset` because we don't own the db
@echo DATABASE_URL=$(DATABASE_URL)
@$(sql) 'DROP OWNED BY CURRENT_USER CASCADE' || \
{ $(sql) 'DROP SCHEMA IF EXISTS public CASCADE' && $(sql)'CREATE SCHEMA public'; }
db-wait:
@bin/db-wait
genesis: confirm_action
@bin/genesis.sh
# Frontend clients
client:
@cd js/client && yarn serve
explorer:
@cd js/explorer && yarn serve
dist-client:
@cd js/client && yarn build
dist-explorer:
@cd js/explorer && yarn build
image-nginx: dist-client dist-explorer
@docker build -t "${NGINX_DOCKER_IMAGE}" -f ./docker/nginx/Dockerfile .
push-image-nginx: image-nginx
docker push "${NGINX_DOCKER_IMAGE}"
image-ci:
@docker build -t "${CI_DOCKER_IMAGE}" -f ./docker/ci/Dockerfile .
push-image-ci:
docker push "${CI_DOCKER_IMAGE}"
# Using RUST+Linux docker image (ekidd/rust-musl-builder) to build for Linux. More at https://github.com/emk/rust-musl-builder
docker-options = --rm -v $(shell pwd):/home/rust/src -v cargo-git:/home/rust/.cargo/git -v cargo-registry:/home/rust/.cargo/registry --env-file $(ZKSYNC_HOME)/etc/env/$(ZKSYNC_ENV).env
rust-musl-builder = @docker run $(docker-options) ekidd/rust-musl-builder
# Rust: main stuff
dummy-prover:
cargo run --bin dummy_prover
prover:
@cargo run --release --bin prover
server:
@cargo run --bin server --release
sandbox:
@cargo run --bin sandbox
# See more more at https://github.com/emk/rust-musl-builder#caching-builds
build-target:
$(rust-musl-builder) sudo chown -R rust:rust /home/rust/.cargo/git /home/rust/.cargo/registry
$(rust-musl-builder) cargo build --release
clean-target:
$(rust-musl-builder) cargo clean
image-server: build-target
@docker build -t "${SERVER_DOCKER_IMAGE}" -f ./docker/server/Dockerfile .
image-prover: build-target
@docker build -t "${PROVER_DOCKER_IMAGE}" -f ./docker/prover/Dockerfile .
image-rust: image-server image-prover
push-image-rust: image-rust
docker push "${SERVER_DOCKER_IMAGE}"
docker push "${PROVER_DOCKER_IMAGE}"
# Contracts
deploy-contracts: confirm_action build-contracts
@bin/deploy-contracts.sh
test-contracts: confirm_action build-contracts
@bin/contracts-test.sh
build-contracts: confirm_action flatten
@bin/prepare-test-contracts.sh
@cd contracts && yarn build
define flatten_file
@cd contracts && scripts/solidityFlattener.pl --mainsol $(1) --outputsol flat/$(1);
endef
# Flatten contract source
flatten: prepare-contracts
@mkdir -p contracts/flat
$(call flatten_file,Franklin.sol)
$(call flatten_file,Governance.sol)
$(call flatten_file,PriorityQueue.sol)
$(call flatten_file,Verifier.sol)
gen-keys-if-not-present:
test -f ${KEY_DIR}/${BLOCK_SIZE_CHUNKS}/${ACCOUNT_TREE_DEPTH}/zksync_pk.key || gen-keys
prepare-contracts:
@cp ${KEY_DIR}/${BLOCK_SIZE_CHUNKS}/${ACCOUNT_TREE_DEPTH}/VerificationKey.sol contracts/contracts/VerificationKey.sol || (echo "please run gen-keys" && exit 1)
@cp ${KEY_DIR}/${BLOCK_SIZE_CHUNKS}/${ACCOUNT_TREE_DEPTH}/VerificationKeyExit.sol contracts/contracts/VerificationKeyExit.sol || (echo "please run gen-keys" && exit 1)
# testing
ci-check:
@ci-check.sh
loadtest: confirm_action
@bin/loadtest.sh
integration-testkit: build-contracts
cargo run --bin testkit --release
cargo run --bin exodus_test --release
itest: # contracts simple integration tests
@bin/prepare-test-contracts.sh
@cd contracts && yarn itest
utest: # contracts unit tests
@bin/prepare-test-contracts.sh
@cd contracts && yarn unit-test
integration-simple:
@cd js/tests && yarn && yarn simple
integration-full-exit:
@cd js/tests && yarn && yarn full-exit
price:
@node contracts/scripts/check-price.js
circuit-tests:
cargo test --no-fail-fast --release -p circuit -- --ignored --test-threads 1
prover-tests:
f cargo test -p prover --release -- --ignored
# Loadtest
run-loadtest: confirm_action
@cd js/franklin_lib && yarn loadtest
prepare-loadtest: confirm_action
@node js/loadtest/loadtest.js prepare
rescue: confirm_action
@node js/loadtest/rescue.js
deposit: confirm_action
@node contracts/scripts/deposit.js
# Devops: main
# (Re)deploy contracts and database
redeploy: confirm_action stop deploy-contracts db-insert-contract
init-deploy: confirm_action deploy-contracts db-insert-contract
dockerhub-push: image-nginx image-rust
docker push "${NGINX_DOCKER_IMAGE}"
apply-kubeconfig:
@bin/k8s-apply
update-rust: push-image-rust apply-kubeconfig
@kubectl patch deployment $(ZKSYNC_ENV)-server -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"
@kubectl patch deployment $(ZKSYNC_ENV)-prover -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"
update-nginx: push-image-nginx apply-kubeconfig
@kubectl patch deployment $(ZKSYNC_ENV)-nginx -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"
update-all: update-rust update-nginx apply-kubeconfig
start-kube: apply-kubeconfig
ifeq (dev,$(ZKSYNC_ENV))
start: image-nginx image-rust start-local
else
start: apply-kubeconfig start-prover start-server start-nginx
endif
ifeq (dev,$(ZKSYNC_ENV))
stop:
else ifeq (ci,$(ZKSYNC_ENV))
stop:
else
stop: confirm_action stop-prover stop-server stop-nginx
endif
restart: stop start
start-prover:
@bin/kube scale deployments/$(ZKSYNC_ENV)-prover --replicas=1
start-nginx:
@bin/kube scale deployments/$(ZKSYNC_ENV)-nginx --replicas=1
start-server:
@bin/kube scale deployments/$(ZKSYNC_ENV)-server --replicas=1
stop-prover:
@bin/kube scale deployments/$(ZKSYNC_ENV)-prover --replicas=0
stop-server:
@bin/kube scale deployments/$(ZKSYNC_ENV)-server --replicas=0
stop-nginx:
@bin/kube scale deployments/$(ZKSYNC_ENV)-nginx --replicas=0
# Monitoring
status:
@curl $(API_SERVER)/api/v0.1/status; echo
log-server:
kubectl logs -f deployments/$(ZKSYNC_ENV)-server
log-prover:
kubectl logs --tail 300 -f deployments/$(ZKSYNC_ENV)-prover
# Kubernetes: monitoring shortcuts
pods:
kubectl get pods -o wide | grep -v Pending
nodes:
kubectl get nodes -o wide
# Dev environment
dev-up:
@docker-compose up -d postgres geth
@docker-compose up -d tesseracts
dev-down:
@docker-compose stop tesseracts
@docker-compose stop postgres geth
geth-up: geth
@docker-compose up geth
# Auxillary docker containers for dev environment (usually no need to build, just use images from dockerhub)
dev-build-geth:
@docker build -t "${GETH_DOCKER_IMAGE}" ./docker/geth
dev-push-geth:
@docker push "${GETH_DOCKER_IMAGE}"
# Key generator
make-keys:
@cargo run -p key_generator --release --bin key_generator
# Data Restore
data-restore-setup-and-run: data-restore-build data-restore-restart
data-restore-db-prepare: confirm_action db-reset
data-restore-build:
@cargo build -p data_restore --release --bin data_restore
data-restore-restart: confirm_action data-restore-db-prepare
@cargo run --bin data_restore --release -- --genesis
data-restore-continue:
@cargo run --bin data_restore --release -- --continue