Skip to content

Commit

Permalink
Merge pull request #52 from onflow/gregor/index/integrate-requester
Browse files Browse the repository at this point in the history
[Indexer] Flow EVM requester
  • Loading branch information
devbugging authored Feb 27, 2024
2 parents a54f4ba + 8f45c00 commit ea18f11
Show file tree
Hide file tree
Showing 58 changed files with 6,878 additions and 3,476 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: "Deploy EVM Gateway to Cloud Run"

on:
push:
branches:
- main
- gregor/index/previewnet-testing-fixes

env:
DOCKER_IMAGE_URL: ${{ vars.GCP_DOCKER_IMAGE_URL }}:${{ github.sha }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.BUILDER_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.BUILDER_SERVICE_ACCOUNT }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ vars.GAR_PROJECT_ID }}

- name: Docker Auth
run: |-
gcloud auth configure-docker ${{ vars.GAR_LOCATION }}-docker.pkg.dev
docker build -t ${{ env.DOCKER_IMAGE_URL }} --file Dockerfile .
docker push ${{ env.DOCKER_IMAGE_URL }}
deploy-canary:
needs: [build]
environment: canary
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.DEPLOYER_GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.DEPLOYER_SERVICE_ACCOUNT }}
- name: Deploy EVM Gateway to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ vars.GCP_SERVICE }}
image: ${{ env.DOCKER_IMAGE_URL }}

deploy-crescendo:
needs: [build]
environment: crescendo
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.DEPLOYER_GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.DEPLOYER_SERVICE_ACCOUNT }}
- name: Deploy EVM Gateway to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ vars.GCP_SERVICE }}
image: ${{ env.DOCKER_IMAGE_URL }}

deploy-testnet:
needs: [build]
environment: testnet
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.DEPLOYER_GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.DEPLOYER_SERVICE_ACCOUNT }}
- name: Deploy EVM Gateway to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ vars.GCP_SERVICE }}
image: ${{ env.DOCKER_IMAGE_URL }}

