Skip to content

opgeth-decoupling: make op-service/sources the OP-aware eth client #20264

Closed

Description

@sebastianst

Part of #20257. See plan §3, §11 in the op-geth decoupling doc.

Goal

Under upstream go-ethereum, ethclient.BlockByNumber/BlockByHash/TransactionByHash on an L2 endpoint fail because the returned JSON contains deposit transactions (type 0x7E) that upstream's types.Transaction.UnmarshalJSON doesn't know. Extended Receipt fields (L1GasPrice, OperatorFeeScalar, etc.) silently drop. Solution: make op-service/sources the canonical OP-aware eth client; it already uses raw JSON-RPC so it can decode both.

Scope

op-service/sources — deposit-tx JSON decoding

  • op-service/sources/types.go — extend RPCBlock.Transactions JSON unmarshal to route type 0x7e to op-core/types.DepositTx and everything else to upstream types.Transaction.
  • Verify RPCBlock.Verify() still works (calls IsDepositTx() — switch to optypes.IsDepositTx).

apis.EthClient.TransactionReceipt — return *optypes.Receipt

  • op-service/apis/eth.go: change ReceiptFetcher.TransactionReceipt return type from *types.Receipt to *optypes.Receipt. Same for ReceiptsFetcher.FetchReceipts (return optypes.Receipts).
  • Implementation in op-service/sources (raw JSON-RPC) unmarshals into the extended type.
  • Downstream callers that only read standard fields continue to work because optypes.Receipt embeds types.Receipt.

op-batcher migration

  • op-batcher/batcher/driver.go L2Client interface (line ~77) and loadBlockIntoState (line ~320): stop using *ethclient.Client for L2 block fetches; use op-service/sources.EthClient (or a narrow interface it satisfies).
  • op-service/dial/ethclient_interface.go L2EndpointProvider.EthClient: return an apis.EthClient-shaped client instead of *ethclient.Client, or phase the interface out.

op-service/txinclude

  • The EL interface in op-service/txinclude/interfaces.go:44 returns *types.Receipt today. Change to *optypes.Receipt and wire the implementation through the updated sources client.
  • No ethclient changes needed in isthmus_cost_oracle.go — it reads contract storage via batch eth_call, not receipts.

Dependencies

Blocked on: #20262 (op-core/types.Receipt and DepositTx).

🤖 Generated by Claude Code

Activity

  1. sebastianst commented on Jun 15, 2026

    @sebastianst
    MemberAuthor

    🤖 Claude says: Design resolution for the L2 transaction representation (from the #21356 discussion). Recording it here since this issue owns "make op-service/sources the OP-aware eth client".

    No optypes.Transaction wrapper. Partition the L2 tx accessors by tx class instead. A go-ethereum-style Transaction+TxData wrapper would re-import the signer/hashing machinery the decoupling is trying to shed, for a list that is read typed-ly in very few places (the dominant L2-tx currency is already opaque []hexutil.Bytes via eth.ExecutionPayload). Where typed access is needed it's class-specific, and each class has a clean home type. So add to apis.EthClient (op-service/apis/eth.go):

    • InfoAndUserTxs(...) (eth.BlockInfo, types.Transactions, error) — excludes the synthetic OP types (0x7E deposits, 0x7D post-exec). The remainder are all standard Ethereum tx types, so the list is plain upstream types.Transactions and decodes fine post-cutover. Serves the dominant "skip deposits, operate on user txs" pattern (op-batcher DA estimation; most test iterators).
    • InfoAndDeposits(...) (eth.BlockInfo, []*optypes.DepositTx, error) — deposits as op-core structs.
    • InfoAndFirstDeposit(...) (eth.BlockInfo, *optypes.DepositTx, error) — header + first tx (the L1-info deposit) only, for hot paths. This is the shape prototyped by refactor(op-service/sources): minimal-fetch path for L2BlockRef and SystemConfig #20532 (HeaderAndFirstTx / BlockRefFromHeaderAndDeposit), which closed unmerged but established the pattern — revive it here.

    InfoAndTxsBy* stays unchanged for L1 (no OP tx types there). Internally RPCBlock keeps txs as raw per-tx bytes: the transactions-trie root recomputes directly from them (the trie leaf for a typed tx is its opaque MarshalBinary encoding), deposit/post-exec detection is a type-byte check, and the partitioned accessors decode each class on demand.

    Lagoon makes 0x7D routing load-bearing. PostExecTx is a canonical block tx in Lagoon (trailing sequencer-rebate tx), so a Lagoon+ block's tx list is [deposit(0x7E), …user txs…, optional post-exec(0x7D)]. Under upstream go-ethereum the full-list decode fails on both 0x7E and 0x7D; the accessors must route both out. InfoAndUserTxs excludes both; add an InfoAndPostExecTx-style accessor only if a consumer needs to read the rebate tx (most code only needs to exclude it).

    Full write-up in docs/ai/opgeth-decoupling.md §11 (updated in #21356).

    🤖 Generated by Claude Code

  2. sebastianst commented on Jul 20, 2026

    @sebastianst
    MemberAuthor

    🤖 Claude says: Design correction for the op-batcher migration (found while planning the implementation; approved by @sebastianst).

    op-batcher cannot migrate to InfoAndUserTxs — it goes payload-native instead. The earlier resolution assumed the batcher only iterates txs to filter deposits for DA estimation. That's incomplete: the fetched L2 block flows into channelMgr.AddL2Block → derive.BlockToSingularBatch, which

    1. requires txs[0] to be the L1-info deposit — it parses EpochNum/EpochHash/SequenceNumber out of its calldata (ErrNotDepositTx otherwise), and
    2. includes post-exec (0x7D) txs in batch content when SDM is active (derivation expects them in span batches).

    InfoAndUserTxs drops both classes, so it can't feed batch building. Instead the batcher fetches *eth.ExecutionPayloadEnvelope via the existing PayloadByNumber accessor: the payload's opaque []hexutil.Bytes txs are exactly the batch currency (deposit exclusion becomes a type-byte filter, bytes pass through verbatim), a new derive.PayloadToSingularBatch replaces BlockToSingularBatch (deleted), and derive.PayloadToBlockRef already exists for the block-ref metric. DA estimation (RawSize/EstimatedDABytes) computes value-identically from raw bytes. Batch-byte identity is pinned by parity tests.

    The partitioned accessors (InfoAndUserTxs / InfoAndDeposits / InfoAndFirstDeposit) are still added as specified — they serve the #20265 test migrations; they're just not the batcher's vehicle.

    Also surfaced during planning (consensus-critical for the receipts half): optypes.Receipts root derivation must hand-roll three OP arms — post-Canyon deposit receipts (nonce+version in the hash preimage), pre-Canyon deposit receipts (hashed without the nonce, deliberately diverging from MarshalBinary — see op-geth core/types/receipt.go:564-586), and 0x7D post-exec receipts (first-class typed receipts in op-geth). And FetchReceipts must derive tx hashes as keccak256(rawTx) rather than decoding typed txs, or L2 receipt fetching breaks at hash acquisition post-cutover.

    🤖 Generated by Claude Code (Claude Fable 5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions