Skip to content

Commit 138e285

Browse files
authored
Merge branch 'main' into petera/handle-resourceexhaused-ingestion
2 parents 79a0de7 + 87dae51 commit 138e285

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2082
-1193
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ jobs:
4040
- name: Docker Auth
4141
run: |-
4242
gcloud auth configure-docker ${{ vars.GAR_LOCATION }}-docker.pkg.dev
43-
docker build -t ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }} --build-arg GATEWAY_VERSION=${{ steps.set_version.outputs.GATEWAY_VERSION }} --file Dockerfile .
43+
docker build --build-arg VERSION="${{ steps.set_version.outputs.GATEWAY_VERSION }}" --build-arg ARCH=amd64 -t ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }} --file Dockerfile .
4444
docker push ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ tests/e2e-network/node_modules
55
tests/e2e-network/package-lock.json
66
db
77
flow.json
8-
flow*.json
98
.idea
109
metrics/data/

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
FROM golang:1.22.0 as app-builder
44

5-
ARG GATEWAY_VERSION="v0.1.0"
6-
75
# Build the app binary in /app
86
WORKDIR /app
97

@@ -14,8 +12,11 @@ COPY . ./
1412
RUN go mod download
1513
RUN go mod verify
1614

15+
ARG VERSION
16+
ARG ARCH
17+
1718
# Build binary
18-
RUN CGO_ENABLED=1 go build -o bin -ldflags="-X github.com/onflow/flow-evm-gateway/api.Version=${GATEWAY_VERSION}" cmd/main.go
19+
RUN CGO_ENABLED=1 GOOS=linux GOARCH=$ARCH go build -o bin -ldflags="-X github.com/onflow/flow-evm-gateway/api.Version=$VERSION" -trimpath cmd/main.go
1920
RUN chmod a+x bin
2021

2122
# RUN APP

Makefile

Lines changed: 175 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
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+
--tx-state-validation=local-index
32+
33+
# Set VERSION from command line, environment, or default to SHORT_COMMIT
34+
VERSION ?= $(SHORT_COMMIT)
35+
36+
# Set IMAGE_TAG from VERSION if not explicitly set
37+
IMAGE_TAG ?= $(VERSION)
38+
39+
# docker container registry
40+
CONTAINER_REGISTRY := us-west1-docker.pkg.dev/dl-flow-devex-production/development
41+
DOCKER_BUILDKIT := 1
42+
DATADIR := /data
43+
44+
# Determine OS and set ARCH
45+
ifeq ($(UNAME_S),Darwin)
46+
OS := macos
47+
ARCH := arm64
48+
COMPILER_FLAGS += CGO_CFLAGS="-O2 -D__BLST_PORTABLE__"
49+
else ifeq ($(UNAME_S),Linux)
50+
OS := linux
51+
ARCH := amd64
52+
else
53+
$(error Unsupported operating system: $(UNAME_S))
54+
endif
55+
56+
# Function to check and append required arguments
57+
define check_and_append
58+
$(if $($(2)),\
59+
$(eval CMD_ARGS += --$(1)=$($(2))),\
60+
$(error ERROR: $(2) ENV variable is required))
61+
endef
62+
63+
# Default target
64+
.PHONY: all
65+
all: test build
66+
167
.PHONY: test
268
test:
369
# test all packages
@@ -20,7 +86,7 @@ check-tidy:
2086

2187
.PHONY: build
2288
build:
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
89+
$(COMPILER_FLAGS) go build -o flow-evm-gateway -ldflags="-X github.com/onflow/flow-evm-gateway/api.Version=$(IMAGE_TAG)" cmd/main.go
2490
chmod a+x flow-evm-gateway
2591