deploy-mainnet:
needs: [build]
environment: mainnet
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
workload_identity_provider: ${{ vars.DEPLOYER_GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.DEPLOYER_SERVICE_ACCOUNT }}
- name: Deploy EVM Gateway to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ vars.GCP_SERVICE }}
image: ${{ env.DOCKER_IMAGE_URL }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
integration/db-test
db
flow.json
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# BUILD BIN

FROM golang:1.22.0 as builder
# Install go modules
WORKDIR /flow-evm-gateway
COPY go.* ./
COPY . ./
RUN go mod download
RUN go mod verify
RUN CGO_ENABLED=0 go build -o evm-gateway ./cmd/main/main.go
RUN chmod a+x evm-gateway
RUN chmod a+x ./scripts/run.sh

# RUN APP
FROM debian:latest
WORKDIR /flow-evm-gateway
RUN apt-get update
RUN apt-get install -y nfs-common
COPY --from=builder /flow-evm-gateway/evm-gateway /flow-evm-gateway/evm-gateway
COPY --from=builder /flow-evm-gateway/scripts/run.sh /flow-evm-gateway/run.sh
EXPOSE 3000
CMD cd /flow-evm-gateway && ./run.sh
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: test
test:
# test all packages
go test -cover -parallel 8 ./...
go test -cover ./...

.PHONY: check-tidy
check-tidy:
Expand All @@ -11,8 +11,23 @@ check-tidy:
.PHONY: generate
generate:
go get -d github.com/vektra/mockery/[email protected]
mockery --all --dir=storage --output=storage/mocks
mockery --dir=storage --name=BlockIndexer --output=storage/mocks
mockery --dir=storage --name=ReceiptIndexer --output=storage/mocks
mockery --dir=storage --name=TransactionIndexer --output=storage/mocks
mockery --dir=storage --name=AccountIndexer --output=storage/mocks
mockery --all --dir=services/events --output=services/events/mocks

.PHONY: ci
ci: check-tidy test

.PHONY: start-emulator
start-emulator:
./flow-x86_64-linux- emulator --evm-enabled

.PHONY: setup-account
setup-account:
./flow-x86_64-linux- transactions send api/cadence/transactions/create_bridged_account.cdc 1500.0 --network=emulator --signer=emulator-account

.PHONY: start
start:
go run ./cmd/server/main.go
100 changes: 77 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,77 @@
# Repository template
A template enabled repository, including all necesary files to open source.
(create an issue with the following content if you want to track the repo configuration)

## Repository settings and configuration
- [ ] Repository info
- [ ] Add repo description
- [ ] Update website to https://onflow.org
- [ ] Add relevant repository topics (i.e. `blockchain` `onflow`, etc)
- [ ] Check issue labels on `.github/labels.yml` and do any commit to main to get them synced
- [ ] Define merge workflow (create new branch protection rule)
- [ ] `main` branch rule:
- [ ] **Require pull request reviews before merging (2 approving reviews)**
- [ ] **Require review from Code Owners**
- [ ] **Require status checks to pass before merging**
- [ ] **Require branches to be up to date before merging**
- [ ] **Require linear history**
- [ ] **Restrict who can push to matching branches**
- [ ] Choose `onflow/flow` team

- [ ] Add necessary team members, adjust access levels
- [ ] `onflow/flow-admin` ⇒ Admin access
- [ ] `onflow/flow-engineering ` ⇒ Write access
# EVM Gateway


**EVM Gateway enables seamless interaction with the Flow EVM, mirroring the experience of engaging with any other EVM blockchain.**

EVM Gateway serves as a powerful API gateway, designed specifically to bridge the Ethereum Virtual Machine (EVM) with the Flow blockchain ecosystem. By exposing a JSON RPC API, it enables seamless access to EVM functionalities on Flow, creating a unified platform for developers to interact with and build upon.

At its core, EVM Gateway is engineered to index EVM transactions and blocks produced within the EVM network hosted on Flow. This capability ensures that all relevant data—ranging from transaction details to block information—is accurately captured and made readily accessible to clients. Through its comprehensive indexing system, EVM Gateway provides an essential service for applications requiring up-to-date and historical EVM data.

Beyond data provision, EVM Gateway plays a crucial role in transaction management. It accepts EVM-compatible transactions from clients, transforming them into Cadence transactions before submitting them to the Flow network. This process not only simplifies the transaction submission for users familiar with EVM ecosystems but also leverages Flow's unique features and benefits, thereby enhancing transaction efficiency and security.

EVM Gateway stands as a testament to the collaborative potential of blockchain technologies. By integrating EVM's robust capabilities with Flow's innovative blockchain platform, it offers developers a versatile and powerful toolset. Whether you're building decentralized applications, conducting blockchain analysis, or integrating blockchain functionalities into existing systems, EVM Gateway provides the necessary infrastructure to bridge these two pioneering technologies.


# Running
Operating an EVM Gateway is straightforward. It can either be deployed locally alongside the Flow emulator or configured to connect with any active Flow networks supporting EVM. Given that the EVM Gateway depends solely on [Access Node APIs](https://developers.flow.com/networks/node-ops/access-onchain-data/access-nodes/accessing-data/access-api), it is compatible with any networks offering this API access.

### Running Locally
**Start Emulator**

In order to run the gateway locally you need to start the emulator with EVM enabled:
```
flow emulator --evm-enabled
```
_Make sure flow.json has the emulator account configured to address and private key we will use for starting gateway bellow._

Then you need to start the gateway:
```
go run cmd/main/main.go
--init-cadence-height 0
--coinbase FACF71692421039876a5BB4F10EF7A439D8ef61E
--coa-address f8d6e0586b0a20c7
--coa-key 2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21
--coa-resource-create
--gas-price 0
```

_In this example we use `coa-address` value set to service account of the emulator, same as `coa-key`.
This account will by default be funded with Flow which is a requirement. For `coinbase` we can
use whichever valid EVM address. It's not really useful for local running beside collecting fees. We provide also the
`coa-resource-create` to auto-create resources needed on start-up on the `coa` account in order to operate gateway.
`gas-price` is set at 0 so we don't have to fund EOA accounts. We can set it higher but keep in mind you will then
need funded accounts for interacting with EVM._

## Configuration Flags

The application can be configured using the following flags at runtime:

| Flag | Default Value | Description |
|----------------------------|------------------|------------------------------------------------------------------------------------------------------------------------|
| `--database-dir` | `./db` | Path to the directory for the database. |
| `--rpc-host` | (empty) | Host for the JSON RPC API server. |
| `--rpc-port` | `3000` | Port for the JSON RPC API server. |
| `--access-node-grpc-host` | `localhost:3569` | Host to the Flow access node (AN) gRPC API. |
| `--init-cadence-height` | `EmptyHeight` | Init cadence block height from where the event ingestion will start. *WARNING*: Used only if no existing DB values. |
| `--evm-network-id` | `testnet` | EVM network ID (options: `testnet`, `mainnet`). |
| `--flow-network-id` | `emulator` | Flow network ID (options: `emulator`, `previewnet`). |
| `--coinbase` | (required) | Coinbase address to use for fee collection. |
| `--gas-price` | `1` | Static gas price used for EVM transactions. |
| `--coa-address` | (required) | Flow address that holds COA account used for submitting transactions. |
| `--coa-key` | (required) | *WARNING*: Do not use this flag in production! Private key value for the COA address used for submitting transactions. |
| `--coa-resource-create` | `false` | Auto-create the COA resource in the Flow COA account provided if one doesn't exist. |

## Getting Started

To start using EVM Gateway, ensure you have the required dependencies installed and then run the application with your desired configuration flags. For example:

```bash
./evm-gateway --rpc-host "127.0.0.1" --rpc-port 3000 --database-dir "/path/to/database"
````
For more detailed information on configuration and deployment, refer to the Configuration and Deployment sections.

## Contributing
We welcome contributions from the community! Please read our Contributing Guide for information on how to get involved.

## License
EVM Gateway is released under the Apache License 2.0. See the LICENSE file for more details.
Loading

0 comments on commit ea18f11

Please sign in to comment.