Skip to content

Commit

Permalink
feat(eventindexer): Event indexer (#13439)
Browse files Browse the repository at this point in the history
Co-authored-by: David <david@taiko.xyz>
Co-authored-by: dave | d1onys1us <13951458+d1onys1us@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 27, 2023
1 parent 8ef5ce2 commit 08b26d2
Show file tree
Hide file tree
Showing 43 changed files with 4,694 additions and 23 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/eventindexer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Eventindexer

on:
push:
branches: [main, alpha-2]
paths:
- "packages/eventindexer/**"
pull_request:
paths:
- "packages/eventindexer/**"

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
working-directory: ./packages/eventindexer
args: --config=.golangci.yml

test:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ">=1.19.0"

- name: eventindexer - Unit Tests
working-directory: ./packages/eventindexer
run: go test `go list ./... | grep -v ./contracts | grep -v ./mock | grep -v ./cmd` -coverprofile=coverage.txt -covermode=atomic

- name: eventindexer - Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./packages/eventindexer/coverage.txt
flags: eventindexer

push-docker-image:
# only push docker image on PR merge to main
if: ${{ github.event }} == 'push'
name: Build and push docker image
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Login to GCR
uses: docker/login-action@v2
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
gcr.io/evmchain/eventindexer
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=sha
- name: Build and push
uses: docker/build-push-action@v2
with:
platforms: linux/amd64
push: true
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PACKAGE=eventindexer
4 changes: 3 additions & 1 deletion .github/workflows/relayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ jobs:
with:
platforms: linux/amd64
push: true
context: packages/relayer
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PACKAGE=relayer
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM golang:1.19.3 as builder

ARG PACKAGE=eventindexer

RUN apt install git curl

RUN mkdir /taiko-mono

WORKDIR /taiko-mono

COPY . .

RUN go mod download

WORKDIR /taiko-mono/packages/$PACKAGE

RUN CGO_ENABLED=0 GOOS=linux go build -o /taiko-mono/packages/$PACKAGE/bin/${PACKAGE} /taiko-mono/packages/$PACKAGE/cmd/main.go

FROM alpine:latest

ARG PACKAGE

RUN apk add --no-cache ca-certificates

COPY --from=builder /taiko-mono/packages/$PACKAGE/bin/$PACKAGE /usr/local/bin/

ENTRYPOINT ["$PACKAGE"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ taiko-mono
├── <a href="./packages">packages</a>
│ ├── <a href="./packages/branding">branding</a>: Taiko branding materials
│ ├── <a href="./packages/bridge-ui">bridge-ui</a>: Taiko Bridge frontend UI
│ ├── <a href="./packages/eventindexer">eventindexer</a>: Event indexer
│ ├── <a href="./packages/protocol">protocol</a>: Taiko ZK-Rollup L2 Protocol and Taiko Bridge smart contracts
│ ├── <a href="./packages/relayer">relayer</a>: Bridge relayer (backend)
│ ├── <a href="./packages/status-page">status-page</a>: Taiko Protocol status page
Expand Down
13 changes: 13 additions & 0 deletions packages/eventindexer/.default.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
HTTP_PORT=4101
PROMETHEUS_HTTP_PORT=6061
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_DATABASE=eventindexer
MYSQL_HOST=localhost:3306
MYSQL_MAX_IDLE_CONNS=50
MYSQL_MAX_OPEN_CONNS=3000
MYSQL_CONN_MAX_LIFETIME_IN_MS=100000
L1_TAIKO_ADDRESS=0x7B3AF414448ba906f02a1CA307C56c4ADFF27ce7
L1_RPC_URL=wss://l1ws.a2.taiko.xyz
CORS_ORIGINS=*
BLOCK_BATCH_SIZE=10
46 changes: 46 additions & 0 deletions packages/eventindexer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.netrc
.env
.test.env
main
coverage.txt

# Local .terraform directories
.terraform

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

.idea

Bridge.json
TaikoL2.json
IHeaderSync.json
42 changes: 42 additions & 0 deletions packages/eventindexer/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See: https://golangci-lint.run/usage/configuration/
#
# Note: for VSCode, you must have the following settings to use this configuration:
#
# "go.lintTool": "golangci-lint",
# "go.lintFlags": [
# "--fast",
# "--config=${workspaceFolder}/.golangci.yml"
# ],

output:
format: colored-line-number

linters:
enable:
- errcheck
- funlen
- gocognit
- gocritic
- gofmt
- golint
- gosec
- gosimple
- lll
- unused
- whitespace
- wsl

linters-settings:
funlen:
lines: 137
statements: 54
gocognit:
min-complexity: 43

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- funlen

2 changes: 1 addition & 1 deletion packages/eventindexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Catches events, stores them in the database to be queried via API.

run `cp .default.env .env`, and add your own private key as `RELAYER_ECDSA_KEY` in `.env`. You need to be running a MySQL instance, and replace all the `MYSQL_` env vars with yours.

Run `go run cmd/main.go --help` to see a list of possible configuration flags, or `go run cmd/main.go` to run with defaults, which will process messages from L1 to L2, and from L2 to L1, and start indexing blocks from 0.
Run `go run cmd/main.go --help` to see a list of possible configuration flags, or `go run cmd/main.go` to run with defaults, which will process messages from L1 to L2, and from L2 to L1, and start indexing blocks from 0.
Loading

0 comments on commit 08b26d2

Please sign in to comment.