Skip to content

Commit 921593b

Browse files
committed
refactor fhevm cli runtime model
1 parent c1876ff commit 921593b

File tree

88 files changed

+3170
-1530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3170
-1530
lines changed

test-suite/fhevm/ARCHITECTURE.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ flowchart TD
1010
B --> B2["latest-release: latest stable release"]
1111
B --> B3["sha: exact repo-owned SHA on main, fail if any package tag is missing or if it predates 803f104"]
1212
B --> B4["devnet/testnet/mainnet: GitOps bundles"]
13-
B1 --> C["Lock resolved bundle"]
13+
B1 --> C["apply *_VERSION env overrides"]
1414
B2 --> C
1515
B3 --> C
1616
B4 --> C
1717
18-
C --> E["3. generate runtime files under .fhevm"]
18+
C --> C1["Lock resolved bundle"]
19+
C1 --> C2["apply coprocessor scenario or --override coprocessor shorthand"]
20+
21+
C2 --> E["3. generate runtime files under .fhevm"]
1922
E --> E1["env/"]
2023
E --> E2["compose/"]
2124
E --> E3["locks/"]
@@ -36,8 +39,8 @@ flowchart TD
3639
F10 --> F11["14. relayer"]
3740
F11 --> F12["15. test-suite"]
3841
39-
G["Local overrides (group or runtime service)"] --> E
40-
H["Multicopro topology + per-instance overrides"] --> E
42+
G["Local overrides (group or runtime service)"] --> C2
43+
H["Scenario-driven coprocessor topology"] --> C2
4144
I["Compatibility policy"] --> E
4245
I --> F8
4346
@@ -71,8 +74,18 @@ the SHA-tagged images for every component built from the PR.
7174
- Version selection is explicit. The CLI does not silently use a vague "latest".
7275
- `latest-main` is modern-only by construction. If no complete bundle exists after the floor SHA, resolution fails.
7376
- The resolved bundle is printed and locked before the real boot continues.
77+
- Runtime precedence is fixed: bundle -> `*_VERSION` env overrides -> coprocessor scenario/shorthand -> generated runtime files.
7478
- `.fhevm` is the only mutable runtime area owned by the CLI.
79+
- Tracked inputs are split by role:
80+
- compose templates: `docker-compose/*.yml`
81+
- env templates: `templates/env/.env.*`
82+
- relayer template config: `templates/config/relayer.yaml`
83+
- static config: `static/config/kms-core/config.toml`, `static/config/prometheus/prometheus.yml`
84+
- scenario inputs: `scenarios/*.yaml`
85+
- `src/runtime-plan.ts` resolves the final coprocessor/runtime shape consumed by regeneration.
86+
- `src/render-env.ts`, `src/render-config.ts`, and `src/render-compose.ts` are the only rendering layers.
7587
- Discovery is not terminal output only. It feeds env regeneration before dependent services start.
7688
- Resume is step-based via `state.json`, not "rerun the bash ritual and hope".
77-
- `upgrade` is intentionally narrow: it only rebuilds and restarts active runtime override groups.
89+
- Tracked compose files are the default runtime truth. `.fhevm/compose` only contains generated overrides for coprocessor topology and active local-override components.
90+
- `upgrade` is intentionally narrow: it only rebuilds and restarts active runtime override groups or local coprocessor scenario instances.
7891
- `up --dry-run` exercises the same target-aware resolve and preflight path without mutating runtime state.

test-suite/fhevm/README.md

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It exists for three workflows:
66

77
- run a known stack target locally
88
- swap in local changes for one repo-owned group
9-
- run multicopro topologies with deterministic generated state
9+
- run consensus/matrix coprocessor scenarios with deterministic generated state
1010

1111
The CLI owns all mutable runtime state under `.fhevm/`. Tracked compose and env files stay as templates.
1212

@@ -30,13 +30,53 @@ bun test
3030

3131
- `up` resolves a target bundle, runs preflight, generates `.fhevm`, and boots the stack
3232
- `up --dry-run` runs the same resolve and preflight path without mutating runtime state
33+
- `up --scenario <file>` applies an explicit coprocessor consensus scenario on top of the resolved bundle
34+
- `up --override coprocessor` is the fast local-dev shorthand for a one-instance local coprocessor scenario
3335
- `test` runs against the current stack; it does not recompile contracts. `--parallel` runs tests in parallel (auto for `operators`)
3436
- `logs` follows container output; `--no-follow` prints the tail and exits
3537
- `pause` / `unpause` pauses or unpauses host or gateway contracts
3638
- `down` stops the stack
3739
- `clean` removes CLI-owned runtime state
3840
- `clean --images` also removes CLI-owned local override images
3941

