1+ # The short Git commit hash
2+ SHORT_COMMIT := $(shell git rev-parse --short HEAD)
3+ BRANCH_NAME: =$(shell git rev-parse --abbrev-ref HEAD | tr '/' '-')
4+ # The Git commit hash
5+ COMMIT := $(shell git rev-parse HEAD)
6+ # The tag of the current commit, otherwise empty
7+ GIT_VERSION := $(shell git describe --tags --abbrev=2 2>/dev/null)
8+ CMD_ARGS :=
9+ # ACCESS_NODE_SPORK_HOSTS are comma separated
10+ TESTNET_ACCESS_NODE_SPORK_HOSTS := access-001.devnet51.nodes.onflow.org:9000
11+ MAINNET_ACCESS_NODE_SPORK_HOSTS := access-001.mainnet25.nodes.onflow.org:9000
12+ EMULATOR_COINBASE := FACF71692421039876a5BB4F10EF7A439D8ef61E
13+ EMULATOR_COA_ADDRESS := f8d6e0586b0a20c7
14+ EMULATOR_COA_KEY := 2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21
15+ UNAME_S := $(shell uname -s)
16+ # Set default values
17+ ARCH :=
18+ OS :=
19+ COMPILER_FLAGS := CGO_ENABLED=1
20+
21+ EMULATOR_ARGS := --flow-network-id=flow-emulator \
22+ --coinbase=$(EMULATOR_COINBASE ) \
23+ --coa-address=$(EMULATOR_COA_ADDRESS ) \
24+ --coa-key=$(EMULATOR_COA_KEY ) \
25+ --wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
26+ --gas-price=0 \
27+ --log-writer=console \
28+ --tx-state-validation=local-index \
29+ --profiler-enabled=true \
30+ --profiler-port=6060
31+
32+ # Set VERSION from command line, environment, or default to SHORT_COMMIT
33+ VERSION ?= ${SHORT_COMMIT}
34+
35+ # Set IMAGE_TAG from VERSION if not explicitly set
36+ IMAGE_TAG ?= ${VERSION}
37+
38+ # Function to check and append required arguments
39+ define check_and_append
40+ $(if $($(2 ) ) ,\
41+ $(eval CMD_ARGS += --$(1 ) =$($(2 ) ) ) ,\
42+ $(error ERROR: $(2 ) ENV variable is required) )
43+ endef
44+
45+ # Determine OS and set ARCH
46+ ifeq ($(UNAME_S ) ,Darwin)
47+ OS := macos
48+ ARCH := arm64
49+ $(eval COMPILER_FLAGS += CGO_CFLAGS="-O2 -D__BLST_PORTABLE__")
50+ else ifeq ($(UNAME_S),Linux)
51+ OS := linux
52+ ARCH := amd64
53+ else
54+ $(error Unsupported operating system : $(UNAME_S ) )
55+ endif
56+
57+ # docker container registry
58+ export CONTAINER_REGISTRY := us-west1-docker.pkg.dev/dl-flow-devex-production/development
59+ export DOCKER_BUILDKIT := 1
60+ export DATADIR := /data
61+
162.PHONY : test
263test :
364 # test all packages
@@ -20,7 +81,7 @@ check-tidy:
2081
2182.PHONY : build
2283build :
23- CGO_ENABLED=1 go build -o flow-evm-gateway -ldflags=" -X github.com/onflow/flow-evm-gateway/api.Version=$( shell git describe --tags --abbrev=0 2> /dev/null || echo ' unknown ' ) " cmd/main.go
84+ $( COMPILER_FLAGS ) go build -o flow-evm-gateway -ldflags=" -X github.com/onflow/flow-evm-gateway/api.Version=$( IMAGE_TAG ) " cmd/main.go
2485 chmod a+x flow-evm-gateway
2586
2687.PHONY : fix-lint
@@ -44,37 +105,113 @@ ci: check-tidy test e2e-test
44105
45106.PHONY : start
46107start :
47- go run ./cmd/server /main.go
108+ $( COMPILER_FLAGS ) go run ./cmd/main.go
48109
49110.PHONY : start-local
50111start-local :
51112 rm -rf db/
52113 rm -rf metrics/data/
53- go run cmd/main.go run \
54- --flow-network-id=flow-emulator \
55- --coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \
56- --coa-address=f8d6e0586b0a20c7 \
57- --coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
58- --wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
59- --coa-resource-create=true \
60- --gas-price=0 \
61- --log-writer=console \
62- --profiler-enabled=true \
63- --profiler-port=6060
114+ $(COMPILER_FLAGS ) go run cmd/main.go run $(EMULATOR_ARGS )
64115
65116# Use this after running `make build`, to test out the binary
66117.PHONY : start-local-bin
67118start-local-bin :
68119 rm -rf db/
69120 rm -rf metrics/data/
70- ./flow-evm-gateway run \
71- --flow-network-id=flow-emulator \
72- --coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \
73- --coa-address=f8d6e0586b0a20c7 \
74- --coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
75- --wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
76- --coa-resource-create=true \
77- --gas-price=0 \
78- --log-writer=console \
79- --profiler-enabled=true \
80- --profiler-port=6060
121+ $(COMPILER_FLAGS ) go run cmd/main.go run $(EMULATOR_ARGS )
122+
123+ # Build docker image from local sources
124+ .PHONY : docker-build-local
125+ docker-build-local :
126+ ifdef GOARCH
127+ $(eval ARCH=$(GOARCH))
128+ endif
129+ docker build --build-arg ARCH=$(ARCH) --no-cache -f dev/Dockerfile -t "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(COMMIT)" .
130+
131+ # Docker run for local development
132+ .PHONY : docker-run-local
133+ docker-run-local :
134+ @trap ' kill $$(jobs -p)' EXIT
135+ flow emulator -f dev/flow.json &
136+ sleep 3
137+
138+ $(call check_and_append,coinbase,EMULATOR_COINBASE)
139+ $(call check_and_append,coa-address,EMULATOR_COA_ADDRESS)
140+ $(call check_and_append,coa-key,EMULATOR_COA_KEY)
141+
142+ $(eval CMD_ARGS += --flow-network-id=flow-emulator --tx-state-validation=local-index --log-level=debug --gas-price=0 --log-writer=console --profiler-enabled=true --access-node-grpc-host=host.docker.internal:3569)
143+
144+ docker run -p 8545:8545 --add-host=host.docker.internal:host-gateway "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(COMMIT)" $(CMD_ARGS)
145+
146+
147+ # Build docker image for release
148+ .PHONY : docker-build
149+ docker-build :
150+ ifdef GOARCH
151+ $(eval ARCH=$(GOARCH))
152+ endif
153+ docker build --build-arg VERSION="$(VERSION)" --build-arg ARCH=$(ARCH) -f Dockerfile -t "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(IMAGE_TAG)" \
154+ --label "git_commit=$(COMMIT)" --label "git_tag=$(IMAGE_TAG)" .
155+
156+ # Install image version from container registry
157+ .PHONY : docker-pull-version
158+ docker-pull-version :
159+ docker pull " $( CONTAINER_REGISTRY) /flow-evm-gateway:$( IMAGE_VERSION) "
160+
161+ # Run GW image
162+ # https://github.com/onflow/flow-evm-gateway?tab=readme-ov-file#configuration-flags
163+ # Requires the following ENV variables:
164+ # - ACCESS_NODE_GRPC_HOST: [access.devnet.nodes.onflow.org:9000 | access.mainnet.nodes.onflow.org:9000]
165+ # - FLOW_NETWORK_ID: [flow-testnet, flow-mainnet]
166+ # - INIT_CADENCE_HEIGHT: [testnet: 211176670, mainnet: 85981135]
167+ # - COINBASE: To be set by the operator. This is an EVM EOA or COA address which is set as the receiver of GW transaction fees (remove 0x prefix)
168+ # - COA_ADDRESS: To be set by the operator. This is a Cadence address which funds gateway operations (remove 0x prefix)
169+ # - COA_KEY: A full weight, private key belonging to operator COA_ADDRESS (remove 0x prefix). NB: For development use only. We recommend using cloud KMS configuration on mainnet
170+ #
171+ # Optional
172+ # - GAS_PRICE: the attoFlow amount of gas to charge for transactions
173+ #
174+ # Optional make arguments:
175+ # - DOCKER_RUN_DETACHED: Runs container in detached mode when true
176+ # - DOCKER_HOST_PORT: Sets the exposed container port for the gateway JSON-RPC
177+ # - DOCKER_MOUNT: Sets the host mount point for the EVM data dir
178+ .PHONY : docker-run
179+ docker-run :
180+ $(eval CMD_ARGS :=)
181+ ifdef DOCKER_RUN_DETACHED
182+ $(eval MODE=-d)
183+ endif
184+ ifdef DOCKER_HOST_PORT
185+ $(eval HOST_PORT=$(DOCKER_HOST_PORT))
186+ else
187+ $(eval HOST_PORT=8545)
188+ endif
189+ ifndef GAS_PRICE
190+ $(eval GAS_PRICE=100)
191+ endif
192+ ifdef DOCKER_MOUNT
193+ $(eval MOUNT=--mount type=bind,src="$(DOCKER_MOUNT)",target=$(DATADIR))
194+ $(call check_and_append,database-dir,DATADIR)
195+ endif
196+
197+ ifdef FLOW_NETWORK_ID
198+ ifeq ($(FLOW_NETWORK_ID),flow-testnet)
199+ ACCESS_NODE_SPORK_HOSTS := TESTNET_ACCESS_NODE_SPORK_HOSTS
200+ else ifeq ($(FLOW_NETWORK_ID),flow-mainnet)
201+ ACCESS_NODE_SPORK_HOSTS := MAINNET_ACCESS_NODE_SPORK_HOSTS
202+ endif
203+ endif
204+
205+ $(call check_and_append,access-node-grpc-host,ACCESS_NODE_GRPC_HOST)
206+ $(call check_and_append,flow-network-id,FLOW_NETWORK_ID)
207+ $(call check_and_append,init-cadence-height,INIT_CADENCE_HEIGHT)
208+ $(call check_and_append,coinbase,COINBASE)
209+ $(call check_and_append,coa-address,COA_ADDRESS)
210+ $(call check_and_append,coa-key,COA_KEY)
211+ $(call check_and_append,gas-price,GAS_PRICE)
212+
213+ $(eval CMD_ARGS += --ws-enabled=true --rate-limit=9999999 --rpc-host=0.0.0.0 --log-level=info --tx-state-validation=local-index)
214+ $(call check_and_append,access-node-spork-hosts,ACCESS_NODE_SPORK_HOSTS)
215+
216+ docker run $(MODE) -p $(HOST_PORT):8545 -p 8080:8080 $(MOUNT) "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(IMAGE_TAG)" $(CMD_ARGS)
217+
0 commit comments