Skip to content

Commit 11ca3ec

Browse files
committed
feat: implement scheduler and clean up runtime/bootstrap flow
1 parent 4b923cd commit 11ca3ec

87 files changed

Lines changed: 8513 additions & 6253 deletions

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ jobs:
1313
- name: Checkout
1414
uses: actions/checkout@v4
1515

16+
- name: Install system dependencies
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y \
20+
lua5.4 \
21+
liblua5.4-dev \
22+
libslirp-dev
23+
1624
- name: Install Rust toolchain
1725
uses: dtolnay/rust-toolchain@stable
1826
with:
@@ -37,4 +45,4 @@ jobs:
3745

3846
- name: Test
3947
timeout-minutes: 15
40-
run: cargo test --workspace --all-targets --all-features --locked
48+
run: RUN_ANVIL_TESTS=1 cargo test --workspace --all-targets --all-features --locked

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ sequencer.db
33
sequencer.db-shm
44
sequencer.db-wal
55
benchmarks/results/
6+
/benchmarks/.deps/
7+
/examples/canonical-app/out/
8+
/out/
9+
/.DS_Store

AGENTS.md

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Build and evolve a **sequencer prototype** for a future DeFi stack.
88

99
Current scope is intentionally small: a **dummy wallet app** that supports:
1010
- `Transfer`
11-
- `Deposit`
1211
- `Withdrawal`
1312

1413
Primary objective in this phase: make sequencer behavior, safety checks, and persistence reliable before adding "real world" execution logic.
@@ -26,36 +25,42 @@ Primary objective in this phase: make sequencer behavior, safety checks, and per
2625
## Glossary
2726

2827
- `chunk`: small bounded list of user ops processed/executed and persisted together to amortize SQLite cost and keep low-latency ack behavior.
29-
- `frame`: canonical ordering boundary that contains user ops plus a `drain_n` decision for direct-input execution.
28+
- `frame`: canonical ordering boundary that commits a `safe_block` plus a list of user ops; canonical execution drains all direct inputs safe at that block before executing the frame’s user ops.
3029
- `batch`: list of frames that will be posted on-chain as one unit.
3130
- `inclusion lane`: the hot-path single-lane loop that dequeues user ops, executes app logic, persists ordering, and rotates frame/batch boundaries.
3231

3332
## Architecture Map
3433

35-
- `sequencer/src/main.rs`: process bootstrap, env config, queue wiring, HTTP server.
36-
- `sequencer/src/api/mod.rs`: `POST /tx` and `GET /ws/subscribe` endpoints (tx ingress + replay broadcaster).
34+
- `sequencer/src/main.rs`: thin binary entrypoint.
35+
- `sequencer/src/lib.rs`: public sequencer API (`run`, `RunConfig`).
36+
- `sequencer/src/config.rs`: runtime input parsing and EIP-712 domain construction.
37+
- `sequencer/src/runtime.rs`: bootstrap and runtime wiring.
38+
- `sequencer/src/api/mod.rs`: `POST /tx` and `GET /ws/subscribe` endpoints (tx ingress + replay feed).
3739
- `sequencer/src/api/error.rs`: API error model + HTTP mapping.
3840
- `sequencer/src/inclusion_lane/mod.rs`: inclusion-lane exports and public surface.
3941
- `sequencer/src/inclusion_lane/lane.rs`: batched execution/commit loop (single lane).
4042
- `sequencer/src/inclusion_lane/types.rs`: inclusion-lane queue item and pipeline error types.
4143
- `sequencer/src/inclusion_lane/error.rs`: inclusion-lane runtime and catch-up error types.
42-
- `sequencer/src/l2_tx_broadcaster/mod.rs`: centralized ordered-L2Tx poller + live fanout to WS subscribers.
44+
- `sequencer/src/input_reader/`: safe-input ingestion from InputBox into SQLite.
45+
- `sequencer/src/l2_tx_feed/mod.rs`: DB-backed ordered-L2Tx feed used by WS subscriptions.
4346
- `sequencer/src/storage/mod.rs`: DB open, migrations, frame persistence, and direct-input broker APIs.
4447
- `sequencer/src/storage/migrations/`: DB schema/bootstrapping (`0001`).
4548
- `sequencer-core/src/`: shared domain types/interfaces (`Application`, `SignedUserOp`, `SequencedL2Tx`, broadcast message model).
4649
- `examples/app-core/src/application/mod.rs`: wallet prototype implementing `Application`.
47-
- `examples/canonical-app/src/main.rs`: placeholder canonical scheduler binary entrypoint.
50+
- `benchmarks/src/`: benchmark harnesses and self-contained benchmark runtime.
4851

4952
## Domain Truths (Important)
5053