42+
## Ownership Model
43+
44+
There are four kinds of inputs/runtime artifacts:
45+
46+
- tracked compose templates: `docker-compose/*.yml`
47+
- tracked env templates: `templates/env/.env.*`
48+
- tracked config:
49+
- relayer template input: `templates/config/relayer.yaml`
50+
- static mounted config: `static/config/kms-core/config.toml`, `static/config/prometheus/prometheus.yml`
51+
- tracked scenario inputs: `scenarios/*.yaml`
52+
53+
Generated runtime artifacts always live under `.fhevm/`:
54+
55+
- `.fhevm/env/*.env`
56+
- `.fhevm/compose/*.yml` for generated runtime overrides only
57+
- `.fhevm/config/relayer.yaml`
58+
- `.fhevm/addresses/*`
59+
- `.fhevm/locks/*`
60+
- `.fhevm/state.json`
61+
62+
Tracked compose files are the default runtime truth. `.fhevm/compose` only holds generated overrides when runtime structure or local-image policy actually changes, with coprocessor topology as the only structural expansion.
63+
64+
The code follows the same split:
65+
66+
- `src/runtime-plan.ts`: resolve one runtime plan from bundle + env overrides + scenario/shorthand
67+
- `src/render-env.ts`: render runtime env maps
68+
- `src/render-config.ts`: render generated config files
69+
- `src/render-compose.ts`: render compose overlays, with coprocessor topology as the only structural exception
70+
71+
## Resolution Order
72+
73+
Runtime resolution is intentionally fixed:
74+
75+
1. Resolve the base bundle from `--target`, `--sha`, or `--lock-file`
76+
2. Apply matching `*_VERSION` environment overrides
77+
3. Apply either `--scenario <file>` or the `--override coprocessor` shorthand
78+
4. Materialize generated env/config/compose state under `.fhevm/`
79+
4080
## Targets
4181

4282
- `latest-release`: latest stable fhevm release plus checked-in companion defaults
@@ -160,7 +200,7 @@ The matrix has four sections:
160200
| `externalDefaults` | Pinned versions for non-workspace components | modern relayer SHA |
161201
| `anchors` | Git history reference points | simple-ACL cutover commit |
162202

163-
CI workflows read these values via `./fhevm-cli compat-defaults` instead of hardcoding them.
203+
CI workflows read `externalDefaults` and `anchors` via `./fhevm-cli compat-defaults` instead of hardcoding them.
164204

165205
### How to update
166206

@@ -187,7 +227,7 @@ When the minimum supported version passes the threshold, delete the `legacyShims
187227
./fhevm-cli up --target latest-release --resume --from-step relayer
188228
./fhevm-cli up --target latest-release --override coprocessor
189229
./fhevm-cli up --target latest-release --override coprocessor:host-listener,tfhe-worker
190-
./fhevm-cli up --target latest-release --coprocessors 2 --threshold 2
230+
./fhevm-cli up --target latest-release --scenario ./scenarios/two-of-two.yaml
191231
./fhevm-cli upgrade coprocessor
192232

193233
./fhevm-cli status
@@ -222,6 +262,8 @@ Supported groups:
222262
./fhevm-cli up --target latest-release --override coprocessor
223263
```
224264

265+
For `coprocessor`, this is also the shorthand local-dev scenario: one coprocessor instance, threshold `1`, source mode `local`.
266+
225267
### Override specific runtime services
226268

