Skip to content

Commit e552ca5

Browse files
authored
Merge pull request #116 from bitfinity-network/evm_block_extractor_daemon
[EPROD-707] Evm block extractor daemon
2 parents 1ffcccd + 5a101d5 commit e552ca5

14 files changed

Lines changed: 348 additions & 354 deletions

File tree

.github/workflows/block-extractor-scheduler.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,53 @@
1-
name: 'Deploy EVM Block Extractor to GCP Registry'
1+
name: 'Deploy EVM Block Extractor docker image'
22

33
on:
44
workflow_dispatch: {}
55

66
push:
7-
branches:
8-
- 'main'
7+
branches: [main]
8+
tags:
9+
- 'v*'
910

1011
concurrency:
1112
group: ${{ github.workflow }}-${{ github.ref }}
1213
cancel-in-progress: true
1314

15+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{github.repository_owner}}/evm-block-extractor
19+
20+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
1421
jobs:
15-
publishing-image:
22+
build-and-push-image:
1623
runs-on: ubuntu-latest
17-
strategy:
18-
matrix:
19-
network: [mainnet, testnet]
20-
24+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
25+
permissions:
26+
contents: read
27+
packages: write
28+
#
2129
steps:
22-
- name: Set up QEMU
23-
uses: docker/setup-qemu-action@v3
24-
25-
- name: Set up Docker Buildx
26-
uses: docker/setup-buildx-action@v3
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
2732

28-
- name: Login to GCP Registry
33+
- name: Log in to the Container registry
2934
uses: docker/login-action@v3
3035
with:
31-
registry: us-east4-docker.pkg.dev
32-
username: _json_key
33-
password: ${{ secrets.GCP_DOCKER_KEY }}
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
3439

35-
- name: Checkout
36-
uses: actions/checkout@v3
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3745