2692
.PHONY: fix-lint
@@ -33,7 +99,9 @@ generate:
3399
mockery --dir=storage --name=BlockIndexer --output=storage/mocks
34100
mockery --dir=storage --name=ReceiptIndexer --output=storage/mocks
35101
mockery --dir=storage --name=TransactionIndexer --output=storage/mocks
102+
mockery --dir=storage --name=AccountIndexer --output=storage/mocks
36103
mockery --dir=storage --name=TraceIndexer --output=storage/mocks
104+
mockery --all --dir=services/traces --output=services/traces/mocks
37105
mockery --all --dir=services/ingestion --output=services/ingestion/mocks
38106
mockery --dir=models --name=Engine --output=models/mocks
39107

@@ -42,35 +110,120 @@ ci: check-tidy test e2e-test
42110

43111
.PHONY: start
44112
start:
45-
go run ./cmd/server/main.go
113+
$(COMPILER_FLAGS) go run ./cmd/main.go
46114

47115
.PHONY: start-local
48116
start-local:
49117
rm -rf db/
50118
rm -rf metrics/data/
51-
go run cmd/main.go run \
52-
--flow-network-id=flow-emulator \
53-
--coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \
54-
--coa-address=f8d6e0586b0a20c7 \
55-
--coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
56-
--wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
57-
--gas-price=0 \
58-
--log-writer=console \
59-
--profiler-enabled=true \
60-
--profiler-port=6060
119+
$(COMPILER_FLAGS) go run cmd/main.go run $(EMULATOR_ARGS)
61120