5154
- This is a **sequencer prototype**, not a full DeFi stack yet.
5255
- API validates signature and enqueues signed `UserOp`; method decoding happens during application execution.
56+
- Deposits are direct-input-only (L1 -> L2) and must not be represented as user ops.
5357
- Rejections (`InvalidNonce`, fee cap too low, insufficient gas balance) produce no state mutation and are not persisted.
5458
- Included txs are persisted as frame/batch data in `batches`, `frames`, `user_ops`, `direct_inputs`, and `sequenced_l2_txs`.
5559
- Frame fee is persisted in `frames.fee` and is fixed for the lifetime of that frame.
5660
- The next frame fee is sampled from `recommended_fees` when rotating to a new frame (default bootstrap value is `0`).
57-
- `/ws/subscribe` has soft operational guardrails: subscriber cap (`SEQ_WS_MAX_SUBSCRIBERS`, default `64`) and catch-up cap (`SEQ_WS_MAX_CATCHUP_EVENTS`, default `50000`).
61+
- `/ws/subscribe` currently has internal guardrails: subscriber cap `64`, catch-up cap `50000`.
5862
- Wallet state (balances/nonces) is in-memory right now (not persisted).
63+
- EIP-712 domain name/version are fixed in code; chain ID and verifying contract are deployment-specific inputs.
5964

6065
## Hot-Path Invariants
6166

@@ -69,7 +74,7 @@ Primary objective in this phase: make sequencer behavior, safety checks, and per
6974

7075
- Storage model is append-oriented; avoid mutable status flags for open/closed entities.
7176
- Open batch/frame are derived by “latest row” convention.
72-
- `drain_n` is derivable from `sequenced_l2_txs` by counting direct-input rows per frame.
77+
- A frame’s leading direct-input prefix is derivable from `sequenced_l2_txs` plus `frames.safe_block`.
7378
- Safe cursor/head values should be derived from persisted facts when possible, not duplicated as mutable fields.
7479
- Replay/catch-up must use persisted ordering plus persisted frame fee (`frames.fee`) to mirror inclusion semantics.
7580
- Included user-op identity is constrained by `UNIQUE(sender, nonce)`.
@@ -101,38 +106,22 @@ cargo fmt --all
101106
cargo clippy --all-targets --all-features -- -D warnings
102107
```
103108

104-
Run server (defaults shown):
109+
Run server:
105110

106111
```bash
107-
SEQ_HTTP_ADDR=127.0.0.1:3000 \
108-
SEQ_DB_PATH=sequencer.db \
112+
SEQ_ETH_RPC_URL=http://127.0.0.1:8545 \
113+
SEQ_DOMAIN_CHAIN_ID=31337 \
114+
SEQ_DOMAIN_VERIFYING_CONTRACT=0x1111111111111111111111111111111111111111 \
109115
cargo run -p sequencer
110116
```
111117

112-
Key env vars:
118+
Optional env vars:
113119
- `SEQ_HTTP_ADDR`
114120
- `SEQ_DB_PATH`
115-
- `SEQ_QUEUE_CAP`
116-
- `SEQ_OVERLOAD_MAX_INFLIGHT_SUBMISSIONS`
117-
- `SEQ_MAX_USER_OPS_PER_CHUNK` (preferred)
118-
- `SEQ_MAX_BATCH` (legacy alias)
119-
- `SEQ_SAFE_DIRECT_BUFFER_CAPACITY`
120-
- `SEQ_MAX_BATCH_OPEN_MS`
121-
- `SEQ_MAX_BATCH_USER_OP_BYTES`
122-
- `SEQ_INCLUSION_LANE_IDLE_POLL_INTERVAL_MS` (preferred)
123-
- `SEQ_INCLUSION_LANE_TICK_INTERVAL_MS` (legacy alias)
124-
- `SEQ_COMMIT_LANE_TICK_INTERVAL_MS` (legacy alias)
125-
- `SEQ_BROADCASTER_IDLE_POLL_INTERVAL_MS`
126-
- `SEQ_BROADCASTER_PAGE_SIZE`
127-
- `SEQ_BROADCASTER_SUBSCRIBER_BUFFER_CAPACITY`
128-
- `SEQ_WS_MAX_SUBSCRIBERS`
129-
- `SEQ_WS_MAX_CATCHUP_EVENTS`
130-
- `SEQ_RUNTIME_METRICS_ENABLED`
131-
- `SEQ_RUNTIME_METRICS_LOG_INTERVAL_MS`
132-
- `SEQ_MAX_BODY_BYTES`
133-
- `SEQ_SQLITE_SYNCHRONOUS`
134-
- `SEQ_DOMAIN_NAME`
135-
- `SEQ_DOMAIN_VERSION`
121+
- `SEQ_LONG_BLOCK_RANGE_ERROR_CODES`
122+
123+
Required env vars:
124+
- `SEQ_ETH_RPC_URL`
136125
- `SEQ_DOMAIN_CHAIN_ID`
137126
- `SEQ_DOMAIN_VERIFYING_CONTRACT`
138127

@@ -178,6 +167,12 @@ Focus tests on:
178167

179168
If adding integration tests, prefer black-box tests around `POST /tx` and commit outcomes.
180169

170+
Some `sequencer` tests use Anvil and are opt-in locally:
171+
172+
```bash
173+
RUN_ANVIL_TESTS=1 cargo test -p sequencer --lib
174+
```
175+
181176
## Definition of Done for Agent Changes
182177

183178
Before finishing, ensure:

0 commit comments

Comments
 (0)