38-
- name: Building CloudRun image for BigQuery
46+
- name: Build and push Docker image
3947
uses: docker/build-push-action@v5
4048
with:
41-
push: true
4249
context: .
4350
file: ./src/evm-block-extractor/Dockerfile
44-
tags: |
45-
us-east4-docker.pkg.dev/extractor-410310/block-extractor-repo/evm-block-extractor-server:${{ matrix.network }}-latest
46-
build-args: |
47-
PROJECT_ID=${{ secrets.BIGQUERY_PROJECT_ID }}
48-
DATASET=${{ matrix.network }}
49-
GCP_BLOCK_EXTRACTOR_SA_KEY=${{ secrets.GCP_BLOCK_EXTRACTOR_SA_KEY }}
51+
push: true
52+
tags: ${{ steps.meta.outputs.tags }}
53+
# labels: ${{ steps.meta.outputs.labels }}

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ic-storage = { git = "https://github.com/bitfinity-network/canister-sdk", packag
5050
itertools = "0.12"
5151
jsonrpc-core = "18.0"
5252
jsonrpsee = { version = "0.21", features = ["server", "macros"] }
53+
lightspeed_scheduler = "0.57"
5354
log = "0.4"
5455
murmur3 = "0.5"
5556
num = "0.4"

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3.3"
2+
3+
#
4+
# This docker-compose file is used to start the services for local testing.
5+
# It starts a evm-blockchain-extractor connected to a local postgres database.
6+
#
7+
8+
services:
9+
10+
db:
11+
image: "postgres:11-alpine"
12+
ports:
13+
- "5432:5432"
14+
environment:
15+
POSTGRES_PASSWORD: postgres
16+
POSTGRES_USER: postgres
17+
18+
19+
extractor:
20+
image: ghcr.io/bitfinity-network/evm-block-extractor:main
21+
# image: "evm-block-extractor:latest"
22+
# build:
23+
# dockerfile: ./src/evm-block-extractor/Dockerfile
24+
ports:
25+
- "8080:8080"
26+
command: --rpc-url https://testnet.bitfinity.network --postgres --username postgres --password postgres --database-name postgres --database-url db

src/evm-block-extractor/Cargo.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ name = "evm-block-extractor"
33
version = "0.1.0"
44
edition = "2021"
55

6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7-
8-
[[bin]]
9-
name = "evm-block-extractor"
10-
path = "src/bin/extractor.rs"
11-
12-
[[bin]]
13-
name = "evm-block-extractor-server"
14-
path = "src/bin/server.rs"
156

167
[dependencies]
178
anyhow = { workspace = true }
@@ -24,8 +15,8 @@ ethers-core = { workspace = true }
2415
futures = { workspace = true }
2516
gcp-bigquery-client = { workspace = true }
2617
hex = { workspace = true }
27-
itertools = { workspace = true }
2818
jsonrpsee = { workspace = true }
19+
lightspeed_scheduler = { workspace = true }
2920
log = { workspace = true }
3021
serde = { workspace = true }
3122
serde_json = { workspace = true }
@@ -34,6 +25,7 @@ tokio = { workspace = true }
3425
yup-oauth2 = { workspace = true }
3526
zip = { workspace = true }
3627

28+
3729
[dev-dependencies]
3830
jsonrpc-core = { workspace = true }
3931
port_check = { workspace = true }

src/evm-block-extractor/Dockerfile

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
1-
FROM lukemathwalker/cargo-chef:latest-rust-1.75 as chef
1+
#
2+
# This dockerfile has to be called from the root folder of the project
3+
# > docker build -f src/evm-block-extractor/Dockerfile -t evm-block-extractor .
4+
#
5+
FROM rust:slim-bookworm as builder
26
WORKDIR /app
37

4-
FROM chef as planner
5-
COPY ../../ .
8+
ADD . .
69

7-
RUN cargo chef prepare --recipe-path recipe.json
8-
9-
FROM chef as builder
10-
COPY --from=planner /app/recipe.json recipe.json
11-
RUN cargo chef cook --release --recipe-path recipe.json
12-
13-
COPY . .
14-
RUN cargo build --release --bin evm-block-extractor-server
10+
RUN cargo build --release --bin evm-block-extractor
1511

1612
FROM debian:bookworm-slim AS runtime
1713

18-
# GCP BigQuery Environment Variables
19-
ARG DATASET
20-
ARG PROJECT_ID
21-
ARG GCP_BLOCK_EXTRACTOR_SA_KEY
22-
23-
# Set environment variables
24-
ENV DATASET=$DATASET \
25-
PROJECT_ID=$PROJECT_ID \
26-
GCP_BLOCK_EXTRACTOR_SA_KEY=$GCP_BLOCK_EXTRACTOR_SA_KEY
27-
2814
WORKDIR /app
15+
2916
RUN apt-get update -y \
3017
&& apt-get install -y --no-install-recommends ca-certificates \
3118
&& update-ca-certificates \
@@ -34,12 +21,9 @@ RUN apt-get update -y \
3421
&& apt-get clean -y \
3522
&& rm -rf /var/lib/apt/lists/*
3623

37-
COPY --from=builder /app/target/release/evm-block-extractor-server /app/evm-block-extractor-server
38-
39-
24+
COPY --from=builder /app/target/release/evm-block-extractor /app/evm-block-extractor
4025

4126
EXPOSE 8080
4227

43-
44-
CMD ./evm-block-extractor-server -s 0.0.0.0:8080 --bigquery -p $PROJECT_ID -d $DATASET
28+
ENTRYPOINT ["./evm-block-extractor"]
4529

src/evm-block-extractor/README.md

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,66 @@
1-
# EVM Block Extractor And Server
1+
# EVM Block Extractor
22

3-
## EVM Block Extractor
3+
## Introduction
44

5-
### Introduction
5+
The EVM block extractor is an advanced tool used to collect EVM blocks and transactions, and send them to a specified data storage.
6+
This version is enhanced to handle parallel requests efficiently and integrates with Google Cloud Platform's BigQuery service or Postgres.
67

7-
The EVM block extractor is an advanced tool used to collect EVM blocks and transactions, and send them to a specified BigQuery dataset endpoint. This version is enhanced to handle parallel requests efficiently and integrates with Google Cloud Platform's BigQuery service.
8+
## Configuration
89

9-
### Usage
10+
### Usage with BigQuery
1011

1112
```sh
1213
evm-block-extractor
14+
--server-address <server-address>
1315
--rpc-url <evmc-rpc-url>
14-
--dataset-id <bigquery-dataset-id>
1516
--max-number-of-requests <max-parallel-requests>
1617
--rpc-batch-size <rpc-batch-size>
18+
--bigquery
19+
--project-id <bigquery-project-id>
20+
--dataset-id <bigquery-dataset-id>
1721
--sa-key <service-account-key>
1822
```
1923

2024
Where:
2125

26+
- **server-address:** The address where the server will be hosted (default: 127.0.0.1:8080).
2227
- **rpc-url**: is the endpoint of the EVMC json-rpc url
23-
- **dataset-id**: is the BigQuery dataset id where the data will be sent
2428
- **max-number-of-requests**: is the maximum number of parallel requests to be sent to the EVMC json-rpc endpoint
2529
- **rpc-batch-size**: is the number of blocks to be requested in a single batch
30+
- **dataset-id**: is the BigQuery dataset id where the data will be sent
2631
- **sa-key**: the service account key in JSON format for GCP authentication.
2732

28-
### Output
2933

30-
The data is sent and stored in the specified BigQuery dataset. This allows for enhanced querying and analysis capabilities using BigQuery's features.
31-
32-
## EVM Block Extractor Server
33-
34-
### Introduction
35-
36-
The EVM block extractor server is a JSON-RPC server for the EVM block extractor. It is integrated with BigQuery and allows for querying the data stored in the BigQuery dataset.
37-
38-
### Usage
34+
### Usage with Postgres
3935

4036
```sh
41-
evm-block-extractor-server
42-
--dataset-id <bigquery-dataset-id>
37+
evm-block-extractor
4338
--server-address <server-address>
44-
--sa-key <service-account-key>
39+
--rpc-url <evmc-rpc-url>
40+
--max-number-of-requests <max-parallel-requests>
41+
--rpc-batch-size <rpc-batch-size>
42+
--postgres
43+
--username <postgres-db-username>
44+
--password <postgres-db-password>
45+
--database_name <postgres-db-name>
46+
--database_url <postgres-db-url>
47+
--database_port <postgres-db-port>
48+
--require_ssl <postgres-db-require-ssl>
4549
```
4650

4751
Where:
4852

49-
- **dataset-id**: The dataset ID of the BigQuery table.
50-
- **server-address:** The address where the server will be hosted (default: 127.0.0.1:8080).
51-
- **sa-key**: The service account key in JSON format for GCP authentication.
53+
- **username**: Username for the database connection
54+
- **password**: Password for the database connection
55+
- **database_name**: database name
56+
- **database_url**: database IP or URL
57+
- **database_port**: database port
58+
- **require_ssl**: whether to use ssl (true/false)
59+
5260

53-
### Endpoints
61+
## Endpoints
5462

55-
This is minimal version of the Ethereum JSON-RPC server. It supports the following endpoints:
63+
Th evm-block-extracor is also a minimal version of the Ethereum JSON-RPC server which supports the following endpoints:
5664

5765
- **eth_blockNumber**: Returns the number of most recent block.
5866
- **eth_getBlockByNumber**: Returns information about a block by block number.
@@ -62,5 +70,15 @@ This is minimal version of the Ethereum JSON-RPC server. It supports the followi
6270
### Example
6371

6472
```sh
65-
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://127.0.0.1:8080
73+
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://127.0.0.1:8080
6674
```
75+
76+
## Docker image
77+
78+
The evm-block-extractor docker image is a debian slim based image that allows for simple installation of the service.
79+
The docker image accepts the same configuration arguments of the plain executor.
80+
E.g.:
81+
```sh
82+
docker run ghcr.io/bitfinity-network/evm-block-extractor:main --rpc-url https://testnet.bitfinity.network --postgres --username postgres --password postgres --database-name postgres --database-url 127.0.0.1:5432
83+
```
84+

0 commit comments

Comments
 (0)