227269
Runtime override groups also support per-service filtering:
@@ -284,27 +326,31 @@ If a runtime override is already active and you only want to rebuild and restart
284326
./fhevm-cli upgrade coprocessor
285327
```
286328

287-
`upgrade` only supports active runtime override groups: `coprocessor`, `kms-connector`, and `test-suite`. It rebuilds and restarts runtime services only; one-shot DB migration containers are not rerun.
329+
`upgrade` only supports active runtime override groups: `coprocessor`, `kms-connector`, and `test-suite`. For `coprocessor`, it rebuilds only the local coprocessor instances from the active shorthand/scenario state. One-shot DB migration containers are not rerun.
288330

289331
## Dropped Convenience Commands
290332

291333
- `smoke`: use explicit `up ...` plus `test ...`
292334
- `test debug`: use `docker exec -it fhevm-test-suite-e2e-debug sh`
293335

294-
## Multicopro
336+
## Coprocessor Scenarios
337+
338+
Use `--scenario <file>` for consensus and rollout matrices. The file is the source of truth for:
339+
340+
- coprocessor count and threshold
341+
- per-instance source mode: `inherit`, `registry`, or `local`
342+
- per-instance env overrides
343+
- per-instance runtime args
295344

296-
Example:
345+
Examples:
297346

298347
```sh
299-
./fhevm-cli up \
300-
--target latest-release \
301-
--coprocessors 2 \
302-
--threshold 2 \
303-
--instance-env 1:OTEL_SERVICE_NAME=coprocessor-1-local \
304-
--instance-arg '1:tfhe-worker=--coprocessor-fhe-threads=4'
348+
./fhevm-cli up --target latest-release --scenario ./scenarios/two-of-two.yaml
349+
./fhevm-cli up --target latest-release --scenario ./scenarios/one-registry-outlier.yaml
350+
./fhevm-cli up --target latest-release --scenario ./scenarios/one-local-outlier.yaml
305351
```
306352

307-
Generated env, compose overlays, addresses, locks, and state all live under `.fhevm/`.
353+
`--scenario` cannot be combined with `--override coprocessor`. Keep `--override coprocessor` for the fast local e2e loop; use scenarios when you need an explicit consensus matrix.
308354

309355
## Runtime State
310356

@@ -316,4 +362,4 @@ The CLI owns:
316362
- `.fhevm/compose/`
317363
- `.fhevm/addresses/`
318364

319-
`status` shows the active stack state and any CLI-owned local build images.
365+
`status` shows the active stack state, the active scenario origin when present, and any CLI-owned local build images.

test-suite/fhevm/bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-suite/fhevm/config/core-client/config.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.

test-suite/fhevm/docker-compose/coprocessor-docker-compose.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ services:
2626
cache_from:
2727
- ${FHEVM_CACHE_FROM_COPROCESSOR:-type=gha}
2828
env_file:
29-
- ../env/staging/.env.coprocessor.local
29+
- ../../../.fhevm/env/coprocessor.env
3030
environment:
3131
- KEY_ID=${FHE_KEY_ID}
3232
command:
@@ -45,7 +45,7 @@ services:
4545
cache_from:
4646
- ${FHEVM_CACHE_FROM_COPROCESSOR:-type=gha}
4747
env_file:
48-
- ../env/staging/.env.coprocessor.local
48+
- ../../../.fhevm/env/coprocessor.env
4949
command:
5050
- host_listener
5151
- --database-url=${DATABASE_URL}
@@ -68,7 +68,7 @@ services:
6868
cache_from:
6969
- ${FHEVM_CACHE_FROM_COPROCESSOR:-type=gha}
7070
env_file:
71-
- ../env/staging/.env.coprocessor.local
71+
- ../../../.fhevm/env/coprocessor.env
7272
command:
7373
- host_listener_poller
7474
- --database-url=${DATABASE_URL}
@@ -95,7 +95,7 @@ services:
9595
timeout: 5s
9696
retries: 3
9797
env_file:
98-
- ../env/staging/.env.coprocessor.local
98+
- ../../../.fhevm/env/coprocessor.env
9999
command:
100100
- gw_listener
101101
- --database-url=${DATABASE_URL}
@@ -124,7 +124,7 @@ services:
124124
cache_to:
125125
- ${FHEVM_CACHE_TO_COPROCESSOR:-type=gha,mode=max}
126126
env_file:
127-
- ../env/staging/.env.coprocessor.local
127+
- ../../../.fhevm/env/coprocessor.env
128128
command:
129129
- tfhe_worker
130130
- --run-bg-worker
@@ -149,7 +149,7 @@ services:
149149
cache_from:
150150
- ${FHEVM_CACHE_FROM_COPROCESSOR:-type=gha}
151151
env_file:
152-
- ../env/staging/.env.coprocessor.local
152+
- ../../../.fhevm/env/coprocessor.env
153153
command:
154154
- zkproof_worker
155155
- --database-url=${DATABASE_URL}
@@ -172,7 +172,7 @@ services:
172172
cache_from:
173173
- ${FHEVM_CACHE_FROM_COPROCESSOR:-type=gha}
174174
env_file:
175-
- ../env/staging/.env.coprocessor.local
175+
- ../../../.fhevm/env/coprocessor.env
176176
command:
177177
- sns_worker
178178
- --database-url=${DATABASE_URL}
@@ -207,7 +207,7 @@ services:
207207
cache_from:
208208
- ${FHEVM_CACHE_FROM_COPROCESSOR:-type=gha}
209209
env_file:
210-
- ../env/staging/.env.coprocessor.local
210+
- ../../../.fhevm/env/coprocessor.env
211211
command:
212212
- transaction_sender
213213
- --database-url=${DATABASE_URL}

test-suite/fhevm/docker-compose/core-docker-compose.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
container_name: kms-core
55
image: ghcr.io/zama-ai/kms/core-service:${CORE_VERSION}
66
env_file:
7-
- ../env/staging/.env.core.local
7+
- ../../../.fhevm/env/core.env
88
entrypoint:
99
- /bin/sh
1010
- -c
@@ -18,15 +18,11 @@ services:
1818
kms-server --config-file config/config.toml
1919
volumes:
2020
- fhevm_minio_secrets:/minio_secrets
21-
- ../config/kms-core/config.toml:/app/kms/core/service/config/config.toml
21+
- ../static/config/kms-core/config.toml:/app/kms/core/service/config/config.toml
2222
ports:
2323
- "50051:50051"
2424
healthcheck:
25-
test: "grpc_health_probe --addr=localhost:50051"
26-
interval: 1s
27-
timeout: 1s
28-
retries: 5
29-
start_period: 1s
25+
disable: true
3026

3127
volumes:
3228
fhevm_minio_secrets:

test-suite/fhevm/docker-compose/database-docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
- -c
99
- max_connections=500
1010
env_file:
11-
- ../env/staging/.env.database.local
11+
- ../../../.fhevm/env/database.env
1212
ports:
1313
- '5432:5432'
1414
healthcheck:

test-suite/fhevm/docker-compose/gateway-mocked-payment-docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
cache_to:
1111
- ${FHEVM_CACHE_TO_GATEWAY_DEPLOY_MOCKED_ZAMA_OFT:-type=gha,mode=max}
1212
env_file:
13-
- ../env/staging/.env.gateway-mocked-payment.local
13+
- ../../../.fhevm/env/gateway-mocked-payment.env
1414
command:
1515
- npx hardhat task:deployMockedZamaOFT
1616

@@ -26,9 +26,9 @@ services:
2626
cache_to:
2727
- ${FHEVM_CACHE_TO_GATEWAY_SET_RELAYER_MOCKED_PAYMENT:-type=gha,mode=max}
2828
env_file:
29-
- ../env/staging/.env.gateway-mocked-payment.local
29+
- ../../../.fhevm/env/gateway-mocked-payment.env
3030
command:
3131
- npx hardhat task:setTxSenderMockedPayment
3232
depends_on:
3333
gateway-deploy-mocked-zama-oft:
34-
condition: service_completed_successfully
34+
condition: service_completed_successfully

test-suite/fhevm/docker-compose/gateway-node-docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
container_name: gateway-node
44
image: ghcr.io/foundry-rs/foundry:v1.3.5
55
env_file:
6-
- ../env/staging/.env.gateway-node.local
6+
- ../../../.fhevm/env/gateway-node.env
77
entrypoint:
88
- anvil
99
- --block-time

test-suite/fhevm/docker-compose/gateway-pause-docker-compose.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ services:
1010
cache_to:
1111
- ${FHEVM_CACHE_TO_GATEWAY_SC_PAUSE:-type=gha,mode=max}
1212
env_file:
13-
- ../env/staging/.env.gateway-sc.local
13+
- ../../../.fhevm/env/gateway-sc.env
1414
command:
1515
- npx hardhat compile && npx hardhat task:pauseAllGatewayContracts
1616
volumes:
17-
- addresses-volume:/app/addresses # workdir in gateway's Dockerfile is /app
18-
19-
volumes:
20-
addresses-volume:
17+
- ../../../.fhevm/addresses/gateway:/app/addresses # workdir in gateway's Dockerfile is /app

0 commit comments

Comments
 (0)