github.com/leovct/zkevm-bridge-service@v0.4.4/Makefile (about)

     1  include version.mk
     2  
     3  DOCKER_COMPOSE := docker-compose -f docker-compose.yml
     4  DOCKER_COMPOSE_STATE_DB := zkevm-state-db
     5  DOCKER_COMPOSE_POOL_DB := zkevm-pool-db
     6  DOCKER_COMPOSE_RPC_DB := zkevm-rpc-db
     7  DOCKER_COMPOSE_BRIDGE_DB := zkevm-bridge-db
     8  DOCKER_COMPOSE_ZKEVM_NODE := zkevm-node
     9  DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2 := zkevm-node-v1tov2
    10  DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2 := zkevm-aggregator-v1tov2
    11  DOCKER_COMPOSE_L1_NETWORK := zkevm-mock-l1-network
    12  DOCKER_COMPOSE_L1_NETWORK_V1TOV2 := zkevm-v1tov2-l1-network
    13  DOCKER_COMPOSE_ZKPROVER := zkevm-prover
    14  DOCKER_COMPOSE_ZKPROVER_V1TOV2 := zkevm-prover-v1tov2
    15  DOCKER_COMPOSE_BRIDGE := zkevm-bridge-service
    16  DOCKER_COMPOSE_BRIDGE_V1TOV2 := zkevm-bridge-service-v1tov2
    17  
    18  RUN_STATE_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_STATE_DB)
    19  RUN_POOL_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_POOL_DB)
    20  RUN_BRIDGE_DB := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_DB)
    21  RUN_DBS := ${RUN_BRIDGE_DB} && ${RUN_STATE_DB} && ${RUN_POOL_DB}
    22  RUN_NODE := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_NODE)
    23  RUN_NODE_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2)
    24  RUN_AGGREGATOR_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2)
    25  RUN_L1_NETWORK := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_L1_NETWORK)
    26  RUN_L1_NETWORK_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_L1_NETWORK_V1TOV2)
    27  RUN_ZKPROVER := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER)
    28  RUN_ZKPROVER_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_ZKPROVER_V1TOV2)
    29  RUN_BRIDGE := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE)
    30  RUN_BRIDGE_V1TOV2 := $(DOCKER_COMPOSE) up -d $(DOCKER_COMPOSE_BRIDGE_V1TOV2)
    31  
    32  STOP_NODE_DB := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_NODE_DB) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_NODE_DB)
    33  STOP_BRIDGE_DB := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_DB) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_DB)
    34  STOP_DBS := ${STOP_NODE_DB} && ${STOP_BRIDGE_DB}
    35  STOP_NODE := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_NODE) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_NODE)
    36  STOP_NODE_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_NODE_V1TOV2)
    37  STOP_AGGREGATOR_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKEVM_AGGREGATOR_V1TOV2)
    38  STOP_NETWORK := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_L1_NETWORK) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_L1_NETWORK)
    39  STOP_NETWORK_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_L1_NETWORK_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_L1_NETWORK_V1TOV2)
    40  STOP_ZKPROVER := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKPROVER) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKPROVER)
    41  STOP_ZKPROVER_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_ZKPROVER_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_ZKPROVER_V1TOV2)
    42  STOP_BRIDGE := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE)
    43  STOP_BRIDGE_V1TOV2 := $(DOCKER_COMPOSE) stop $(DOCKER_COMPOSE_BRIDGE_V1TOV2) && $(DOCKER_COMPOSE) rm -f $(DOCKER_COMPOSE_BRIDGE_V1TOV2)
    44  STOP := $(DOCKER_COMPOSE) down --remove-orphans
    45  
    46  LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.Version=$(VERSION)'
    47  LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.GitRev=$(GITREV)'
    48  LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.GitBranch=$(GITBRANCH)'
    49  LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-bridge-service.BuildDate=$(DATE)'
    50  
    51  GO_BASE := $(shell pwd)
    52  GO_BIN := $(GO_BASE)/dist
    53  GO_ENV_VARS := GO_BIN=$(GO_BIN)
    54  GO_BINARY := zkevm-bridge
    55  GO_CMD := $(GO_BASE)/cmd
    56  
    57  LINT := $$(go env GOPATH)/bin/golangci-lint run --timeout=5m -E whitespace -E gosec -E gci -E misspell -E gomnd -E gofmt -E goimports --exclude-use-default=false --max-same-issues 0
    58  BUILD := $(GO_ENV_VARS) go build -ldflags "all=$(LDFLAGS)" -o $(GO_BIN)/$(GO_BINARY) $(GO_CMD)
    59  
    60  .PHONY: build
    61  build: ## Build the binary locally into ./dist
    62  	$(BUILD)
    63  
    64  .PHONY: lint
    65  lint: ## runs linter
    66  	$(LINT)
    67  
    68  .PHONY: install-git-hooks
    69  install-git-hooks: ## Moves hook files to the .git/hooks directory
    70  	cp .github/hooks/* .git/hooks
    71  
    72  .PHONY: test
    73  test: ## Runs only short tests without checking race conditions
    74  	$(STOP_BRIDGE_DB) || true
    75  	$(RUN_BRIDGE_DB); sleep 3
    76  	trap '$(STOP_BRIDGE_DB)' EXIT; go test --cover -short -p 1 ./...
    77  
    78  .PHONY: install-linter
    79  install-linter: ## Installs the linter
    80  	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.54.2
    81  
    82  .PHONY: build-docker
    83  build-docker: ## Builds a docker image with the zkevm bridge binary
    84  	docker build -t zkevm-bridge-service -f ./Dockerfile .
    85  
    86  .PHONY: run-db-node
    87  run-db-node: ## Runs the node database
    88  	$(RUN_NODE_DB)
    89  
    90  .PHONY: stop-db-node
    91  stop-db-node: ## Stops the node database
    92  	$(STOP_NODE_DB)
    93  
    94  .PHONY: run-db-bridge
    95  run-db-bridge: ## Runs the node database
    96  	$(RUN_BRIDGE_DB)
    97  
    98  .PHONY: stop-db-bridge
    99  stop-db-bridge: ## Stops the node database
   100  	$(STOP_BRIDGE_DB)
   101  
   102  .PHONY: run-dbs
   103  run-dbs: ## Runs the node database
   104  	$(RUN_DBS)
   105  
   106  .PHONY: stop-dbs
   107  stop-dbs: ## Stops the node database
   108  	$(STOP_DBS)
   109  
   110  .PHONY: run-node
   111  run-node: ## Runs the node
   112  	$(RUN_NODE)
   113  
   114  .PHONY: stop-node
   115  stop-node: ## Stops the node
   116  	$(STOP_NODE)
   117  
   118  .PHONY: run-network
   119  run-network: ## Runs the l1 network
   120  	$(RUN_L1_NETWORK)
   121  
   122  .PHONY: stop-network
   123  stop-network: ## Stops the l1 network
   124  	$(STOP_NETWORK)
   125  
   126  .PHONY: run-node-v1tov2
   127  run-node-v1tov2: ## Runs the node
   128  	$(RUN_NODE_V1TOV2)
   129  
   130  .PHONY: stop-node-v1tov2
   131  stop-node-v1tov2: ## Stops the node
   132  	$(STOP_NODE_V1TOV2)
   133  
   134  .PHONY: run-aggregator-v1tov2
   135  run-aggregator-v1tov2: ## Runs the aggregator
   136  	$(RUN_AGGREGATOR_V1TOV2)
   137  
   138  .PHONY: stop-aggregator-v1tov2
   139  stop-aggregator-v1tov2: ## Stops the aggregator
   140  	$(STOP_AGGREGATOR_V1TOV2)
   141  
   142  .PHONY: run-network-v1tov2
   143  run-network-v1tov2: ## Runs the l1 network
   144  	$(RUN_L1_NETWORK_V1TOV2)
   145  
   146  .PHONY: stop-network-v1tov2
   147  stop-network-v1tov2: ## Stops the l1 network
   148  	$(STOP_NETWORK_V1TOV2)
   149  
   150  .PHONY: run-prover
   151  run-prover: ## Runs the zk prover
   152  	$(RUN_ZKPROVER)
   153  
   154  .PHONY: stop-prover
   155  stop-prover: ## Stops the zk prover
   156  	$(STOP_ZKPROVER)
   157  
   158  .PHONY: run-prover-v1tov2
   159  run-prover-v1tov2: ## Runs the zk prover
   160  	$(RUN_ZKPROVER_V1TOV2)
   161  
   162  .PHONY: stop-prover-v1tov2
   163  stop-prover-v1tov2: ## Stops the zk prover
   164  	$(STOP_ZKPROVER_V1TOV2)	
   165  
   166  .PHONY: run-bridge
   167  run-bridge: ## Runs the bridge service
   168  	$(RUN_BRIDGE)
   169  
   170  .PHONY: stop-bridge
   171  stop-bridge: ## Stops the bridge service
   172  	$(STOP_BRIDGE)
   173  
   174  .PHONY: run-bridge-v1tov2
   175  run-bridge-v1tov2: ## Runs the bridge service
   176  	$(RUN_BRIDGE_V1TOV2)
   177  
   178  .PHONY: stop-bridge-v1tov2
   179  stop-bridge-v1tov2: ## Stops the bridge service
   180  	$(STOP_BRIDGE_V1TOV2)
   181  
   182  .PHONY: stop
   183  stop: ## Stops all services
   184  	$(STOP)
   185  
   186  .PHONY: restart
   187  restart: stop run ## Executes `make stop` and `make run` commands
   188  
   189  .PHONY: run
   190  run: stop ## runs all services
   191  	$(RUN_DBS)
   192  	$(RUN_L1_NETWORK)
   193  	sleep 5
   194  	$(RUN_ZKPROVER)
   195  	sleep 3
   196  	$(RUN_NODE)
   197  	sleep 7
   198  	$(RUN_BRIDGE)
   199  
   200  .PHONY: run-v1tov2
   201  run-v1tov2: stop ## runs all services
   202  	$(RUN_DBS)
   203  	$(RUN_L1_NETWORK_V1TOV2)
   204  	sleep 5
   205  	$(RUN_ZKPROVER_V1TOV2)
   206  	sleep 3
   207  	$(RUN_NODE_V1TOV2)
   208  	sleep 7
   209  	$(RUN_AGGREGATOR_V1TOV2)
   210  	$(RUN_BRIDGE_V1TOV2)
   211  
   212  .PHONY: update-external-dependencies
   213  update-external-dependencies: ## Updates external dependencies like images, test vectors or proto files
   214  	go run ./scripts/cmd/... updatedeps
   215  
   216  .PHONY: generate-code-from-proto
   217  generate-code-from-proto:
   218  	cd proto/src/proto/bridge/v1 && protoc --proto_path=. --proto_path=../../../../../third_party --go_out=../../../../../bridgectrl/pb --go-grpc_out=../../../../../bridgectrl/pb  --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative query.proto
   219  	cd proto/src/proto/bridge/v1 && protoc --proto_path=. --proto_path=../../../../../third_party --grpc-gateway_out=logtostderr=true:../../../../../bridgectrl/pb --grpc-gateway_opt=paths=source_relative query.proto
   220  
   221  .PHONY: stop-mockserver
   222  stop-mockserver: ## Stops the mock bridge service
   223  	$(STOP_BRIDGE_MOCK)
   224  
   225  .PHONY: bench
   226  bench: ## benchmark test
   227  	$(STOP_BRIDGE_DB) || true
   228  	$(RUN_BRIDGE_DB); sleep 3
   229  	trap '$(STOP_BRIDGE_DB)' EXIT; go test -run=NOTEST -timeout=30m -bench=Small ./test/benchmark/...
   230  
   231  .PHONY: bench-full
   232  bench-full: export ZKEVM_BRIDGE_DATABASE_PORT = 5432
   233  bench-full: ## benchmark full test
   234  	cd test/benchmark && \
   235  	go test -run=NOTEST -bench=Small . && \
   236  	go test -run=NOTEST -bench=Medium . && \
   237  	go test -run=NOTEST -timeout=30m -bench=Large .
   238  
   239  .PHONY: test-full
   240  test-full: build-docker stop run ## Runs all tests checking race conditions
   241  	sleep 3
   242  	trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -failfast -race -p 1 -timeout 2400s ./test/e2e/... -count 1 -tags='e2e'
   243  
   244  .PHONY: test-edge
   245  test-edge: build-docker stop run ## Runs all tests checking race conditions
   246  	sleep 3
   247  	trap '$(STOP)' EXIT; MallocNanoZone=0 go test -v -failfast -race -p 1 -timeout 2400s ./test/e2e/... -count 1 -tags='edge'
   248  
   249  .PHONY: validate
   250  validate: lint build test-full ## Validates the whole integrity of the code base
   251  
   252  ## Help display.
   253  ## Pulls comments from beside commands and prints a nicely formatted
   254  ## display with the commands and their usage information.
   255  .DEFAULT_GOAL := help
   256  
   257  .PHONY: help
   258  help: ## Prints this help
   259  		@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
   260  		| sort \
   261  		| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
   262  
   263  .PHONY: generate-mocks
   264  generate-mocks: ## Generates mocks for the tests, using mockery tool
   265  	mockery --name=ethermanInterface --dir=synchronizer --output=synchronizer --outpkg=synchronizer --structname=ethermanMock --filename=mock_etherman.go
   266  	mockery --name=storageInterface --dir=synchronizer --output=synchronizer --outpkg=synchronizer --structname=storageMock --filename=mock_storage.go
   267  	mockery --name=bridgectrlInterface --dir=synchronizer --output=synchronizer --outpkg=synchronizer --structname=bridgectrlMock --filename=mock_bridgectrl.go
   268  	mockery --name=Tx --srcpkg=github.com/jackc/pgx/v4 --output=synchronizer --outpkg=synchronizer --structname=dbTxMock --filename=mock_dbtx.go
   269  	mockery --name=zkEVMClientInterface --dir=synchronizer --output=synchronizer --outpkg=synchronizer --structname=zkEVMClientMock --filename=mock_zkevmclient.go