ethereum-optimism / ethereum-optimism/optimism
opgeth-decoupling: own the log layer — op-service/log becomes the monorepo logging API
- Dominant language
- Go
- Stars
- 6.5k
- Forks
- 4k
- Avg merge
- 2d 38m
- Merged PRs (30d)
- 164
Description
Part of #21745 (§15 of the [op-geth decoupling doc](https://github.com/ethereum-optimism/optimism/blob/1657fbe391d3f37785a6a3609422ee79fe86d9fa/docs/ai/opgeth-decoupling.md#L416-L436)). **Blocks #20266.**
`op-service/log` becomes the monorepo's logging API: no monorepo Go file imports `go-ethereum/log`. This is better layering regardless of the decoupling — the fork's `Logger.SetContext`/`WriteCtx`/`LogAttrs`/`Trace…ErrorContext` extensions are just what forces it.
## Scope (measured at 1657fbe)
- **697** monorepo Go files import `github.com/ethereum/go-ethereum/log` — op-node 121, op-service 82, op-challenger 71, op-e2e 65, op-dispute-mon 48, op-test-sequencer 42, op-devstack 37, op-chain-ops 36, op-deployer 33, op-supernode 27, op-batcher 21, op-conductor 20, and a long tail. (`superchain-registry/` is a submodule with its own Go module — out of scope, flagged to that team.)
- **63** of those import *both* `geth/log` and `oplog`, so they need symbol-level dedup, not a blind import rewrite.
- Only ~13 files use the fork's context extensions at all: [`op-service/testlog`](https://github.com/ethereum-optimism/optimism/blob/1657fbe391d3f37785a6a3609422ee79fe86d9fa/op-service/testlog/testlog.go), [`op-service/log/logfilter`](https://github.com/ethereum-optimism/optimism/tree/1657fbe391d3f37785a6a3609422ee79fe86d9fa/op-service/log/logfilter), `op-service/tls/tlsinfo.go`, `op-devstack/devtest`, plus a handful of call sites. Phase 2 is therefore small; phase 1 is the bulk.
## PRs
1. **`op-service/log`: add the `oplog` logger surface.** `type Logger = log.Logger` (alias) plus re-exports of the package-level API actually in use: `New`, `NewLogger`, `Root`, `SetDefault`, `With`, `Info/Warn/Error/Debug/Trace/Crit`, the `Level*`/`Lvl*` constants, `LevelFromString`, `FromLegacyLevel`, `DiscardHandler`, `NewTerminalHandler[WithLevel]`, `JSONHandler`, `LogfmtHandlerWithLevel`, `Handler`. Migrate `op-service` itself as the first consumer.
2. **Tree-wide sweep + gate.** Rewrite the remaining ~615 files to `oplog`, dedup the 63 dual-import files, and add a lint/CI gate (golangci `depguard`, or a grep check) that fails any new `go-ethereum/log` import. Pure rename while the alias holds — zero behaviour change; build + test is the gate. Land fast to avoid rebase churn against everything in flight.
3. **Flip the alias to an owned interface** *(at cutover)*. Replace the alias with an interface — upstream's method set plus the context methods — over an `slog`-backed implementation. Do **not** copy upstream's LGPL `log` package; the context-extension logic is OP-authored and ports over. Our interface is a superset of upstream's, so an `oplog.Logger` still satisfies `log.Logger` wherever we hand one into geth code (e.g. the in-process L1 geth in op-e2e).
PRs 1–2 land now and are independent of the rest of the epic. PR 3 lands with or just before the go.mod flip.
## Acceptance criteria
- No monorepo Go file imports `go-ethereum/log`, enforced by a CI/lint gate.
- `op-service/log/logfilter` and `op-service/testlog` build on the owned API with unchanged behaviour.
- After PR 3, `op-service/log` has no `go-ethereum/log` dependency, and an `oplog.Logger` is still accepted by geth APIs taking `log.Logger`.
🤖 *Co-created with Claude Opus 5 (1M context)*
Contributor guide
Research direction
Start with op-service/log and migrate op-service first, then inspect the 63 files importing both go-ethereum/log and oplog. Read op-service/log/logfilter, op-service/testlog, and the listed context-extension call sites before the tree-wide sweep. Run the Go build and tests; done means no monorepo Go file imports go-ethereum/log and a lint or CI gate rejects new imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- ci-cd, tooling
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100