Skip to content

Commit 3e7dcd9

Browse files
QuentinIOpenCode
andcommitted
op-batcher: integrate TEE batcher and Espresso submission loop
Add the Espresso TEE batcher write-path on top of the fallback batcher: - op-batcher/batcher/espresso.go: Espresso submission loop (peeks the channel manager, converts each L2 block to an EspressoBatch, submits it to Espresso, waits for inclusion, and then posts the batch txs to L1 with TEE-attested BatchAuthenticator.authenticateBatchInfo calls). - op-batcher/batcher/espresso_service.go: EspressoBatcherConfig, initEspresso (Espresso client / light-client construction, optional TEE attestation gathering), and the initChainSigner hook that wraps the txmgr into a opcrypto.ChainSigner. - op-batcher/batcher/espresso_helpers_test.go and espresso_transaction_submitter_test.go: unit tests for the helpers and the TEE transaction submitter. Extends the existing fallback wiring: - op-batcher/batcher/espresso_driver.go: adds EspressoDriverSetup fields (Client/LightClient/ChainSigner/SequencerAddress/Attestation), batcherL1Adapter, setupEspressoStreamer, startEspressoLoops, resetEspressoStreamer; extends dispatchAuthenticatedSendTx with the TEE branch (always authenticates when Espresso.Enabled). - op-batcher/batcher/espresso_active.go: adds isBatcherActive (queries BatchAuthenticator.activeIsEspresso to gate publishing against this batcher's role). - op-batcher/batcher/driver.go: extends DriverSetup with the Espresso EspressoDriverSetup field; adds espressoSubmitter / espressoStreamer / teeVerifierAddress / degradedLog fields on BatchSubmitter; calls setupEspressoStreamer in NewBatchSubmitter; branches StartBatchSubmitting on Espresso.Enabled to call startEspressoLoops; calls resetEspressoStreamer in clearState. - op-batcher/batcher/service.go: BatcherConfig.Espresso field; EspressoClient / EspressoLightClient / ChainSigner / Attestation runtime fields; initEspresso / initChainSigner / applyEspressoDriverSetup call-outs. - op-batcher/batcher/config.go: thread Espresso espresso.CLIConfig through CLIConfig. - op-batcher/flags/flags.go: register espresso.CLIFlags (TEE-only flags; the --espresso.fallback-auth-lead-time flag added by the fallback PR continues to live in op-batcher/flags/flags.go). Also adds op-service/log/repeat_state.go (RepeatStateLogger) and its test, used by the Espresso submission loop's tick-driven warnings. A safeTestRecorder helper is inlined into the test to avoid pulling in the unrelated debouncer. Adds the github.com/hf/nitrite dependency (transitively required by hf/nsm for attestation document parsing). Co-authored-by: OpenCode <noreply@opencode.ai>
1 parent 270aa45 commit 3e7dcd9

14 files changed

Lines changed: 2727 additions & 34 deletions

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ require (
3434
github.com/hashicorp/raft v1.7.3
3535
github.com/hashicorp/raft-boltdb/v2 v2.3.1
3636
github.com/hashicorp/raft-wal v0.4.2
37+
github.com/hf/nitrite v0.0.0-20241225144000-c2d5d3c4f303
3738
github.com/hf/nsm v0.0.0-20220930140112-cd181bd646b9
3839
github.com/holiman/uint256 v1.3.2
3940
github.com/ipfs/go-datastore v0.6.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ github.com/hashicorp/raft-boltdb/v2 v2.3.1 h1:ackhdCNPKblmOhjEU9+4lHSJYFkJd6Jqyv
425425
github.com/hashicorp/raft-boltdb/v2 v2.3.1/go.mod h1:n4S+g43dXF1tqDT+yzcXHhXM6y7MrlUd3TTwGRcUvQE=
426426
github.com/hashicorp/raft-wal v0.4.2 h1:DV1jgqEumNfdNpOaZ9mL1Gu7Mz59epFtiE6CoqnHrlY=
427427
github.com/hashicorp/raft-wal v0.4.2/go.mod h1:S92ainH+6fRuWk6BtZKJ8EgcGgNTKx48Hk5dhOOY1DM=
428+
github.com/hf/nitrite v0.0.0-20241225144000-c2d5d3c4f303 h1:XBSq4rXFUgD8ic6Mr7dBwJN/47yg87XpZQhiknfr4Cg=
429+
github.com/hf/nitrite v0.0.0-20241225144000-c2d5d3c4f303/go.mod h1:ycRhVmo6wegyEl6WN+zXOHUTJvB0J2tiuH88q/McTK8=
428430
github.com/hf/nsm v0.0.0-20220930140112-cd181bd646b9 h1:pU32bJGmZwF4WXb9Yaz0T8vHDtIPVxqDOdmYdwTQPqw=
429431
github.com/hf/nsm v0.0.0-20220930140112-cd181bd646b9/go.mod h1:MJsac5D0fKcNWfriUERtln6segcGfD6Nu0V5uGBbPf8=
430432
github.com/holiman/billy v0.0.0-20250707135307-f2f9b9aae7db h1:IZUYC/xb3giYwBLMnr8d0TGTzPKFGNTCGgGLoyeX330=

op-batcher/batcher/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ethereum/go-ethereum/params"
99
"github.com/urfave/cli/v2"
1010

11+
"github.com/ethereum-optimism/optimism/espresso"
1112
altda "github.com/ethereum-optimism/optimism/op-alt-da"
1213
"github.com/ethereum-optimism/optimism/op-batcher/compressor"
1314
"github.com/ethereum-optimism/optimism/op-batcher/config"
@@ -157,6 +158,10 @@ type CLIConfig struct {
157158
// authentication gate. See BatcherConfig.FallbackAuthLeadTime in
158159
// service.go and isFallbackAuthRequired in espresso_active.go.
159160
FallbackAuthLeadTime time.Duration
161+
162+
// Espresso groups all TEE-batcher-specific CLI flags. See
163+
// espresso/cli.go for the flag definitions.
164+
Espresso espresso.CLIConfig
160165
}
161166

162167
func (c *CLIConfig) Check() error {
@@ -254,6 +259,7 @@ func NewConfig(ctx *cli.Context) *CLIConfig {
254259
RPC: oprpc.ReadCLIConfig(ctx),
255260
AltDA: altda.ReadCLIConfig(ctx),
256261
FallbackAuthLeadTime: ctx.Duration(flags.FallbackAuthLeadTimeFlag.Name),
262+
Espresso: espresso.ReadCLIConfig(ctx),
257263
ThrottleConfig: ThrottleConfig{
258264
AdditionalEndpoints: ctx.StringSlice(flags.AdditionalThrottlingEndpointsFlag.Name),
259265
TxSizeLowerLimit: ctx.Uint64(flags.ThrottleTxSizeLowerLimitFlag.Name),

op-batcher/batcher/driver.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/ethereum/go-ethereum/log"
2222
"github.com/ethereum/go-ethereum/rpc"
2323

24+
"github.com/ethereum-optimism/optimism/espresso"
2425
altda "github.com/ethereum-optimism/optimism/op-alt-da"
2526
"github.com/ethereum-optimism/optimism/op-batcher/batcher/throttler"
2627
config "github.com/ethereum-optimism/optimism/op-batcher/config"
@@ -29,6 +30,7 @@ import (
2930
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
3031
"github.com/ethereum-optimism/optimism/op-service/dial"
3132
"github.com/ethereum-optimism/optimism/op-service/eth"
33+
oplog "github.com/ethereum-optimism/optimism/op-service/log"
3234
"github.com/ethereum-optimism/optimism/op-service/txmgr"
3335
)
3436

@@ -102,6 +104,11 @@ type DriverSetup struct {
102104
ChannelConfig ChannelConfigProvider
103105
AltDA AltDAClient
104106
ChannelOutFactory ChannelOutFactory
107+
108+
// Espresso groups all TEE-batcher-specific runtime state plumbed from
109+
// BatcherService. Defined in espresso_driver.go to keep the upstream
110+
// Optimism field block compact.
111+
Espresso EspressoDriverSetup
105112
}
106113

107114
// BatchSubmitter encapsulates a service responsible for submitting L2 tx
@@ -128,10 +135,19 @@ type BatchSubmitter struct {
128135
publishSignal chan pubInfo
129136

130137
// authGroup serializes in-flight BatchAuthenticator submissions issued by
131-
// the fallback batcher's authentication path so the publishing loop can
132-
// drain them on shutdown. Bounded to fallbackAuthGroupLimit; see
133-
// espresso_driver.go.
138+
// the fallback batcher's authentication path and by the TEE batcher's
139+
// authentication path so the publishing loop can drain them on shutdown.
140+
// Bounded to fallbackAuthGroupLimit; see espresso_driver.go.
134141
authGroup errgroup.Group
142+
143+
espressoSubmitter *espressoTransactionSubmitter
144+
espressoStreamer espresso.EspressoStreamer[derive.EspressoBatch]
145+
146+
teeVerifierAddress common.Address
147+
148+
// degradedLog throttles repeated warnings from tick-driven loops so the
149+
// log debouncer doesn't see the same message every poll interval.
150+
degradedLog *oplog.RepeatStateLogger
135151
}
136152

137153
// NewBatchSubmitter initializes the BatchSubmitter driver from a preconfigured DriverSetup
@@ -144,6 +160,7 @@ func NewBatchSubmitter(setup DriverSetup) *BatchSubmitter {
144160
batcher := &BatchSubmitter{
145161
DriverSetup: setup,
146162
channelMgr: state,
163+
degradedLog: oplog.NewRepeatStateLogger(),
147164
}
148165

149166
err := batcher.SetThrottleController(setup.Config.ThrottleParams.ControllerType, setup.Config.ThrottleParams.PIDConfig)
@@ -152,6 +169,7 @@ func NewBatchSubmitter(setup DriverSetup) *BatchSubmitter {
152169
}
153170

154171
batcher.initAuthGroup()
172+
batcher.setupEspressoStreamer()
155173

156174
return batcher
157175
}
@@ -200,10 +218,16 @@ func (l *BatchSubmitter) StartBatchSubmitting() error {
200218
l.Log.Warn("Throttling loop is DISABLED due to 0 throttle-threshold. This should not be disabled in prod.")
201219
}
202220

203-
l.wg.Add(3)
204-
go l.receiptsLoop(l.wg, receiptsCh) // ranges over receiptsCh channel
205-
go l.publishingLoop(l.killCtx, l.wg, receiptsCh, publishSignal) // ranges over publishSignal, spawns routines which send on receiptsCh. Closes receiptsCh when done.
206-
go l.blockLoadingLoop(l.shutdownCtx, l.wg, unsafeBytesUpdated, publishSignal) // sends on unsafeBytesUpdated (if throttling enabled), and publishSignal. Closes them both when done
221+
if l.Config.Espresso.Enabled {
222+
if err := l.startEspressoLoops(receiptsCh, publishSignal); err != nil {
223+
return err
224+
}
225+
} else {
226+
l.wg.Add(3)
227+
go l.receiptsLoop(l.wg, receiptsCh) // ranges over receiptsCh channel
228+
go l.publishingLoop(l.killCtx, l.wg, receiptsCh, publishSignal) // ranges over publishSignal, spawns routines which send on receiptsCh. Closes receiptsCh when done.
229+
go l.blockLoadingLoop(l.shutdownCtx, l.wg, unsafeBytesUpdated, publishSignal) // sends on unsafeBytesUpdated (if throttling enabled), and publishSignal. Closes them both when done
230+
}
207231

208232
l.Log.Info("Batch Submitter started")
209233
return nil
@@ -845,6 +869,7 @@ func (l *BatchSubmitter) clearState(ctx context.Context) {
845869
l.channelMgrMutex.Lock()
846870
defer l.channelMgrMutex.Unlock()
847871
l.channelMgr.Clear(l1SafeOrigin)
872+
l.resetEspressoStreamer()
848873
return true
849874
}
850875
}

0 commit comments

Comments
 (0)