-
Notifications
You must be signed in to change notification settings - Fork 33
/
Makefile
634 lines (509 loc) · 30.5 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
include build.mk
# For simplicity's sake, we will use the same docker-compose file for all docker-compose commands.
docker-compose := $(shell command -v docker-compose 2> /dev/null || echo "docker compose") \
-f build/deployments/docker-compose.yaml
CWD ?= CURRENT_WORKING_DIRECTIONRY_NOT_SUPPLIED
# IMPROVE: Add `-shuffle=on` to the `go test` command to randomize the order in which tests are run.
# An easy way to turn off verbose test output for some of the test targets. For example
# `make test_persistence` by default enables verbose testing
# `VERBOSE_TEST="" make test_persistence` is an easy way to run the same tests without verbose output
VERBOSE_TEST ?= -v
# Detect OS using the $(shell uname -s) command
ifeq ($(shell uname -s),Darwin)
# Add macOS-specific commands here
SEDI = sed -i ''
else ifeq ($(shell uname -s),Linux)
# Add Linux-specific commands here
SEDI = sed -i
endif
.SILENT:
.PHONY: list ## List all make targets
list:
@${MAKE} -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: help ## Prints all the targets in all the Makefiles
.DEFAULT_GOAL := help
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: docker_check
# Internal helper target - check if docker is installed
docker_check:
{ \
if ( ! ( command -v docker >/dev/null && (docker compose version >/dev/null || command -v docker-compose >/dev/null) )); then \
echo "Seems like you don't have Docker or docker-compose installed. Make sure you review build/localnet/README.md and docs/development/README.md before continuing"; \
exit 1; \
fi; \
}
# Internal helper target - check if kubectl is installed.
kubectl_check:
{ \
if ( ! ( command -v kubectl >/dev/null )); then \
echo "Seems like you don't have Kubectl installed. Make sure you review build/localnet/README.md and docs/development/README.md before continuing"; \
exit 1; \
fi; \
}
# Internal helper target - check if rsync is installed.
rsync_check:
{ \
if ( ! ( command -v kubectl >/dev/null )); then \
echo "Seems like you don't have rsync installed. Make sure you review build/localnet/README.md and docs/development/README.md before continuing"; \
exit 1; \
fi; \
}
.PHONY: trigger_ci
trigger_ci: ## Trigger the CI pipeline by submitting an empty commit; See https://github.com/pokt-network/pocket/issues/900 for details
git commit --allow-empty -m "Empty commit"
git push
.PHONY: prompt_user
# Internal helper target - prompt the user before continuing
prompt_user:
@echo "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
.PHONY: warn_destructive
warn_destructive: ## Print WARNING to the user
@echo "This is a destructive action that will affect docker resources outside the scope of this repo!"
.PHONY: protoc_check
protoc_check: ## Checks if protoc is installed
{ \
if ! command -v protoc >/dev/null; then \
echo "Follow instructions to install 'protoc': https://grpc.io/docs/protoc-installation/"; \
fi; \
}
.PHONY: go_vet
go_vet: ## Run `go vet` on all files in the current project
go vet ./...
.PHONY: go_staticcheck
go_staticcheck: ## Run `go staticcheck` on all files in the current project
{ \
if command -v staticcheck >/dev/null; then \
staticcheck ./...; \
else \
echo "Install with 'go install honnef.co/go/tools/cmd/staticcheck@latest'"; \
fi; \
}
GODOC_PORT ?= 6060
.PHONY: go_doc
go_doc: # INCOMPLETE: [WIP] Generate documentation for the current project using `godo`
{ \
if command -v godoc >/dev/null; then \
echo "Visit http://localhost:${GODOC_PORT}/pkg/github.com/pokt-network/pocket"; \
godoc -http=localhost:${GODOC_PORT} -goroot=${PWD}/..; \
else \
echo "Install with 'go install golang.org/x/tools/cmd/godoc@latest'"; \
fi; \
}
.PHONY: go_protoc-go-inject-tag
go_protoc-go-inject-tag: ## Checks if protoc-go-inject-tag is installed
{ \
if ! command -v protoc-go-inject-tag >/dev/null; then \
echo "Install with 'go install github.com/favadi/protoc-go-inject-tag@latest'"; \
fi; \
}
.PHONY: go_oapi-codegen
go_oapi-codegen: ## Checks if oapi-codegen is installed
{ \
if ! command -v oapi-codegen >/dev/null; then \
echo "Install with 'go install github.com/deepmap/oapi-codegen/cmd/[email protected]'"; \
fi; \
}
.PHONY: go_clean_deps
go_clean_deps: ## Runs `go mod tidy` && `go mod vendor`
go mod tidy && go mod vendor
.PHONY: go_lint
go_lint: ## Run all linters that are triggered by the CI pipeline
docker run -t --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.51.1 golangci-lint run -v --timeout 2m --build-tags "test"
.PHONY: go_imports
go_imports: ## Group imports using rinchsan/gosimports
find . -name \*.go -not -path vendor -exec gosimports -w {} \;
.PHONY: go_fmt
go_fmt: ## Format all the .go files in the project in place.
gofmt -w -s .
# TODO(#964): add `rsync_check`, `kubectl_check`, `docker_check` as a validation in `install_cli_deps`; https://github.com/pokt-network/pocket/assets/1892194/a7a24a11-f54d-46e2-a73e-9e8ea7d06726
# .PHONY: install_cli_deps
# install_cli_deps: rsync_check kubectl_check docker_check ## Installs `helm`, `tilt` and the underlying `ci_deps`
.PHONY: install_cli_deps
install_cli_deps: ## Installs `helm`, `tilt` and the underlying `ci_deps`
make install_ci_deps
curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
.PHONY: install_ci_deps
install_ci_deps: ## Installs `protoc-gen-go`, `mockgen`, 'protoc-go-inject-tag' and other tools necessary for CI
go install "google.golang.org/protobuf/cmd/[email protected]" && protoc-gen-go --version
go install "github.com/golang/mock/[email protected]" && mockgen --version
go install "github.com/favadi/protoc-go-inject-tag@latest"
go install "github.com/deepmap/oapi-codegen/cmd/[email protected]"
.PHONY: develop_start
develop_start: ## Run all of the make commands necessary to develop on the project
make protoc_check && \
make docker_loki_check && \
make clean_mocks && \
make protogen_clean && make protogen_local && \
make go_clean_deps && \
make mockgen && \
make generate_rpc_openapi && \
make refresh_debug_keybase && \
make build
.PHONY: develop_test
develop_test: docker_check ## Run all of the make commands necessary to develop on the project and verify the tests pass
make develop_start && \
make test_all
.PHONY: lightweight_localnet_client
lightweight_localnet_client: docker_check ## Run a client daemon which is only used for debugging purposes
# Add `--build` to rebuild the client
${docker-compose} up -d client
.PHONY: lightweight_localnet_client_debug
lightweight_localnet_client_debug: docker_check ## Connect to the running client debugging daemon
docker exec -it client /bin/bash -c "go run -tags=debug app/client/*.go DebugUI"
# IMPROVE: Avoid building the binary on every shell execution and sync it from local instead
.PHONY: lightweight_localnet_shell
lightweight_localnet_shell: docker_check ## Connect to the running client debugging daemon
docker exec -it client /bin/bash -c "go build -tags=debug -o p1 ./app/client/*.go && chmod +x p1 && mv p1 /usr/bin && echo \"Finished building a new p1 binary\" && /bin/bash"
.PHONY: lightweight_localnet
lightweight_localnet: docker_check db_start monitoring_start ## Run a lightweight localnet composed of 4 validators w/ hot reload & debugging
# Add `--build` to rebuild the client
${docker-compose} up --force-recreate validator1 validator2 validator3 validator4 servicer1 fisherman1
.PHONY: db_start
db_start: docker_check ## Start a detached local postgres and admin instance; lightweight_localnet is responsible for instantiating the actual schemas
${docker-compose} up --no-recreate -d db pgadmin
.PHONY: db_cli
db_cli: ## Open a CLI to the local containerized postgres instance
echo "View schema by running 'SELECT schema_name FROM information_schema.schemata;'"
docker exec -it pocket-db bash -c "psql -U postgres"
psqlSchema ?= validator1
.PHONY: db_cli_node
db_cli_node: ## Open a CLI to the local containerized postgres instance for a specific node
echo "View all avialable tables by running \dt"
docker exec -it pocket-db bash -c "PGOPTIONS=--search_path=${psqlSchema} psql -U postgres"
.PHONY: db_drop
db_drop: docker_check ## Drop all schemas used for LocalNet development matching `node%`
docker exec -it pocket-db bash -c "psql -U postgres -d postgres -a -f /tmp/scripts/drop_all_schemas.sql"
.PHONY: db_bench_init
db_bench_init: docker_check ## Initialize pgbench on local postgres - needs to be called once after container is created.
docker exec -it pocket-db bash -c "pgbench -i -U postgres -d postgres"
.PHONY: db_bench
db_bench: docker_check ## Run a local benchmark against the local postgres instance - TODO(olshansky): visualize results
docker exec -it pocket-db bash -c "pgbench -U postgres -d postgres"
.PHONY: db_show_schemas
db_show_schemas: docker_check ## Show all the node schemas in the local SQL DB
docker exec -it pocket-db bash -c "psql -U postgres -d postgres -a -f /tmp/scripts/show_all_schemas.sql"
.PHONY: db_admin
db_admin: ## Helper to access to postgres admin GUI interface
echo "Open http://0.0.0.0:5050 and login with '[email protected]' and 'pgadmin4'.\n The password is 'postgres'"
.PHONY: docker_kill_all
docker_kill_all: docker_check ## Kill all containers started by the docker-compose file
${docker-compose} down
.PHONY: docker_wipe
docker_wipe: docker_check warn_destructive prompt_user ## [WARNING] Remove all the docker containers, images and volumes.
docker ps -a -q | xargs -r -I {} docker stop {}
docker ps -a -q | xargs -r -I {} docker rm {}
docker images -q | xargs -r -I {} docker rmi {}
docker volume ls -q | xargs -r -I {} docker volume rm {}
.PHONY: docker_wipe_volumes
docker_wipe_volumes: docker_check prompt_user ## [WARNING] Remove all pocket volumes
docker volume rm $$(docker volume ls -q | grep pocket-v1)
.PHONY: docker_wipe_nodes
docker_wipe_nodes: docker_check prompt_user db_drop ## [WARNING] Remove all the node containers
docker ps -a -q --filter="name=node*" | xargs -r -I {} docker stop {}
docker ps -a -q --filter="name=node*" | xargs -r -I {} docker rm {}
.PHONY: monitoring_start
monitoring_start: docker_check ## Start grafana, metrics and logging system (this is auto-triggered by lightweight_localnet)
${docker-compose} up --no-recreate -d grafana loki vm
.PHONY: docker_loki_install
docker_loki_install: docker_check ## Installs the loki docker driver
echo "Installing the loki docker driver...\n"
docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
.PHONY: docker_loki_check
## check if the loki docker driver is installed
docker_loki_check:
if [ `docker plugin ls | grep loki: | wc -l` -eq 0 ]; then make docker_loki_install; fi
.PHONY: refresh_debug_keybase
refresh_debug_keybase: ## Refreshes the debug keybase with the latest keys from the private_keys.yaml file if necessary
go run build/debug_keybase/main.go ./build/localnet/manifests/private-keys.yaml ./build/debug_keybase
.PHONY: clean_mocks
clean_mocks: ## Use `clean_mocks` to delete mocks before recreating them. Also useful to cleanup code that was generated from a different branch
find . -type f ! -name "mocks.go" -not -path "./vendor/*" -name "*_mock.go" -exec rm {} \;
.PHONY: mockgen
mockgen: clean_mocks ## Use `mockgen` to generate mocks used for testing purposes of all the modules.
$(eval modules_dir = "shared/modules")
go generate ./${modules_dir}
echo "Mocks generated in ${modules_dir}/mocks"
$(eval DIRS = persistence p2p)
for dir in $(DIRS); do \
echo "Processing $$dir mocks..."; \
find $$dir/types/mocks -type f ! -name "mocks.go" -exec rm {} \;; \
go generate ./${dir_name}/...; \
echo "$$dir mocks generated in $$dir/types/mocks"; \
done
# TODO(team): Tested locally with `protoc` version `libprotoc 3.19.4`. In the near future, only the Dockerfiles will be used to compile protos.
.PHONY: protogen_show
protogen_show: ## A simple `find` command that shows you the generated protobufs.
find . -name "*.pb.go" | grep -v -e "prototype" -e "vendor"
.PHONY: protogen_clean
protogen_clean: ## Remove all the generated protobufs.
find . -name "*.pb.go" | grep -v -e "prototype" -e "vendor" | xargs -r rm
# IMPROVE: Look into using buf in the future; https://github.com/bufbuild/buf.
PROTOC = protoc --experimental_allow_proto3_optional --go_opt=paths=source_relative
PROTOC_SHARED = $(PROTOC) -I=./shared
.PHONY: protogen_local
protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the protobufs
# Shared
$(PROTOC) -I=./shared/core/types/proto --go_out=./shared/core/types ./shared/core/types/proto/*.proto
$(PROTOC) -I=./shared/modules/types/proto --go_out=./shared/modules/types ./shared/modules/types/proto/*.proto
$(PROTOC) -I=./shared/messaging/proto --go_out=./shared/messaging ./shared/messaging/proto/*.proto
$(PROTOC) -I=./shared/codec/proto --go_out=./shared/codec ./shared/codec/proto/*.proto
# Runtime
$(PROTOC) -I=./runtime/configs/types/proto --go_out=./runtime/configs/types ./runtime/configs/types/proto/*.proto
$(PROTOC) -I=./runtime/configs/proto -I=./runtime/configs/types/proto --go_out=./runtime/configs ./runtime/configs/proto/*.proto
$(PROTOC_SHARED) -I=./runtime/genesis/proto --go_out=./runtime/genesis ./runtime/genesis/proto/*.proto
protoc-go-inject-tag -input="./runtime/genesis/*.pb.go"
# Utility
$(PROTOC_SHARED) -I=./utility/types/proto --go_out=./utility/types ./utility/types/proto/*.proto
# Consensus
$(PROTOC_SHARED) -I=./consensus/types/proto --go_out=./consensus/types ./consensus/types/proto/*.proto
# P2P
$(PROTOC_SHARED) -I=./p2p/types/proto --go_out=./p2p/types ./p2p/types/proto/*.proto
# IBC
@if test ! -e "./ibc/types/proto/proofs.proto"; then \
make download_ics23_proto; \
fi
$(PROTOC_SHARED) -I=./ibc/types/proto --go_out=./ibc/types ./ibc/types/proto/*.proto
$(PROTOC_SHARED) -I=./ibc/client/types/proto --go_out=./ibc/client/types ./ibc/client/types/proto/*.proto
$(PROTOC_SHARED) -I=./ibc/client/types/proto -I=./ibc/client/light_clients/types/proto -I=./shared/core/types/proto -I=./ibc/types/proto --go_out=./ibc/client/light_clients/types ./ibc/client/light_clients/types/proto/*.proto
# echo "View generated proto files by running: make protogen_show"
# CONSIDERATION: Some proto files contain unused gRPC services so we may need to add the following
# if/when we decide to include it: `grpc--go-grpc_opt=paths=source_relative --go-grpc_out=./output/path`
.PHONY: download_ics23_proto
download_ics23_proto:
echo "Downloading cosmos/ics23 proto definitions..."; \
curl -s -o ./ibc/types/proto/proofs.proto https://raw.githubusercontent.com/cosmos/ics23/master/proto/cosmos/ics23/v1/proofs.proto; \
$(SEDI) \
-e '/^package/{N;d;}' \
-e '[email protected]/.*"@github.com/pokt-network/pocket/ibc/types"@g' \
./ibc/types/proto/proofs.proto && \
awk 'BEGIN { print "// ===== !! THIS IS CLONED FROM cosmos/ics23 !! =====\n" } { print }' ./ibc/types/proto/proofs.proto > tmpfile && mv tmpfile ./ibc/types/proto/proofs.proto; \
.PHONY: protogen_docker_m1
## TECHDEBT: Test, validate & update.
protogen_docker_m1: docker_check
docker build -t pocket/proto-generator -f ./build/Dockerfile.m1.proto . && docker run --platform=linux/amd64 -it -v $(CWD)/shared:/usr/src/app/shared pocket/proto-generator
.PHONY: protogen_docker
## TECHDEBT: Test, validate & update.
protogen_docker: docker_check
docker build -t pocket/proto-generator -f ./build/Dockerfile.proto . && docker run -it -v $(CWD)/:/usr/src/app/ pocket/proto-generator
.PHONY: generate_rpc_openapi
generate_rpc_openapi: go_oapi-codegen ## (Re)generates the RPC server and client infra code from the openapi spec file (./rpc/v1/openapi.yaml)
oapi-codegen --config ./rpc/server.gen.config.yml ./rpc/v1/openapi.yaml > ./rpc/server.gen.go
oapi-codegen --config ./rpc/client.gen.config.yml ./rpc/v1/openapi.yaml > ./rpc/client.gen.go
echo "OpenAPI client and server generated"
SWAGGER_PORT=127.0.0.1:8080
.PHONY: swagger-ui
swagger-ui: ## Starts a local Swagger UI instance for the RPC API
echo "Attempting to start Swagger UI at http://localhost:8080"
docker run --name pocket-swagger-ui --rm -p $(SWAGGER_PORT):8080 -e SWAGGER_JSON=/v1/openapi.yaml -v $(shell pwd)/rpc/v1:/v1 swaggerapi/swagger-ui
.PHONY: generate_cli_commands_docs
generate_cli_commands_docs: ## (Re)generates the CLI commands docs (this is meant to be called by CI)
$(eval cli_docs_dir = "app/client/cli/doc/commands")
rm ${cli_docs_dir}/*.md >/dev/null 2>&1 || true
cd app/client/cli/docgen && go run .
echo "CLI commands docs generated in ${cli_docs_dir}"
.PHONY: generate_node_state_machine_diagram
generate_node_state_machine_diagram: ## (Re)generates the Node State Machine diagram
go run ./state_machine/visualizer/main.go
echo "Node State Machine diagram generated in state_machine/docs/state-machine.diagram.md"
.PHONY: test_all
test_all: ## Run all go unit tests
go test -p=1 -count=1 -tags=test ./...
.PHONY: test_e2e
test_e2e: kubectl_check ## Run all E2E tests
echo "IMPROVE(#759): Make sure you ran 'make localnet_up' in case this fails with infrastructure related errors."
go test ${VERBOSE_TEST} -count=1 -tags=test,e2e ./e2e/tests/...
.PHONY: test_all_with_json_coverage
test_all_with_json_coverage: generate_rpc_openapi ## Run all go unit tests, output results & coverage into json & coverage files
go test -p=1 -count=1 -tags=test -json ./... -covermode=count -coverprofile=coverage.out | tee test_results.json | jq
.PHONY: test_race
test_race: ## Identify all unit tests that may result in race conditions
go test ${VERBOSE_TEST} -race -count=1 -tags=test ./...
.PHONY: test_app
test_app: ## Run all go app module unit tests
go test ${VERBOSE_TEST} -p=1 -count=1 -tags=test ./app/...
.PHONY: test_utility
test_utility: ## Run all go utility module unit tests
go test ${VERBOSE_TEST} -p=1 -count=1 -tags=test ./utility/...
.PHONY: test_shared
test_shared: ## Run all go unit tests in the shared module
go test ${VERBOSE_TEST} -p=1 -count=1 -tags=test ./shared/...
.PHONY: test_consensus
test_consensus: ## Run all go unit tests in the consensus module
go test ${VERBOSE_TEST} -p=1 -count=1 -tags=test ./consensus/...
# These tests are isolated to a single package which enables logs to be streamed in realtime. More details here: https://stackoverflow.com/a/74903989/768439
.PHONY: test_consensus_e2e
test_consensus_e2e: ## Run all go t2e unit tests in the consensus module w/ log streaming
go test ${VERBOSE_TEST} -count=1 -tags=test ./consensus/e2e_tests/...
.PHONY: test_consensus_concurrent_tests
test_consensus_concurrent_tests: ## Run unit tests in the consensus module that could be prone to race conditions (#192)
for i in $$(seq 1 100); do go test -timeout 2s -count=1 -tags=test -run ^TestPacemakerTimeoutIncreasesRound$ ./consensus/e2e_tests; done;
for i in $$(seq 1 100); do go test -timeout 2s -count=1 -tags=test -run ^TestHotstuff4Nodes1BlockHappyPath$ ./consensus/e2e_tests; done;
for i in $$(seq 1 100); do go test -timeout 2s -count=1 -tags=test -race -run ^TestPacemakerTimeoutIncreasesRound$ ./consensus/e2e_tests; done;
for i in $$(seq 1 100); do go test -timeout 2s -count=1 -tags=test -race -run ^TestHotstuff4Nodes1BlockHappyPath$ ./consensus/e2e_tests; done;
.PHONY: test_hotstuff
test_hotstuff: ## Run all go unit tests related to hotstuff consensus
go test ${VERBOSE_TEST} -count=1 -tags=test ./consensus/e2e_tests -run Hotstuff
.PHONY: test_pacemaker
test_pacemaker: ## Run all go unit tests related to hotstuff pacemaker
go test ${VERBOSE_TEST} -count=1 -tags=test ./consensus/e2e_tests -run Pacemaker
.PHONY: test_statesync
test_statesync: ## Run all go unit tests related to hotstuff statesync
go test -v ${VERBOSE_TEST} -count=1 -tags=test -run StateSync ./consensus/e2e_tests
.PHONY: test_vrf
test_vrf: ## Run all go unit tests in the VRF library
go test ${VERBOSE_TEST} -count=1 -tags=test ./consensus/leader_election/vrf
.PHONY: test_sortition
test_sortition: ## Run all go unit tests in the Sortition library
go test ${VERBOSE_TEST} -count=1 -tags=test ./consensus/leader_election/sortition
.PHONY: test_persistence
test_persistence: ## Run all go unit tests in the Persistence module
go test ${VERBOSE_TEST} -count=1 -tags=test -p=1 ./persistence/...
.PHONY: test_persistence_state_hash
test_persistence_state_hash: ## Run all go unit tests in the Persistence module related to the state hash
go test ${VERBOSE_TEST} -count=1 -tags=test -run TestStateHash ./persistence/...
.PHONY: test_servicer_relay
test_servicer_relay: ## Run all go unit tests related to servicer relays
go test ${VERBOSE_TEST} -count=1 -tags=test ./utility/servicer -run TestRelay
.PHONY: test_p2p
test_p2p: ## Run all p2p related tests
go test ${VERBOSE_TEST} -count=1 -tags=test ./p2p/...
.PHONY: test_p2p_raintree
test_p2p_raintree: ## Run all p2p raintree related tests
go test ${VERBOSE_TEST} -count=1 -tags=test -run RainTreeNetwork -count=1 ./p2p/...
.PHONY: test_p2p_raintree_addrbook
test_p2p_raintree_addrbook: ## Run all p2p raintree addr book related tests
go test ${VERBOSE_TEST} -count=1 -tags=test -run RainTreeAddrBook -count=1 ./p2p/...
.PHONY: test_ibc
test_ibc: ## Run all go unit tests in the IBC module
go test ${VERBOSE_TEST} -count=1 -tags=test -p=1 ./ibc/...
# TIP: For benchmarks, consider appending `-run=^#` to avoid running unit tests in the same package
.PHONY: benchmark_persistence_state_hash
benchmark_persistence_state_hash: ## Benchmark the state hash computation
go test ${VERBOSE_TEST} -count=1 -tags=test -cpu 1,2 -benchtime=1s -benchmem -bench=. -run BenchmarkStateHash -count=1 ./persistence/...
.PHONY: benchmark_sortition
benchmark_sortition: ## Benchmark the Sortition library
go test ${VERBOSE_TEST} -count=1 -tags=test -bench=. -run ^# ./consensus/leader_election/sortition
.PHONY: benchmark_p2p_addrbook
benchmark_p2p_peerstore: ## Run P2P peerstore benchmarks
go test ${VERBOSE_TEST} -count=1 -tags=test -bench=. -run BenchmarkPeerstore ./p2p/...
### Inspired by @goldinguy_ in this post: https://goldin.io/blog/stop-using-todo ###
# TODO - General Purpose catch-all.
# DECIDE - A TODO indicating we need to make a decision and document it using an ADR in the future; https://github.com/pokt-network/pocket-network-protocol/tree/main/ADRs
# TECHDEBT - Not a great implementation, but we need to fix it later.
# IMPROVE - A nice to have, but not a priority. It's okay if we never get to this.
# OPTIMIZE - An opportunity for performance improvement if/when it's necessary
# DISCUSS - Probably requires a lengthy offline discussion to understand next steps.
# INCOMPLETE - A change which was out of scope of a specific PR but needed to be documented.
# INVESTIGATE - TBD what was going on, but needed to continue moving and not get distracted.
# CLEANUP - Like TECHDEBT, but not as bad. It's okay if we never get to this.
# HACK - Like TECHDEBT, but much worse. This needs to be prioritized
# REFACTOR - Similar to TECHDEBT, but will require a substantial rewrite and change across the codebase
# CONSIDERATION - A comment that involves extra work but was thoughts / considered as part of some implementation
# CONSOLIDATE - We likely have similar implementations/types of the same thing, and we should consolidate them.
# ADDTEST - Add more tests for a specific code section
# DEPRECATE - Code that should be removed in the future
# RESEARCH - A non-trivial action item that requires deep research and investigation being next steps can be taken
# DOCUMENT - A comment that involves the creation of a README or other documentation
# BUG - There is a known existing bug in this code
# DISCUSS_IN_THIS_COMMIT - SHOULD NEVER BE COMMITTED TO MASTER. It is a way for the reviewer of a PR to start / reply to a discussion.
# TODO_IN_THIS_COMMIT - SHOULD NEVER BE COMMITTED TO MASTER. It is a way to start the review process while non-critical changes are still in progress
TODO_KEYWORDS = -e "TODO" -e "DECIDE" -e "TECHDEBT" -e "IMPROVE" -e "OPTIMIZE" -e "DISCUSS" -e "INCOMPLETE" -e "INVESTIGATE" -e "CLEANUP" -e "HACK" -e "REFACTOR" -e "CONSIDERATION" -e "TODO_IN_THIS_COMMIT" -e "DISCUSS_IN_THIS_COMMIT" -e "CONSOLIDATE" -e "DEPRECATE" -e "ADDTEST" -e "RESEARCH" -e "BUG"
# How do I use TODOs?
# 1. <KEYWORD>: <Description of follow up work>;
# e.g. HACK: This is a hack, we need to fix it later
# 2. If there's a specific issue, or specific person, add that in paranthesiss
# e.g. TODO(@Olshansk): Automatically link to the Github user https://github.com/olshansk
# e.g. INVESTIGATE(#420): Automatically link this to github issue https://github.com/pokt-network/pocket/issues/420
# e.g. DISCUSS(@Olshansk, #420): Specific individual should tend to the action item in the specific ticket
# e.g. CLEANUP(core): This is not tied to an issue, or a person, but should only be done by the core team.
# e.g. CLEANUP: This is not tied to an issue, or a person, and can be done by the core team or external contributors.
# 3. Feel free to add additional keywords to the list above
.PHONY: todo_list
todo_list: ## List all the TODOs in the project (excludes vendor and prototype directories)
grep --exclude-dir={.git,vendor,prototype} -r ${TODO_KEYWORDS} .
TODO_SEARCH ?= $(shell pwd)
.PHONY: todo_search
todo_search: ## List all the TODOs in a specific directory specific by `TODO_SEARCH`
grep --exclude-dir={.git,vendor,prototype} -r ${TODO_KEYWORDS} ${TODO_SEARCH}
.PHONY: todo_count
todo_count: ## Print a count of all the TODOs in the project
grep --exclude-dir={.git,vendor,prototype} -r ${TODO_KEYWORDS} . | wc -l
.PHONY: todo_this_commit
todo_this_commit: ## List all the TODOs needed to be done in this commit
grep --exclude-dir={.git,vendor,prototype,.vscode} --exclude=Makefile -r -e "TODO_IN_THIS_COMMIT" -e "DISCUSS_IN_THIS_COMMIT"
# Default values for gen_genesis_and_config
numValidators ?= 4
numServicers ?= 1
numApplications ?= 1
numFishermen ?= 1
.PHONY: gen_genesis_and_config
gen_genesis_and_config: ## Generate the genesis and config files for LocalNet
go run ./build/config/main.go --genPrefix="gen." --numValidators=${numValidators} --numServicers=${numServicers} --numApplications=${numApplications} --numFishermen=${numFishermen}
.PHONY: gen_genesis_and_config
clear_genesis_and_config: ## Clear the genesis and config files for LocalNet
rm build/config/gen.*.json
.PHONY: localnet_up
localnet_up: ## Starts up a k8s LocalNet with all necessary dependencies (tl;dr `tilt up`)
tilt up --file=build/localnet/Tiltfile
.PHONY: localnet_client_debug
localnet_client_debug: ## Opens a `client debug` cli to interact with blockchain (e.g. change pacemaker mode, reset to genesis, etc). Though the node binary updates automatiacally on every code change (i.e. hot reloads), if client is already open you need to re-run this command to execute freshly compiled binary.
kubectl exec -it deploy/dev-cli-client --container pocket -- p1 DebugUI
.PHONY: localnet_shell
localnet_shell: ## Opens a shell in the pod that has the `client` cli available. The binary updates automatically whenever the code changes (i.e. hot reloads).
kubectl exec -it deploy/dev-cli-client --container pocket -- /bin/bash
.PHONY: localnet_logs_validators
localnet_logs_validators: ## Outputs logs from all validators
kubectl logs -l "pokt.network/purpose=validator" --all-containers=true --tail=-1
.PHONY: localnet_logs_validators_follow
localnet_logs_validators_follow: ## Outputs logs from all validators and follows them (i.e. tail)
kubectl logs -l "pokt.network/purpose=validator" --all-containers=true --max-log-requests=1000 --tail=-1 -f
.PHONY: localnet_down
localnet_down: ## Stops LocalNet and cleans up dependencies (tl;dr `tilt down`)
tilt down --file=build/localnet/Tiltfile
.PHONY: localnet_db_cli
localnet_db_cli: ## Open a CLI to the local containerized postgres instance of validator 001:
echo "View schema by running 'SELECT schema_name FROM information_schema.schemata;'"
kubectl exec -it validator-001-postgresql-0 -- bash -c "psql postgresql://postgres:LocalNetPassword@localhost"
.PHONY: check_cross_module_imports
check_cross_module_imports: ## Lists cross-module imports
$(eval exclude_common=--exclude=Makefile --exclude-dir=shared --exclude-dir=app --exclude-dir=runtime)
echo "persistence:\n"
grep ${exclude_common} --exclude-dir=persistence -r "github.com/pokt-network/pocket/persistence" || echo "✅ OK!"
echo "-----------------------"
echo "utility:\n"
grep ${exclude_common} --exclude-dir=utility -r "github.com/pokt-network/pocket/utility" || echo "✅ OK!"
echo "-----------------------"
echo "consensus:\n"
grep ${exclude_common} --exclude-dir=consensus -r "github.com/pokt-network/pocket/consensus" || echo "✅ OK!"
echo "-----------------------"
echo "telemetry:\n"
grep ${exclude_common} --exclude-dir=telemetry -r "github.com/pokt-network/pocket/telemetry" || echo "✅ OK!"
echo "-----------------------"
echo "p2p:\n"
grep ${exclude_common} --exclude-dir=p2p -r "github.com/pokt-network/pocket/p2p" || echo "✅ OK!"
echo "-----------------------"
echo "runtime:\n"
grep ${exclude_common} --exclude-dir=runtime -r "github.com/pokt-network/pocket/runtime" || echo "✅ OK!"
.PHONY: send_local_tx
send_local_tx: ## A hardcoded send tx to make LocalNet debugging easier
go run -tags=debug app/client/*.go Account Send --non_interactive 00104055c00bed7c983a48aac7dc6335d7c607a7 00204737d2a165ebe4be3a7d5b0af905b0ea91d8 1000
.PHONY: query_chain_params
query_chain_params: ## A hardcoded ChainParams query to make LocalNet debugging easier
go run app/client/main.go Query AllChainParams
.PHONY: search_structs
search_structs: ## Greps and outputs all of the structs in the project (excluding vendor or proto generated files)
grep -r "type .* struct" --exclude-dir="vendor" --exclude="*.gen.go" --exclude="*.pb.go" .
.PHONY: search_interfaces
search_interfaces: ## Greps and outputs all of the structs in the project (excluding vendor or proto generated files)
grep -r "type .* interface" --exclude-dir="vendor" --exclude="*.gen.go" --exclude="*.pb.go" .
.PHONY: search_protos
search_protos: ## Finds all of the proto files in the project (excluding vendor)
find . -name "*.proto" -not -path "./vendor/*"
.PHONY: ggshield_secrets_scan
ggshield_secrets_scan: ## Scans the project for secrets using ggshield
ggshield secret scan path --recursive .
.PHONY: ggshield_secrets_add
ggshield_secrets_add: ## A helper that adds the last results from `make ggshield_secrets_scan`, store in `.cache_ggshield` to `.gitguardian.yaml`. See `ggshield for more configuratiosn`
ggshield secret ignore --last-found