62121
# Use this after running `make build`, to test out the binary
63122
.PHONY: start-local-bin
64123
start-local-bin:
65124
rm -rf db/
66125
rm -rf metrics/data/
67-
./flow-evm-gateway run \
68-
--flow-network-id=flow-emulator \
69-
--coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \
70-
--coa-address=f8d6e0586b0a20c7 \
71-
--coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
72-
--wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
73-
--gas-price=0 \
74-
--log-writer=console \
75-
--profiler-enabled=true \
76-
--profiler-port=6060
126+
$(COMPILER_FLAGS) go run cmd/main.go run $(EMULATOR_ARGS)
127+
128+
# Build docker image from local sources
129+
.PHONY: docker-build-local
130+
docker-build-local:
131+
ifdef GOARCH
132+
$(eval ARCH=$(GOARCH))
133+
endif
134+
docker build --build-arg ARCH=$(ARCH) --no-cache -f dev/Dockerfile -t "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(COMMIT)" .
135+
136+
# Docker run for local development
137+
.PHONY: docker-run-local
138+
docker-run-local:
139+
@trap 'kill $$(jobs -p)' EXIT
140+
flow emulator -f dev/flow.json &
141+
sleep 3
142+
143+
$(call check_and_append,coinbase,EMULATOR_COINBASE)
144+
$(call check_and_append,coa-address,EMULATOR_COA_ADDRESS)
145+
$(call check_and_append,coa-key,EMULATOR_COA_KEY)
146+
147+
$(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)
148+
149+
docker run -p 8545:8545 --add-host=host.docker.internal:host-gateway "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(COMMIT)" $(CMD_ARGS)
150+
151+
152+
# Build docker image for release
153+
.PHONY: docker-build
154+
docker-build:
155+
ifdef GOARCH
156+
$(eval ARCH=$(GOARCH))
157+
endif
158+
docker build --build-arg VERSION="$(VERSION)" --build-arg ARCH=$(ARCH) -f Dockerfile -t "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(IMAGE_TAG)" \
159+
--label "git_commit=$(COMMIT)" --label "git_tag=$(IMAGE_TAG)" .
160+
161+
# Install image version from container registry
162+
.PHONY: docker-pull-version
163+
docker-pull-version:
164+
docker pull "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(IMAGE_VERSION)"
165+
166+
# Run GW image
167+
# https://github.com/onflow/flow-evm-gateway?tab=readme-ov-file#configuration-flags
168+
# Requires the following ENV variables:
169+
# - ACCESS_NODE_GRPC_HOST: [access.devnet.nodes.onflow.org:9000 | access.mainnet.nodes.onflow.org:9000]
170+
# - FLOW_NETWORK_ID: [flow-testnet, flow-mainnet]
171+
# - INIT_CADENCE_HEIGHT: [testnet: 211176670, mainnet: 85981135]
172+
# - 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)
173+
# - COA_ADDRESS: To be set by the operator. This is a Cadence address which funds gateway operations (remove 0x prefix)
174+
# - 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
175+
#
176+
# Optional
177+
# - GAS_PRICE: the attoFlow amount of gas to charge for transactions
178+
#
179+
# Optional make arguments:
180+
# - DOCKER_RUN_DETACHED: Runs container in detached mode when true
181+
# - DOCKER_HOST_PORT: Sets the exposed host port for the gateway JSON-RPC port
182+
# - DOCKER_HOST_METRICS_PORT: Sets the exposed host port for the gateway metrics RPC port
183+
# - DOCKER_MOUNT: Sets the host mount point for the EVM data dir
184+
.PHONY: docker-run
185+
docker-run:
186+
$(eval CMD_ARGS :=)
187+
ifdef DOCKER_RUN_DETACHED
188+
$(eval MODE=-d)
189+
endif
190+
ifdef DOCKER_HOST_METRICS_PORT
191+
$(eval HOST_METRICS_PORT=$(DOCKER_HOST_METRICS_PORT))
192+
else
193+
$(eval HOST_METRICS_PORT=8080)
194+
endif
195+
ifdef DOCKER_HOST_PORT
196+
$(eval HOST_PORT=$(DOCKER_HOST_PORT))
197+
else
198+
$(eval HOST_PORT=8545)
199+
endif
200+
ifndef GAS_PRICE
201+
$(eval GAS_PRICE=100)
202+
endif
203+
ifdef DOCKER_HOST_MOUNT
204+
$(eval MOUNT=--mount type=bind,src="$(DOCKER_HOST_MOUNT)",target=$(DATADIR))
205+
$(call check_and_append,database-dir,DATADIR)
206+
endif
207+
208+
ifdef FLOW_NETWORK_ID
209+
ifeq ($(FLOW_NETWORK_ID),flow-testnet)
210+
$(eval ACCESS_NODE_SPORK_HOSTS=$(TESTNET_ACCESS_NODE_SPORK_HOSTS))
211+
else ifeq ($(FLOW_NETWORK_ID),flow-mainnet)
212+
$(eval ACCESS_NODE_SPORK_HOSTS=$(MAINNET_ACCESS_NODE_SPORK_HOSTS))
213+
endif
214+
endif
215+
216+
$(call check_and_append,access-node-grpc-host,ACCESS_NODE_GRPC_HOST)
217+
$(call check_and_append,flow-network-id,FLOW_NETWORK_ID)
218+
$(call check_and_append,init-cadence-height,INIT_CADENCE_HEIGHT)
219+
$(call check_and_append,coinbase,COINBASE)
220+
$(call check_and_append,coa-address,COA_ADDRESS)
221+
$(call check_and_append,coa-key,COA_KEY)
222+
$(call check_and_append,gas-price,GAS_PRICE)
223+
$(call check_and_append,metrics-port,HOST_METRICS_PORT)
224+
225+
$(eval CMD_ARGS += --ws-enabled=true --rate-limit=9999999 --rpc-host=0.0.0.0 --log-level=info --tx-state-validation=local-index)
226+
$(call check_and_append,access-node-spork-hosts,ACCESS_NODE_SPORK_HOSTS)
227+
228+
docker run $(MODE) -p $(HOST_PORT):8545 -p $(HOST_METRICS_PORT):8080 $(MOUNT) "$(CONTAINER_REGISTRY)/flow-evm-gateway:$(IMAGE_TAG)" $(CMD_ARGS)
229+

0 commit comments

Comments
 (0)