forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 217
/
Makefile
296 lines (239 loc) · 11.9 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
DOCKERCOMPOSE := docker-compose -f docker-compose.yml
DOCKERCOMPOSEAPPSEQ := zkevm-sequencer
DOCKERCOMPOSEAPPAGG := zkevm-aggregator
DOCKERCOMPOSEAPPRPC := zkevm-json-rpc
DOCKERCOMPOSEAPPSYNC := zkevm-sync
DOCKERCOMPOSEAPPBROADCAST := zkevm-broadcast
DOCKERCOMPOSEDB := zkevm-db
DOCKERCOMPOSENETWORK := zkevm-mock-l1-network
DOCKERCOMPOSEPROVER := zkevm-mock-prover
DOCKERCOMPOSEEXPLORER := zkevm-explorer
DOCKERCOMPOSEEXPLORERDB := zkevm-explorer-db
DOCKERCOMPOSEEXPLORERRPC := zkevm-explorer-json-rpc
DOCKERCOMPOSEZKPROVER := zkevm-prover
RUNDB := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEDB)
RUNSEQUENCER := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPSEQ)
RUNAGGREGATOR := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPAGG)
RUNJSONRPC := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPRPC)
RUNSYNC := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPSYNC)
RUNBROADCAST := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEAPPBROADCAST)
RUNL1NETWORK := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSENETWORK)
RUNPROVER := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEPROVER)
RUNEXPLORER := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEEXPLORER)
RUNEXPLORERDB := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEEXPLORERDB)
RUNEXPLORERJSONRPC := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEEXPLORERRPC)
RUNZKPROVER := $(DOCKERCOMPOSE) up -d $(DOCKERCOMPOSEZKPROVER)
RUN := $(DOCKERCOMPOSE) up -d
STOPDB := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEDB) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEDB)
STOPSEQUENCER := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPSEQ) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPSEQ)
STOPAGGREGATOR := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPAGG) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPAGG)
STOPJSONRPC := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPRPC) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPRPC)
STOPSYNC := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPSYNC) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPSYNC)
STOPBROADCAST := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEAPPBROADCAST) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEAPPBROADCAST)
STOPNETWORK := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSENETWORK) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSENETWORK)
STOPPROVER := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEPROVER) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEPROVER)
STOPEXPLORER := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEEXPLORER) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEEXPLORER)
STOPEXPLORERDB := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEEXPLORERDB) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEEXPLORERDB)
STOPEXPLORERRPC := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEEXPLORERRPC) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEEXPLORERRPC)
STOPZKPROVER := $(DOCKERCOMPOSE) stop $(DOCKERCOMPOSEZKPROVER) && $(DOCKERCOMPOSE) rm -f $(DOCKERCOMPOSEZKPROVER)
STOP := $(DOCKERCOMPOSE) down --remove-orphans
VERSION := $(shell git describe --tags --always)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z)
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
GOBASE := $(shell pwd)
GOBIN := $(GOBASE)/dist
GOENVVARS := GOBIN=$(GOBIN)
GOBINARY := zkevm-node
GOCMD := $(GOBASE)/cmd
LINT := $$(go env GOPATH)/bin/golangci-lint run
BUILD := $(GOENVVARS) go build $(LDFLAGS) -o $(GOBIN)/$(GOBINARY) $(GOCMD)
.PHONY: build
build: ## Builds the binary locally into ./dist
$(BUILD)
.PHONY: build-docker
build-docker: ## Builds a docker image with the node binary
docker build -t zkevm-node -f ./Dockerfile .
.PHONY: build-docker-nc
build-docker-nc: ## Builds a docker image with the node binary - but without build cache
docker build --no-cache=true -t zkevm-node -f ./Dockerfile .
.PHONY: test
test: compile-scs ## Runs only short tests without checking race conditions
$(STOPDB)
$(STOPZKPROVER)
$(RUNDB); sleep 5
$(RUNZKPROVER); sleep 5
trap '$(STOPDB) && $(STOPZKPROVER)' EXIT; go test -short -race -p 1 ./...
.PHONY: test-full
test-full: build-docker compile-scs ## Runs all tests checking race conditions
$(STOPDB)
$(STOPZKPROVER)
$(RUNDB); sleep 7
$(RUNZKPROVER); sleep 5
trap '$(STOPDB) && $(STOPZKPROVER)' EXIT; MallocNanoZone=0 go test -race -p 1 -timeout 1200s `go list ./... | grep -v \/ci\/e2e-group`
.PHONY: test-full-non-e2e
test-full-non-e2e: build-docker compile-scs ## Runs non-e2e tests checking race conditions
$(STOPDB)
$(STOPZKPROVER)
$(RUNDB); sleep 7
$(RUNZKPROVER)
sleep 5
docker logs $(DOCKERCOMPOSEZKPROVER)
trap '$(STOPDB) && $(STOPZKPROVER)' EXIT; MallocNanoZone=0 go test -short -race -p 1 -timeout 600s ./...
.PHONY: test-e2e-group-1
test-e2e-group-1: build-docker compile-scs ## Runs group 1 e2e tests checking race conditions
$(STOPDB)
$(RUNDB); sleep 7
trap '$(STOPDB)' EXIT; MallocNanoZone=0 go test -race -p 1 -timeout 600s ./ci/e2e-group1/...
.PHONY: test-e2e-group-2
test-e2e-group-2: build-docker compile-scs ## Runs group 2 e2e tests checking race conditions
$(STOPDB)
$(RUNDB); sleep 7
trap '$(STOPDB)' EXIT; MallocNanoZone=0 go test -race -p 1 -timeout 600s ./ci/e2e-group2/...
.PHONY: test-e2e-group-3
test-e2e-group-3: build-docker compile-scs ## Runs group 3 e2e tests checking race conditions
$(STOPDB)
$(RUNDB); sleep 7
trap '$(STOPDB)' EXIT; MallocNanoZone=0 go test -race -p 1 -timeout 600s ./ci/e2e-group3/...
.PHONY: install-linter
install-linter: ## Installs the linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.46.2
.PHONY: lint
lint: ## Runs the linter
$(LINT)
.PHONY: check
check: lint build test ## lint, build and unit tests
.PHONY: validate
validate: lint build test-full ## lint, build, unit and e2e tests
.PHONY: run-db
run-db: ## Runs the node database
$(RUNDB)
.PHONY: stop-db
stop-db: ## Stops the node database
$(STOPDB)
.PHONY: run-node
run-node: ## Runs the node
$(RUNSEQUENCER)
$(RUNAGGREGATOR)
$(RUNJSONRPC)
$(RUNSYNC)
.PHONY: stop-node
stop-node: ## Stops the node
$(STOPSEQUENCER)
$(STOPJSONRPC)
$(STOPAGGREGATOR)
$(STOPSYNC)
.PHONY: run-network
run-network: ## Runs the l1 network
$(RUNL1NETWORK)
.PHONY: stop-network
stop-network: ## Stops the l1 network
$(STOPNETWORK)
.PHONY: run-prover
run-prover: ## Runs the zk prover
$(RUNPROVER)
.PHONY: stop-prover
stop-prover: ## Stops the zk prover
$(STOPPROVER)
.PHONY: run-zkprover
run-zkprover: ## Runs zkprover
$(RUNZKPROVER)
.PHONY: stop-zkprover
stop-zkprover: ## Stops zkprover
$(STOPZKPROVER)
.PHONY: run-explorer
run-explorer: ## Runs the explorer
$(RUNEXPLORERJSONRPC)
$(RUNEXPLORER)
.PHONY: stop-explorer
stop-explorer: ## Stops the explorer
$(STOPEXPLORER)
$(STOPEXPLORERRPC)
.PHONY: run-explorer-db
run-explorer-db: ## Runs the explorer database
$(RUNEXPLORERDB)
.PHONY: stop-explorer-db
stop-explorer-db: ## Stops the explorer database
$(STOPEXPLORERDB)
.PHONY: run
run: compile-scs ## Runs all the services
$(RUNDB)
$(RUNEXPLORERDB)
$(RUNL1NETWORK)
sleep 5
$(RUNZKPROVER)
sleep 5
$(RUNPROVER)
sleep 2
$(RUNSEQUENCER)
$(RUNAGGREGATOR)
$(RUNJSONRPC)
$(RUNEXPLORERJSONRPC)
$(RUNSYNC)
$(RUNEXPLORER)
.PHONY: run-broadcast
run-broadcast: ## Runs the broadcast service
$(RUNBROADCAST)
.PHONY: stop-broadcast
stop-broadcast: ## Stops the broadcast service
$(STOPBROADCAST)
.PHONY: init-network
init-network: ## Initializes the network
go run ./scripts/init_network/main.go .
.PHONY: deploy-sc
deploy-sc: ## deploys some examples of transactions and smart contracts
go run ./scripts/deploy_sc/main.go .
.PHONY: deploy-uniswap
deploy-uniswap: ## deploy the uniswap environment to the network
go run ./scripts/uniswap/main.go .
.PHONY: stop
stop: ## Stops all services
$(STOP)
.PHONY: restart
restart: stop run ## Executes `make stop` and `make run` commands
.PHONY: run-db-scripts
run-db-scripts: ## Executes scripts on the db after it has been initialized, potentially using info from the environment
./scripts/postgres/run.sh
.PHONY: install-git-hooks
install-git-hooks: ## Moves hook files to the .git/hooks directory
cp .github/hooks/* .git/hooks
.PHONY: generate-mocks
generate-mocks: ## Generates mocks for the tests, using mockery tool
mockery --name=etherman --dir=sequencer/strategy/txprofitabilitychecker --output=sequencer/strategy/txprofitabilitychecker --outpkg=txprofitabilitychecker_test --filename=etherman-mock_test.go
mockery --name=batchProcessor --dir=sequencer/strategy/txselector --output=sequencer/strategy/txselector --outpkg=txselector_test --filename=batchprocessor-mock_test.go
mockery --name=etherman --dir=sequencer --output=sequencer --outpkg=sequencer --structname=ethermanMock --filename=etherman-mock_test.go
mockery --name=Store --dir=state/tree --output=state/tree --outpkg=tree --structname=storeMock --filename=store-mock_test.go
mockery --name=storageInterface --dir=jsonrpc --output=jsonrpc --outpkg=jsonrpc --inpackage --structname=storageMock --filename=mock_storage_test.go
mockery --name=jsonRPCTxPool --dir=jsonrpc --output=jsonrpc --outpkg=jsonrpc --inpackage --structname=poolMock --filename=mock_pool_test.go
mockery --name=gasPriceEstimator --dir=jsonrpc --output=jsonrpc --outpkg=jsonrpc --inpackage --structname=gasPriceEstimatorMock --filename=mock_gasPriceEstimator_test.go
mockery --name=stateInterface --dir=jsonrpc --output=jsonrpc --outpkg=jsonrpc --inpackage --structname=stateMock --filename=mock_state_test.go
mockery --name=Tx --srcpkg=github.com/jackc/pgx/v4 --output=jsonrpc --outpkg=jsonrpc --structname=dbTxMock --filename=mock_dbtx_test.go
mockery --name=txManager --dir=sequencer --output=sequencer --outpkg=sequencer --structname=txmanagerMock --filename=txmanager-mock_test.go
mockery --name=etherman --dir=sequencer --output=sequencer --outpkg=sequencer --structname=ethermanMock --filename=etherman-mock_test.go
mockery --name=etherman --dir=sequencer/profitabilitychecker --output=sequencer/profitabilitychecker --outpkg=profitabilitychecker_test --structname=ethermanMock --filename=etherman-mock_test.go
mockery --name=stateInterface --dir=sequencer/broadcast --output=sequencer/broadcast --outpkg=broadcast_test --structname=stateMock --filename=state-mock_test.go
.PHONY: generate-code-from-proto
generate-code-from-proto: ## Generates code from proto files
cd proto/src/proto/statedb/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../merkletree/pb --go-grpc_out=../../../../../merkletree/pb --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative statedb.proto
cd proto/src/proto/zkprover/v1 && protoc --proto_path=. --go_out=../../../../../proverclient/pb --go-grpc_out=../../../../../proverclient/pb --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative zk-prover.proto
cd proto/src/proto/zkprover/v1 && protoc --proto_path=. --go_out=../../../../../proverservice/pb --go-grpc_out=../../../../../proverservice/pb --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative zk-prover.proto
cd proto/src/proto/executor/v1 && protoc --proto_path=. --go_out=../../../../../state/runtime/executor/pb --go-grpc_out=../../../../../state/runtime/executor/pb --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative executor.proto
cd proto/src/proto/broadcast/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../sequencer/broadcast/pb --go-grpc_out=../../../../../sequencer/broadcast/pb --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative broadcast.proto
.PHONY: update-external-dependencies
update-external-dependencies: ## Updates external dependencies like images, test vectors or proto files
go run ./scripts/cmd/... updatedeps
.PHONY: run-benchmarks
run-benchmarks: run-db ## Runs benchmars
go test -bench=. ./state/tree
.PHONY: compile-scs
compile-scs: ## Compiles smart contracts, configuration in test/contracts/index.yaml
go run ./scripts/cmd... compilesc --input ./test/contracts
## Help display.
## Pulls comments from beside commands and prints a nicely formatted
## display with the commands and their usage information.
.DEFAULT_GOAL := help
.PHONY: help
help: ## Prints this help
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'