レッスン3 — op-rbuilder を読む(Reth ベースの OP Stack sequencer)
問い
OP Stack chain を立ち上げると、sequencer のブロックは op-node が駆動する実行クライアント(op-geth か op-reth)が作る。外部の Rust builder を使うなら、Flashbots の OP Stack 向け Rust block builder flashbots/op-rbuilder を rollup-boost の後ろに置く。「Reth 上のブロック構築」のオープンソース参照実装で、マーケティング図解では見えない実際の sequencer が何をしているかを理解したければここを読む。
原理(最小モデル)
- 3 入力ストリーム. Engine API(コンセンサス側から「何の上に構築すべきか」)+ Mempool(pending user tx)+ L1 Inbox(必ず含める deposit tx)。
- OP Stack の 5 ルール. Deposit を先頭 / L1 epoch 帰属 / Sequencer 署名(P2P の unsafe ブロックのみ)/ Gas limit(L1 の system config)/ Force inclusion(= L1 deposit + sequencing window)。強制するのは各ノードの derivationで、builder ではない。
- Sequencer が「選べる」vs「選べない」. 選べる = ユーザ tx の選択 + 順序 + L1 epoch + timestamp(範囲内)。選べない = Deposit include 有無 + Block validity ルール。
- build_payload の 3 段. payload attributes の tx(deposit)を先に実行(
execute_sequencer_transactions)→ Mempool から gas limit まで(execute_best_transactions)→ Block seal(root 計算)。op-rbuilder は途中経過を flashblocks として配信。 - MEV 3 立場. Vanilla FIFO / Priority-fee 順序付け(OP Stack デフォルト)/ 外部 block building(rollup-boost + op-rbuilder、
eth_sendBundleで bundle 受付)。 - Pre-confirmation は単一 sequencer のキラー機能. 即時に「含める」と返せる。複数当事者では投票必要 → 難しい。op-rbuilder で最も近い実機能は flashblocks(1 ブロック時間内に部分ブロックを配信)。
- Pre-conf に reorg リスク. L2 reorg で tx が canonical から外れる、設計次第で sequencer slash。
具体例
op-rbuilder アーキテクチャ:
flowchart TB
EngineAPI["Engine API<br/>(rollup consensus から)"] -->|forkchoiceUpdated| Builder["Block Builder"]
Mempool["L2 Mempool"] -->|pending txs| Builder
L1Inbox["L1 deposits<br/>(op-node が attributes に入れる)"] -->|deposit tx| Builder
Builder -->|ブロック構築| EVM["revm<br/>(実行)"]
EVM -->|state 変更| State["State DB"]
Builder -->|署名ブロック| EngineAPI2["Engine API<br/>(getPayload レスポンス)"]
Builder -->|broadcast| P2P["P2P network<br/>(ノードに伝播)"]
OP Stack 順序付け 5 ルール:
- Deposit を先頭に: L1-attributes deposit と L1 origin の user deposit はブロック先頭
- L1 epoch 帰属: ブロックは L1 ブロック(「L1 origin」)を参照必須
- Sequencer 署名: L1 投稿前に P2P で配る「unsafe」ブロックは sequencer 鍵で署名。L1 から derivation するノードはこの署名を見ない
- Gas limit: L1 の system config で決まる(sequencer は決めない)
- Force inclusion: L1 deposit が force-inclusion 経路。sequencing window 内に batch が投稿されなければ、derivation がその L1 origin 用に deposit のみのブロックを作る
op-node が L1 origin を選び deposit を payload attributes に入れる。builder(op-reth のデフォルトか op-rbuilder)はその tx を先に実行する。ルールを強制するのは各ノードの derivation pipeline。
Sequencer が選べる / 選べない:
| 選べる | 選べない |
|---|---|
| どのユーザ tx を含めるか | Deposit を含めるかどうか(必須) |
| ユーザ tx の順序 | L1 deposit を飛ばすこと(derivation で必ず戻ってくる) |
| 帰属させる L1 epoch | Block validity ルール(gas limit / base fee 計算) |
| ブロック timestamp(範囲内) |
コアループ(簡略化した擬似コード。実際のシグネチャではない):
async fn build_payload(
attributes: PayloadAttributes,
parent: BlockHash,
state: StateProvider,
pool: TxPool,
) -> eyre::Result<ExecutionPayload> {
let mut block_env = BlockEnv::from(parent, attributes);
let mut executor = Executor::new(state, &block_env);
let mut included_txs = Vec::new();
// 1. op-node が attributes に入れた tx を実行 (L1-attributes deposit + user deposit)
for sequencer_tx in attributes.transactions {
executor.execute(&sequencer_tx)?;
included_txs.push(sequencer_tx);
}
// (attributes.no_tx_pool なら op-node はこの tx だけを要求: 2 を飛ばす)
// 2. Gas limit までの mempool から pull
let pending = pool.best_pending();
for tx in pending {
if executor.gas_used() + tx.gas_limit() > block_env.gas_limit {
break;
}
match executor.execute(&tx) {
Ok(_) => included_txs.push(tx),
Err(_) => continue, // 失敗 tx スキップ
}
}
// 3. ブロック seal (root 計算)
let payload = ExecutionPayload {
header: build_header(&block_env, &executor, &included_txs),
transactions: included_txs,
};
Ok(payload)
}
op-rbuilder の主要パス(commit 4f1bec3、2026-09-24 時点。バージョンで揺れる):
| パス | 役割 |
|---|---|
crates/op-rbuilder/src/launcher.rs | OpNode に配線(.payload(FlashblocksServiceBuilder::new(...))) |
crates/op-rbuilder/src/builder/payload.rs | OpPayloadBuilder: try_build → build_payload → build_payload_inner(fallback ブロック → flashblocks) |
crates/op-rbuilder/src/builder/context.rs | execute_sequencer_transactions(attributes の tx、deposit 含む)/ execute_best_transactions(pool tx) |
crates/op-rbuilder/src/builder/best_txs.rs | pool の best tx の反復 |
crates/op-rbuilder/src/revert_protection.rs | eth_sendBundle / revert protection |
MEV 3 立場:
| 立場 | Sequencer がすること | 例 |
|---|---|---|
| Vanilla FIFO | 提出時刻順 | naive な実装 |
| Priority-fee 順序付け | ガスチップ順(Ethereum mainnet 系) | OP Stack デフォルト |
| 外部 block building | 外部 builder にブロックを作らせる | OP Stack + rollup-boost + op-rbuilder |
失敗例(誤解)
「Sequencer は何でもできる」— 半分間違い。「選べる」と「選べない」が明確に分かれる。Deposit / validity ルールは 必ず守る → 違反すれば L1 から derivation するノードが batch を拒否 → unsafe ブロックが reorg。「何でもできる」は UX レベル(順序 + 選択)のみ。
「Pre-confirmation はタダ」— 間違い。sequencer は inclusion をコミット → L2 reorg があれば tx が canonical chain から外れる可能性 → 設計次第で sequencer slash。reorg リスクと L1 challenge リスクを負う。
「FIFO が MEV 中立」— 間違い。FIFO でも提出 latency 優位 + toxic flow 被害が残る。中立は 設計選択、FIFO は中立に見えるが実は MEV 抽出経路を作る。
🛑 予測。 Sequencer は ~2s ごとにブロック生成必要。ボトルネックは実行速度(revm)かブロック構築(選択 + 順序付け)?(答え: ブロック構築 > 実行速度。revm 自体は 数十 ms で 数千 tx 実行可能。ボトルネックは ① mempool から「最良」tx を選ぶ heuristic + ② 構築中に新 tx が到着する非同期性 + ③ 新しい forkchoice が来たときの中断・再構築 + ④ state root 計算。op-rbuilder の工夫(flashblocks、cancellation、incremental state root)は主に 構築側 にある。)
ステップで組み立てる
Step 1: 3 入力ストリーム
Engine API(op-node)+ Mempool(user tx)+ L1 deposit(op-node が attributes に入れる)。
Step 2: OP Stack 5 順序付けルール
Deposit 先頭 / L1 epoch 帰属 / Sequencer 署名(unsafe ブロック)/ Gas limit(system config)/ Force inclusion(deposit + sequencing window)。
Step 3: 「選べる」vs「選べない」を区別
選べる = UX 自由度(tx 選択 + 順序 + epoch + timestamp)/ 選べない = derivation が強制(deposit + validity)。
Step 4: build_payload 3 段を辿る
attributes の tx(deposit)→ Mempool(gas limit まで)→ Seal。
Step 5: MEV 3 立場を判別
Vanilla FIFO / Priority-fee / Builder market。chain の MEV policy は source code に現れる。
Step 6: Pre-confirmation の仕組みとリスク
単一 sequencer の即時応答 → 早い「含まれた」表示 → reorg リスク(tx が canonical から外れる、設計次第で slash)。op-rbuilder では flashblocks が最も近い。
答え合わせ
- 「選べない」を違反すると起きること: L1 から derivation するノード(op-node など)が batch を invalid と判定 → unsafe ブロックが reorg → 違反ブロックが canonical から削除。ルールは L1 データからの derivation で強制、sequencer が回避できない。
- Pre-conf を発行する sequencer のリスク: ① L2 reorg(稀でも起こりうる、parent が変わる場合)→ tx が canonical から外れる → ユーザ「confirmed」を見たのに含まれない、② 設計次第で sequencer が slash(pre-conf 違反として on-chain 罰)+ ③ 評判ダメージ。100ms confirmed の代価。
- MEV 3 立場の source code 現れ方: ① Vanilla FIFO = 到着順に取り出す(順序付け hook なし、擬似コード)、② Priority-fee = reth の
TransactionPool::best_transactions()(gas tip ソート)、③ 外部 block building = rollup-boost の設定 + op-rbuilder のeth_sendBundle(--builder.enable-revert-protection時のみ有効、docs/eth_sendBundle.md)。コードと設定を読む = MEV policy を読む。
合格基準
- 3 入力ストリームを即答できる。
- OP Stack 5 ルールと、それを強制するのが derivation であることを言える。
- 「選べる」vs「選べない」を 4 項目ずつ言える。
- build_payload 3 段を辿れる。
- MEV 3 立場を source code パターンで判別できる。
まとめ(3行)
- op-rbuilder = Flashbots の OP Stack 向け Rust block builder(Reth SDK + op-reth、rollup-boost 経由で sequencer が使う)。3 入力(Engine API / Mempool / L1 deposit)+ build_payload 3 段 + flashblocks。
- Sequencer が「選べる」(UX 自由度)と「選べない」(derivation が強制)を区別 — 違反は batch 拒否で unsafe ブロックが reorg。
- Pre-confirmation は単一 sequencer のキラー機能(op-rbuilder では flashblocks が最も近い)だが reorg リスク、MEV 3 立場(Vanilla FIFO / Priority-fee / Builder market)は source code に現れる。