Skip to content

Commit 78ec986

Browse files
authored
IA1.6.1 Add batcher service running in TEE (#205)
* a working script without args * a working script without args * everything works in the scripts despite the args * fix socat proxy script * working op-batcher inside docker-compose * rename the script to build batcher enclave image * cleanup and profile the op-batcher-non-tee * use port number from env and shorten nc listener timeout as it will not be used in most cases * fix dasel format * remove uneeded ESPRESSO_RUN_ENCLAVE_TESTS * fix scripts * Add op-batcher-tee image in CI (#210) * push op-batcher-tee image init * fix tag and push * test image creation without enclaver * try to use env * fix enclaver download * use env in docker images yml * restore other task * remove unneeded steps * special case to common case * use default for op-batcher and tee for op-batcher-tee * fix double ports mapping * fix batcher restart test * add a script to use enclave tool * works to some extend * also works for passing in arguments from cmd * try to upload the image * add my branch patter * fix dockerfile * a simplified version * adding packages/contracts-bedrock/forge-artifacts to op-batcher-enclave-target * PCR0 registered in op-batcher-tee docker compose and add monitor for enclave logs * copy deployment/ to op-batcher-enclave-target * fix docker-images * Remove unneeded script * remove unneeded script and cleanup readme * fix overlapping ports and move long cmd of op-batcher-tee to script * update readme
1 parent d08d6df commit 78ec986

File tree

8 files changed

+503
-22
lines changed

8 files changed

+503
-22
lines changed

.github/workflows/docker-images.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,58 @@ jobs:
348348
TARGET_BASE_IMAGE=alpine:3.22
349349
TARGETOS=linux
350350
TARGETARCH=amd64
351+
352+
build-op-batcher-tee:
353+
needs: prepare-deployment
354+
runs-on: ubuntu-latest
355+
permissions:
356+
contents: read
357+
packages: write
358+
steps:
359+
- name: Checkout
360+
uses: actions/checkout@v4
361+
362+
- name: Download deployment artifacts
363+
uses: actions/download-artifact@v4
364+
with:
365+
name: deployment-artifacts
366+
367+
- name: Copy config for op-batcher
368+
run: |
369+
mkdir -p packages/contracts-bedrock/lib/superchain-registry/ops/testdata/monorepo
370+
# Copy any required config files here, or create placeholder
371+
echo "Config prepared for op-batcher"
372+
373+
- name: Login to GitHub Container Registry
374+
uses: docker/login-action@v3
375+
with:
376+
registry: ${{ env.REGISTRY }}
377+
username: ${{ github.actor }}
378+
password: ${{ secrets.GITHUB_TOKEN }}
379+
380+
- name: Extract metadata
381+
id: meta
382+
uses: docker/metadata-action@v5
383+
with:
384+
images: ${{ env.IMAGE_PREFIX }}/op-batcher-tee
385+
tags: |
386+
type=ref,event=branch
387+
type=ref,event=pr
388+
type=sha,prefix={{branch}}-,enable={{is_default_branch}}
389+
type=raw,value=latest,enable={{is_default_branch}}
390+
type=raw,value=pr-${{ github.event.number }},enable=${{ github.event_name == 'pull_request' }}
391+
392+
- name: Build and push OP Batcher TEE
393+
uses: docker/build-push-action@v5
394+
with:
395+
context: .
396+
file: espresso/docker/op-stack/Dockerfile
397+
target: op-batcher-enclave-target
398+
platforms: linux/amd64
399+
push: true
400+
tags: ${{ steps.meta.outputs.tags }}
401+
labels: ${{ steps.meta.outputs.labels }}
402+
build-args: |
403+
TARGET_BASE_IMAGE=alpine:3.22
404+
TARGETOS=linux
405+
TARGETARCH=amd64

README_ESPRESSO.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ docker compose down -v --remove-orphans
303303
```console
304304
docker compose up --build -d
305305
```
306+
If you're on a machine with [AWS Nitro Enclaves enabled](#guide-setting-up-an-enclave-enabled-nitro-ec2-instance), use the `tee` profile instead to start the enclave batcher.
307+
```console
308+
COMPOSE_PROFILES=tee docker compose up --build -d
309+
```
306310

307311
* Run the services and check the log.
308312
```console

espresso/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ OPERATOR_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
3636

3737
L1_CHAIN_ID=11155111
3838
L2_CHAIN_ID=22266222
39+
40+
COMPOSE_PROFILES=default

espresso/docker-compose-op-geth.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,3 @@ services:
2020
L1_RPC: http://l1-geth:${L1_HTTP_PORT:?err}
2121
OP_HTTP_PORT: ${OP_HTTP_PORT:?err}
2222
OP_ENGINE_PORT: ${OP_ENGINE_PORT:?err}
23-
ports:
24-
- "${OP_HTTP_PORT}"
25-
- "${OP_ENGINE_PORT}"

espresso/docker-compose.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,29 @@ services:
142142
service: op-geth
143143
volumes:
144144
- op-data-seq:/data
145+
ports:
146+
- "${OP_HTTP_PORT}:${OP_HTTP_PORT}"
147+
- "${OP_ENGINE_PORT}:${OP_ENGINE_PORT}"
145148

146149
op-geth-verifier:
147150
extends:
148151
file: docker-compose-op-geth.yml
149152
service: op-geth
150153
volumes:
151154
- op-data-verifier:/data
155+
ports:
156+
- "8547:${OP_HTTP_PORT}"
157+
- "8553:${OP_ENGINE_PORT}"
152158

153159
op-geth-caff-node:
154160
extends:
155161
file: docker-compose-op-geth.yml
156162
service: op-geth
157163
volumes:
158164
- op-data-caff-node:/data
165+
ports:
166+
- "8548:${OP_HTTP_PORT}"
167+
- "8554:${OP_ENGINE_PORT}"
159168

160169
op-node-sequencer:
161170
build:
@@ -269,6 +278,7 @@ services:
269278
restart: "no"
270279

271280
op-batcher:
281+
profiles: ["default"]
272282
build:
273283
context: ../
274284
dockerfile: espresso/docker/op-stack/Dockerfile
@@ -304,7 +314,82 @@ services:
304314
- --max-channel-duration=1
305315
- --target-num-frames=1
306316

317+
# HTTP proxy for enclave Odyn proxy requirement
318+
http-proxy:
319+
image: alpine:latest
320+
command: >
321+
sh -c "
322+
apk add --no-cache tinyproxy &&
323+
echo 'Allow 127.0.0.1' >> /etc/tinyproxy/tinyproxy.conf &&
324+
echo 'Allow 0.0.0.0/0' >> /etc/tinyproxy/tinyproxy.conf &&
325+
echo 'DisableViaHeader Yes' >> /etc/tinyproxy/tinyproxy.conf &&
326+
tinyproxy -d
327+
"
328+
ports:
329+
- "3128:8888"
330+
networks:
331+
default:
332+
aliases:
333+
- proxy
334+
335+
op-batcher-tee:
336+
profiles: ["tee"]
337+
build:
338+
context: ../
339+
dockerfile: espresso/docker/op-stack/Dockerfile
340+
target: op-batcher-enclave-target
341+
image: op-batcher-tee:espresso
342+
healthcheck:
343+
test: ["CMD-SHELL", "test -f /tmp/enclave-tools.pid && kill -0 $(cat /tmp/enclave-tools.pid) 2>/dev/null || exit 1"]
344+
interval: 30s
345+
timeout: 10s
346+
retries: 3
347+
start_period: 60s
348+
depends_on:
349+
l1-geth:
350+
condition: service_healthy
351+
op-geth-sequencer:
352+
condition: service_started
353+
op-node-sequencer:
354+
condition: service_started
355+
espresso-dev-node:
356+
condition: service_started
357+
l2-genesis:
358+
condition: service_completed_successfully
359+
http-proxy:
360+
condition: service_started
361+
network_mode: "host"
362+
environment:
363+
http_proxy: http://127.0.0.1:3128
364+
HTTP_PROXY: http://127.0.0.1:3128
365+
OPERATOR_PRIVATE_KEY: ${OPERATOR_PRIVATE_KEY}
366+
ENCLAVE_DEBUG: ${ENCLAVE_DEBUG:-false}
367+
CONTAINER_MONITOR_INTERVAL: ${CONTAINER_MONITOR_INTERVAL:-1}
368+
ENCLAVE_MEMORY_MB: ${ENCLAVE_MEMORY_MB:-4096}
369+
ENCLAVE_CPU_COUNT: ${ENCLAVE_CPU_COUNT:-2}
370+
volumes:
371+
- /var/run/docker.sock:/var/run/docker.sock
372+
- ..:/source:ro
373+
- ./scripts/batcher-enclave-tool-image.sh:/app/espresso/scripts/batcher-enclave-tool-image.sh:ro
374+
- /tmp:/tmp
375+
privileged: true
376+
devices:
377+
- /dev/nitro_enclaves:/dev/nitro_enclaves
378+
restart: "no"
379+
command:
380+
- sh
381+
- -c
382+
- |
383+
export DEPLOYMENT_MODE=local
384+
export L1_RPC_URL="http://127.0.0.1:${L1_HTTP_PORT}"
385+
export L2_RPC_URL="http://127.0.0.1:${OP_HTTP_PORT}"
386+
export ROLLUP_RPC_URL="http://127.0.0.1:${ROLLUP_PORT}"
387+
export ESPRESSO_URL1="http://127.0.0.1:${ESPRESSO_SEQUENCER_API_PORT}"
388+
/source/espresso/docker/op-batcher-tee/run-enclave.sh
389+
390+
307391
op-proposer:
392+
profiles: ["default"]
308393
build:
309394
context: ../
310395
dockerfile: espresso/docker/op-stack/Dockerfile

0 commit comments

Comments
 (0)