Skip to content

Commit eea1d77

Browse files
authored
Merge of #2196
2 parents ffe80f4 + a84c945 commit eea1d77

File tree

6 files changed

+277
-11
lines changed

6 files changed

+277
-11
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ test-suite/gateway-stress/Dockerfile @zama-ai/fhevm-devs
1515
/host-contracts/ @zama-ai/fhevm-gateway
1616
/library-solidity/ @zama-ai/fhevm-gateway
1717
/kms-connector/ @zama-ai/mpc-devs @dartdart26
18+
/relayer/ @zama-ai/fhevm-gateway
1819

1920
# Coprocessor Team ownership
2021
/coprocessor/ @zama-ai/fhevm-coprocessor
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: relayer-dependency-analysis
2+
3+
permissions: {}
4+
5+
on:
6+
pull_request:
7+
8+
concurrency:
9+
group: fhevm-relayer-deps-analysis-${{ github.ref }}
10+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
11+
12+
jobs:
13+
check-changes:
14+
name: relayer-dependency-analysis/check-changes
15+
permissions:
16+
actions: 'read' # Required to read workflow run information
17+
contents: 'read' # Required to checkout repository code
18+
pull-requests: 'read' # Required to read pull request information
19+
runs-on: ubuntu-latest
20+
outputs:
21+
changes-rust-files: ${{ steps.filter.outputs.rust-files }}
22+
steps:
23+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
persist-credentials: 'false'
26+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
27+
id: filter
28+
with:
29+
filters: |
30+
rust-files:
31+
- .github/workflows/relayer-dependency-analysis.yml
32+
- relayer/**
33+
dependencies-check:
34+
name: relayer-dependency-analysis/dependencies-check (bpr)
35+
needs: check-changes
36+
if: ${{ needs.check-changes.outputs.changes-rust-files == 'true' }}
37+
permissions:
38+
contents: 'read' # Required to checkout repository code
39+
checks: 'write' # Required to create GitHub checks for test results
40+
runs-on: ubuntu-latest
41+
steps:
42+
43+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
44+
with:
45+
persist-credentials: 'false'
46+
47+
- name: Setup Rust toolchain file
48+
run: cp relayer/rust-toolchain.toml .
49+
50+
- name: Rust setup
51+
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
52+
53+
- name: Install cargo-binstall
54+
uses: cargo-bins/cargo-binstall@84ca29d5c1719e79e23b6af147555a8f4dac79d6 # v1.10.14
55+
56+
- name: Install cargo tools
57+
run: |
58+
cargo binstall --no-confirm --force \
59+
cargo-audit@0.22.0 \
60+
cargo-deny@0.16.2
61+
62+
- name: Check that Cargo.lock is the source of truth
63+
run: |
64+
cd relayer
65+
cargo update -w --locked || (echo "Error: Cargo.lock is out of sync. Please run 'cargo update' locally and commit changes" && exit 1)
66+
67+
- name: License whitelist
68+
run: |
69+
cd relayer
70+
cargo-deny deny check license --deny license-not-encountered
71+
72+
- name: Security issue whitelist
73+
run: |
74+
cd relayer
75+
cargo-audit audit
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
name: relayer-test
2+
3+
# NOTE: could be parametrized with which package to test when we have a specific transaction manager different from the relayer itself.
4+
5+
on:
6+
pull_request:
7+
8+
permissions: {}
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.head_ref }}
12+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
13+
14+
jobs:
15+
check-changes:
16+
name: relayer-test/check-changes
17+
permissions:
18+
actions: 'read' # Required to read workflow run information
19+
contents: 'read' # Required to checkout repository code
20+
pull-requests: 'read' # Required to read pull request information
21+
runs-on: ubuntu-latest
22+
outputs:
23+
changes-rust-files: ${{ steps.filter.outputs.rust-files }}
24+
steps:
25+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
with:
27+
persist-credentials: 'false'
28+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
29+
id: filter
30+
with:
31+
filters: |
32+
rust-files:
33+
- .github/workflows/relayer-tests.yaml
34+
- relayer/**
35+
36+
unit-test:
37+
name: relayer-test/unit-test (bpr)
38+
needs: check-changes
39+
if: ${{ needs.check-changes.outputs.changes-rust-files == 'true' }}
40+
permissions:
41+
contents: 'read' # Required to checkout repository code
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout Project
45+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
46+
with:
47+
persist-credentials: false
48+
token: ${{ secrets.BLOCKCHAIN_ACTIONS_TOKEN }}
49+
submodules: recursive
50+
51+
- name: Setup Rust toolchain file
52+
run: cp relayer/rust-toolchain.toml .
53+
54+
- name: Rust setup
55+
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
56+
57+
- name: Cache Rust dependencies and build artifacts
58+
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
59+
with:
60+
workspaces: relayer
61+
key: rust-build-relayer
62+
cache-targets: true
63+
cache-all-crates: true
64+
65+
- name: Format
66+
working-directory: relayer
67+
run: cargo fmt --all -- --check
68+
69+
- name: Build for tests (no rpc mock)
70+
working-directory: relayer
71+
run: cargo test --no-run --lib
72+
73+
- name: Unit tests
74+
working-directory: relayer
75+
run: RUST_BACKTRACE=full make test-unit
76+
77+
clippy:
78+
name: relayer-test/clippy (bpr)
79+
needs: check-changes
80+
if: ${{ needs.check-changes.outputs.changes-rust-files == 'true' }}
81+
permissions:
82+
contents: 'read' # Required to checkout repository code
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Checkout Project
86+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
87+
with:
88+
persist-credentials: false
89+
token: ${{ secrets.BLOCKCHAIN_ACTIONS_TOKEN }}
90+
submodules: recursive
91+
92+
- name: Setup Rust toolchain file
93+
run: cp relayer/rust-toolchain.toml .
94+
95+
- name: Setup Rust
96+
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
97+
98+
- name: Cache Rust dependencies
99+
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
100+
with:
101+
workspaces: relayer
102+
key: rust-build-relayer
103+
104+
- name: Clippy
105+
working-directory: relayer
106+
run: cargo clippy -- -D warnings
107+
108+
integration-test:
109+
name: relayer-test/integration-test (bpr)
110+
needs: check-changes
111+
if: ${{ needs.check-changes.outputs.changes-rust-files == 'true' }}
112+
permissions:
113+
contents: 'read' # Required to checkout repository code
114+
runs-on: ubuntu-latest
115+
services:
116+
postgres:
117+
image: cgr.dev/zama.ai/postgres:17.9@sha256:d42847b7c5f9ece73655164588b2387dcd5fadd618ea64761c19d3484498cef0
118+
credentials:
119+
username: ${{ secrets.CGR_USERNAME }}
120+
password: ${{ secrets.CGR_PASSWORD }}
121+
env:
122+
POSTGRES_USER: postgres
123+
POSTGRES_PASSWORD: postgres
124+
POSTGRES_DB: relayer_db
125+
ports:
126+
- 5432
127+
options: >-
128+
--health-cmd "pg_isready -U postgres -d relayer_db"
129+
--health-interval 10s
130+
--health-timeout 5s
131+
--health-retries 5
132+
133+
env:
134+
SQLX_OFFLINE: true # Use cached queries for compilation (speeds up CI)
135+
APP_GLOBAL__MOCK_TEST: true
136+
DB_USER: postgres
137+
DB_PASSWORD: postgres
138+
DB_NAME: relayer_db
139+
140+
steps:
141+
- name: Checkout Project
142+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
143+
with:
144+
persist-credentials: false
145+
token: ${{ secrets.BLOCKCHAIN_ACTIONS_TOKEN }}
146+
submodules: recursive
147+
148+
- name: Set database URLs
149+
env:
150+
DB_PORT: ${{ job.services.postgres.ports['5432'] }}
151+
run: |
152+
{
153+
echo "DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}"
154+
echo "APP_STORAGE__SQL_DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}"
155+
echo "TEST_DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}"
156+
} >> "$GITHUB_ENV"
157+
158+
- name: Setup Rust toolchain file
159+
run: cp relayer/rust-toolchain.toml .
160+
161+
- name: Setup Rust
162+
uses: dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
163+
164+
- name: Cache Rust dependencies and build artifacts
165+
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
166+
with:
167+
workspaces: relayer
168+
key: rust-build-relayer
169+
cache-targets: true
170+
cache-all-crates: true
171+
172+
- name: Install SQLx CLI
173+
run: |
174+
if ! command -v sqlx &> /dev/null; then
175+
echo "Installing sqlx-cli..."
176+
cargo install sqlx-cli --no-default-features --features postgres
177+
else
178+
echo "sqlx-cli found in cache."
179+
fi
180+
181+
- name: Migrate Database
182+
working-directory: relayer/relayer-migrate
183+
run: sqlx migrate run
184+
185+
- name: Run tests
186+
working-directory: relayer
187+
run: RUST_BACKTRACE=full make test-run

relayer/LOGGING_POLICY.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ How we handle logging and correlation in the relayer's event-driven architecture
44

55
The relayer processes jobs through async flows: HTTP requests trigger blockchain transactions, then gateway events complete the cycle. Correlation IDs track these flows end-to-end.
66

7-
**Applies to:** `apps/relayer/src/`
7+
**Applies to:** `src/`
88

99
**Notation:**
1010
- **For developers** - Sections for human understanding and implementation
@@ -309,18 +309,18 @@ subscription active) remain **INFO**. Reconnects and dropped subscriptions remai
309309

310310
```bash
311311
# 1. No ERROR in non-boundaries (should find nothing)
312-
rg 'error!\(' apps/relayer/src/core/
313-
rg 'error!\(' apps/relayer/src/store/sql/repositories/ --glob '!cron_task.rs'
314-
rg 'error!\(' apps/relayer/src/orchestrator/
312+
rg 'error!\(' src/core/
313+
rg 'error!\(' src/store/sql/repositories/ --glob '!cron_task.rs'
314+
rg 'error!\(' src/orchestrator/
315315

316316
# 2. ERROR only in boundaries (should only find here)
317-
rg 'error!\(' apps/relayer/src/http/endpoints/
318-
rg 'error!\(' apps/relayer/src/gateway/ --glob '*_handler.rs'
319-
rg 'error!\(' apps/relayer/src/gateway/arbitrum/listener.rs
320-
rg 'error!\(' apps/relayer/src/store/sql/repositories/cron_task.rs
317+
rg 'error!\(' src/http/endpoints/
318+
rg 'error!\(' src/gateway/ --glob '*_handler.rs'
319+
rg 'error!\(' src/gateway/arbitrum/listener.rs
320+
rg 'error!\(' src/store/sql/repositories/cron_task.rs
321321

322322
# 3. No ext_job_id in gateway handlers (should find nothing)
323-
rg 'ext_job_id' apps/relayer/src/gateway/ --glob '*_handler.rs'
323+
rg 'ext_job_id' src/gateway/ --glob '*_handler.rs'
324324

325325
# 4. Structured logging - check for string interpolation in messages (code smell)
326326
# Look for patterns like: info!("Message {}", var) or error!("Error: {}", e)
@@ -346,4 +346,4 @@ When reviewing logs:
346346

347347
---
348348

349-
**Reference:** Logging primitives in `src/logging.rs` - Database schema in `apps/relayer/migrations/`
349+
**Reference:** Logging primitives in `src/logging.rs` - Database schema in `relayer-migrate/migrations/`

relayer/docs/SELF_HOSTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Running your own relayer gives you permissionless, independent access to the FHE
2727

2828
### Step-by-step
2929

30-
All commands run from `apps/relayer/`.
30+
All commands run from `relayer/`.
3131

3232
#### 1. Start the database
3333

relayer/rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.91.1"
3+
components = ["rustfmt", "clippy"]

0 commit comments

Comments
 (0)