From d1421717d68163a883ea336fae6f9d002582fe6f Mon Sep 17 00:00:00 2001 From: joey <10592664+joey0612@users.noreply.github.com> Date: Fri, 16 May 2025 11:14:17 +0800 Subject: [PATCH 1/3] feat: add channel out callback for enclave --- op-batcher/batcher/channel.go | 7 +++- op-batcher/batcher/channel_builder.go | 29 +++++++++++--- op-batcher/batcher/channel_builder_test.go | 44 +++++++++++----------- op-batcher/batcher/channel_manager.go | 7 +++- op-batcher/batcher/channel_manager_test.go | 19 +++++----- op-batcher/batcher/channel_test.go | 12 +++--- op-batcher/batcher/driver.go | 23 +++++------ op-batcher/batcher/service.go | 20 ++++++---- 8 files changed, 97 insertions(+), 64 deletions(-) diff --git a/op-batcher/batcher/channel.go b/op-batcher/batcher/channel.go index 0aaa194a73..100a2386b8 100644 --- a/op-batcher/batcher/channel.go +++ b/op-batcher/batcher/channel.go @@ -32,10 +32,12 @@ type channel struct { minInclusionBlock uint64 // Inclusion block number of last confirmed TX maxInclusionBlock uint64 + + outFactory ChannelOutFactory } -func newChannel(log log.Logger, metr metrics.Metricer, cfg ChannelConfig, rollupCfg *rollup.Config, latestL1OriginBlockNum uint64) (*channel, error) { - cb, err := NewChannelBuilder(cfg, *rollupCfg, latestL1OriginBlockNum) +func newChannel(log log.Logger, metr metrics.Metricer, cfg ChannelConfig, rollupCfg *rollup.Config, outFactory ChannelOutFactory, latestL1OriginBlockNum uint64) (*channel, error) { + cb, err := NewChannelBuilder(cfg, *rollupCfg, outFactory, latestL1OriginBlockNum) if err != nil { return nil, fmt.Errorf("creating new channel: %w", err) } @@ -47,6 +49,7 @@ func newChannel(log log.Logger, metr metrics.Metricer, cfg ChannelConfig, rollup channelBuilder: cb, pendingTransactions: make(map[string]txData), confirmedTransactions: make(map[string]eth.BlockID), + outFactory: outFactory, }, nil } diff --git a/op-batcher/batcher/channel_builder.go b/op-batcher/batcher/channel_builder.go index cdb42845ca..afccb65f21 100644 --- a/op-batcher/batcher/channel_builder.go +++ b/op-batcher/batcher/channel_builder.go @@ -76,15 +76,20 @@ type ChannelBuilder struct { outputBytes int } -// NewChannelBuilder creates a new channel builder or returns an error if the -// channel out could not be created. -// it acts as a factory for either a span or singular channel out -func NewChannelBuilder(cfg ChannelConfig, rollupCfg rollup.Config, latestL1OriginBlockNum uint64) (*ChannelBuilder, error) { +type ChannelOutFactory func(cfg ChannelConfig, rollupCfg *rollup.Config) (derive.ChannelOut, error) + +// NewChannelOut creates a new channel out based on the given configuration. +func NewChannelOut(cfg ChannelConfig, rollupCfg *rollup.Config) (derive.ChannelOut, error) { + var ( + co derive.ChannelOut + err error + ) + c, err := cfg.CompressorConfig.NewCompressor() if err != nil { return nil, err } - var co derive.ChannelOut + if cfg.BatchType == derive.SpanBatchType { co, err = derive.NewSpanChannelOut(rollupCfg.Genesis.L2Time, rollupCfg.L2ChainID, cfg.CompressorConfig.TargetOutputSize, cfg.CompressorConfig.CompressionAlgo) } else { @@ -93,6 +98,20 @@ func NewChannelBuilder(cfg ChannelConfig, rollupCfg rollup.Config, latestL1Origi if err != nil { return nil, fmt.Errorf("creating channel out: %w", err) } + return co, nil +} + +// NewChannelBuilder creates a new channel builder or returns an error if the +// channel out could not be created. +// it acts as a factory for either a span or singular channel out +func NewChannelBuilder(cfg ChannelConfig, rollupCfg rollup.Config, outFactory ChannelOutFactory, latestL1OriginBlockNum uint64) (*ChannelBuilder, error) { + if outFactory == nil { + outFactory = NewChannelOut + } + co, err := outFactory(cfg, &rollupCfg) + if err != nil { + return nil, err + } cb := &ChannelBuilder{ cfg: cfg, diff --git a/op-batcher/batcher/channel_builder_test.go b/op-batcher/batcher/channel_builder_test.go index 90a6b682c4..527f1d4f7e 100644 --- a/op-batcher/batcher/channel_builder_test.go +++ b/op-batcher/batcher/channel_builder_test.go @@ -105,7 +105,7 @@ func FuzzDurationTimeoutZeroMaxChannelDuration(f *testing.F) { f.Fuzz(func(t *testing.T, l1BlockNum uint64) { channelConfig := defaultTestChannelConfig() channelConfig.MaxChannelDuration = 0 - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) cb.timeout = 0 cb.updateDurationTimeout(l1BlockNum) @@ -128,7 +128,7 @@ func FuzzChannelBuilder_DurationZero(f *testing.F) { // Create the channel builder channelConfig := defaultTestChannelConfig() channelConfig.MaxChannelDuration = maxChannelDuration - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Whenever the timeout is set to 0, the channel builder should have a duration timeout @@ -155,7 +155,7 @@ func FuzzDurationTimeoutMaxChannelDuration(f *testing.F) { // Create the channel builder channelConfig := defaultTestChannelConfig() channelConfig.MaxChannelDuration = maxChannelDuration - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Whenever the timeout is greater than the l1BlockNum, @@ -189,7 +189,7 @@ func FuzzChannelCloseTimeout(f *testing.F) { channelConfig := defaultTestChannelConfig() channelConfig.ChannelTimeout = channelTimeout channelConfig.SubSafetyMargin = subSafetyMargin - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Check the timeout @@ -217,7 +217,7 @@ func FuzzChannelZeroCloseTimeout(f *testing.F) { channelConfig := defaultTestChannelConfig() channelConfig.ChannelTimeout = channelTimeout channelConfig.SubSafetyMargin = subSafetyMargin - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Check the timeout @@ -244,7 +244,7 @@ func FuzzSeqWindowClose(f *testing.F) { channelConfig := defaultTestChannelConfig() channelConfig.SeqWindowSize = seqWindowSize channelConfig.SubSafetyMargin = subSafetyMargin - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Check the timeout @@ -272,7 +272,7 @@ func FuzzSeqWindowZeroTimeoutClose(f *testing.F) { channelConfig := defaultTestChannelConfig() channelConfig.SeqWindowSize = seqWindowSize channelConfig.SubSafetyMargin = subSafetyMargin - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Check the timeout @@ -318,7 +318,7 @@ func TestChannelBuilder_NextFrame(t *testing.T) { channelConfig := defaultTestChannelConfig() // Create a new channel builder - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Mock the internals of `ChannelBuilder.outputFrame` @@ -359,7 +359,7 @@ func ChannelBuilder_OutputWrongFramePanic(t *testing.T, batchType uint) { channelConfig.BatchType = batchType // Construct a channel builder - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Mock the internals of `ChannelBuilder.outputFrame` @@ -395,7 +395,7 @@ func TestChannelBuilder_OutputFrames(t *testing.T) { channelConfig.InitNoneCompressor() // Construct the channel builder - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) require.False(t, cb.IsFull()) require.Equal(t, 0, cb.PendingFrames()) @@ -453,7 +453,7 @@ func ChannelBuilder_OutputFrames_SpanBatch(t *testing.T, algo derive.Compression channelConfig.InitRatioCompressor(1, algo) // Construct the channel builder - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) require.False(t, cb.IsFull()) require.Equal(t, 0, cb.PendingFrames()) @@ -510,7 +510,7 @@ func ChannelBuilder_MaxRLPBytesPerChannel(t *testing.T, batchType uint) { channelConfig.BatchType = batchType // Construct the channel builder - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Add a block that overflows the [ChannelOut] @@ -532,7 +532,7 @@ func ChannelBuilder_OutputFramesMaxFrameIndex(t *testing.T, batchType uint) { // Continuously add blocks until the max frame index is reached // This should cause the [ChannelBuilder.OutputFrames] function // to error - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) require.False(t, cb.IsFull()) require.Equal(t, 0, cb.PendingFrames()) @@ -568,7 +568,7 @@ func TestChannelBuilder_FullShadowCompressor(t *testing.T) { } cfg.InitShadowCompressor(derive.Zlib) - cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(err) rng := rand.New(rand.NewSource(420)) @@ -600,7 +600,7 @@ func ChannelBuilder_AddBlock(t *testing.T, batchType uint) { channelConfig.InitRatioCompressor(1, derive.Zlib) // Construct the channel builder - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Add a nonsense block to the channel builder @@ -626,7 +626,7 @@ func TestChannelBuilder_CheckTimeout(t *testing.T) { channelConfig := defaultTestChannelConfig() // Construct the channel builder - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Assert timeout is setup correctly @@ -651,7 +651,7 @@ func TestChannelBuilder_CheckTimeoutZeroMaxChannelDuration(t *testing.T) { channelConfig.MaxChannelDuration = 0 // Construct the channel builder - cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(channelConfig, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) // Without a max channel duration, timeout should not be set @@ -674,7 +674,7 @@ func TestChannelBuilder_FramePublished(t *testing.T) { cfg.SubSafetyMargin = 100 // Construct the channel builder - cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) require.Equal(t, latestL1BlockOrigin+cfg.MaxChannelDuration, cb.timeout) @@ -691,7 +691,7 @@ func TestChannelBuilder_FramePublished(t *testing.T) { } func TestChannelBuilder_LatestL1Origin(t *testing.T) { - cb, err := NewChannelBuilder(defaultTestChannelConfig(), defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(defaultTestChannelConfig(), defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(t, err) require.Equal(t, eth.BlockID{}, cb.LatestL1Origin()) @@ -721,7 +721,7 @@ func ChannelBuilder_PendingFrames_TotalFrames(t *testing.T, batchType uint) { cfg.TargetNumFrames = tnf cfg.BatchType = batchType cfg.InitShadowCompressor(derive.Zlib) - cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(err) // initial builder should be empty @@ -766,7 +766,7 @@ func ChannelBuilder_InputBytes(t *testing.T, batchType uint) { chainId := big.NewInt(1234) spanBatch = derive.NewSpanBatch(uint64(0), chainId) } - cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(err) require.Zero(cb.InputBytes()) @@ -803,7 +803,7 @@ func ChannelBuilder_OutputBytes(t *testing.T, batchType uint) { cfg.TargetNumFrames = 16 cfg.BatchType = batchType cfg.InitRatioCompressor(1.0, derive.Zlib) - cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, latestL1BlockOrigin) + cb, err := NewChannelBuilder(cfg, defaultTestRollupConfig, nil, latestL1BlockOrigin) require.NoError(err, "NewChannelBuilder") require.Zero(cb.OutputBytes()) diff --git a/op-batcher/batcher/channel_manager.go b/op-batcher/batcher/channel_manager.go index edd874f280..3a226b9da5 100644 --- a/op-batcher/batcher/channel_manager.go +++ b/op-batcher/batcher/channel_manager.go @@ -50,15 +50,18 @@ type channelManager struct { closed bool isVolta bool + + outFactory ChannelOutFactory } -func NewChannelManager(log log.Logger, metr metrics.Metricer, cfg ChannelConfig, rollupCfg *rollup.Config) *channelManager { +func NewChannelManager(log log.Logger, metr metrics.Metricer, cfg ChannelConfig, rollupCfg *rollup.Config, outFactory ChannelOutFactory) *channelManager { return &channelManager{ log: log, metr: metr, cfg: cfg, rollupCfg: rollupCfg, txChannels: make(map[string]*channel), + outFactory: outFactory, } } @@ -206,7 +209,7 @@ func (s *channelManager) ensureChannelWithSpace(l1Head eth.BlockID) error { return nil } - pc, err := newChannel(s.log, s.metr, s.cfg, s.rollupCfg, s.l1OriginLastClosedChannel.Number) + pc, err := newChannel(s.log, s.metr, s.cfg, s.rollupCfg, s.outFactory, s.l1OriginLastClosedChannel.Number) if err != nil { return fmt.Errorf("creating new channel: %w", err) } diff --git a/op-batcher/batcher/channel_manager_test.go b/op-batcher/batcher/channel_manager_test.go index d6c3d2e933..866818cacb 100644 --- a/op-batcher/batcher/channel_manager_test.go +++ b/op-batcher/batcher/channel_manager_test.go @@ -62,7 +62,7 @@ func TestChannelManagerBatchType(t *testing.T) { // detects a reorg when it has cached L1 blocks. func ChannelManagerReturnsErrReorg(t *testing.T, batchType uint) { log := testlog.Logger(t, log.LevelCrit) - m := NewChannelManager(log, metrics.NoopMetrics, ChannelConfig{BatchType: batchType}, &rollup.Config{}) + m := NewChannelManager(log, metrics.NoopMetrics, ChannelConfig{BatchType: batchType}, &rollup.Config{}, nil) m.Clear(eth.BlockID{}) a := types.NewBlock(&types.Header{ @@ -95,7 +95,7 @@ func ChannelManagerReturnsErrReorgWhenDrained(t *testing.T, batchType uint) { log := testlog.Logger(t, log.LevelCrit) cfg := channelManagerTestConfig(120_000, batchType) cfg.CompressorConfig.TargetOutputSize = 1 // full on first block - m := NewChannelManager(log, metrics.NoopMetrics, cfg, &rollup.Config{}) + m := NewChannelManager(log, metrics.NoopMetrics, cfg, &rollup.Config{}, nil) m.Clear(eth.BlockID{}) a := newMiniL2Block(0) @@ -124,7 +124,7 @@ func ChannelManager_Clear(t *testing.T, batchType uint) { // clearing confirmed transactions, and resetting the pendingChannels map cfg.ChannelTimeout = 10 cfg.InitRatioCompressor(1, derive.Zlib) - m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig) + m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig, nil) // Channel Manager state should be empty by default require.Empty(m.blocks) @@ -195,7 +195,7 @@ func ChannelManager_TxResend(t *testing.T, batchType uint) { log := testlog.Logger(t, log.LevelError) cfg := channelManagerTestConfig(120_000, batchType) cfg.CompressorConfig.TargetOutputSize = 1 // full on first block - m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig) + m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig, nil) m.Clear(eth.BlockID{}) a := derivetest.RandomL2BlockWithChainId(rng, 4, defaultTestRollupConfig.L2ChainID) @@ -235,6 +235,7 @@ func ChannelManagerCloseBeforeFirstUse(t *testing.T, batchType uint) { m := NewChannelManager(log, metrics.NoopMetrics, channelManagerTestConfig(10000, batchType), &defaultTestRollupConfig, + nil, ) m.Clear(eth.BlockID{}) @@ -258,7 +259,7 @@ func ChannelManagerCloseNoPendingChannel(t *testing.T, batchType uint) { cfg := channelManagerTestConfig(10000, batchType) cfg.CompressorConfig.TargetOutputSize = 1 // full on first block cfg.ChannelTimeout = 1000 - m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig) + m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig, nil) m.Clear(eth.BlockID{}) a := newMiniL2Block(0) b := newMiniL2BlockWithNumberParent(0, big.NewInt(1), a.Hash()) @@ -294,7 +295,7 @@ func ChannelManagerClosePendingChannel(t *testing.T, batchType uint) { log := testlog.Logger(t, log.LevelError) cfg := channelManagerTestConfig(10_000, batchType) cfg.ChannelTimeout = 1000 - m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig) + m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig, nil) m.Clear(eth.BlockID{}) numTx := 20 // Adjust number of txs to make 2 frames @@ -346,7 +347,7 @@ func TestChannelManager_Close_PartiallyPendingChannel(t *testing.T) { TargetNumFrames: 100, } cfg.InitNoneCompressor() - m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig) + m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig, nil) m.Clear(eth.BlockID{}) numTx := 3 // Adjust number of txs to make 2 frames @@ -398,7 +399,7 @@ func ChannelManagerCloseAllTxsFailed(t *testing.T, batchType uint) { cfg := channelManagerTestConfig(100, batchType) cfg.TargetNumFrames = 1000 cfg.InitNoneCompressor() - m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig) + m := NewChannelManager(log, metrics.NoopMetrics, cfg, &defaultTestRollupConfig, nil) m.Clear(eth.BlockID{}) a := derivetest.RandomL2BlockWithChainId(rng, 1000, defaultTestRollupConfig.L2ChainID) @@ -471,7 +472,7 @@ func TestChannelManager_ChannelCreation(t *testing.T) { } { test := tt t.Run(test.name, func(t *testing.T) { - m := NewChannelManager(l, metrics.NoopMetrics, cfg, &defaultTestRollupConfig) + m := NewChannelManager(l, metrics.NoopMetrics, cfg, &defaultTestRollupConfig, nil) m.l1OriginLastClosedChannel = test.safeL1Block require.Nil(t, m.currentChannel) diff --git a/op-batcher/batcher/channel_test.go b/op-batcher/batcher/channel_test.go index 3d3e813d0a..0237f802d1 100644 --- a/op-batcher/batcher/channel_test.go +++ b/op-batcher/batcher/channel_test.go @@ -33,7 +33,7 @@ func TestChannelTimeout(t *testing.T) { CompressorConfig: compressor.Config{ CompressionAlgo: derive.Zlib, }, - }, &rollup.Config{}) + }, &rollup.Config{}, nil) m.Clear(eth.BlockID{}) // Pending channel is nil so is cannot be timed out @@ -77,7 +77,7 @@ func TestChannelManager_NextTxData(t *testing.T) { log := testlog.Logger(t, log.LevelCrit) m := NewChannelManager(log, metrics.NoopMetrics, ChannelConfig{CompressorConfig: compressor.Config{ CompressionAlgo: derive.Zlib, - }}, &rollup.Config{}) + }}, &rollup.Config{}, nil) m.Clear(eth.BlockID{}) // Nil pending channel should return EOF @@ -127,7 +127,7 @@ func TestChannel_NextTxData_singleFrameTx(t *testing.T) { CompressorConfig: compressor.Config{ CompressionAlgo: derive.Zlib, }, - }, &rollup.Config{}, latestL1BlockOrigin) + }, &rollup.Config{}, nil, latestL1BlockOrigin) require.NoError(err) chID := ch.ID() @@ -168,7 +168,7 @@ func TestChannel_NextTxData_multiFrameTx(t *testing.T) { CompressorConfig: compressor.Config{ CompressionAlgo: derive.Zlib, }, - }, &rollup.Config{}, latestL1BlockOrigin) + }, &rollup.Config{}, nil, latestL1BlockOrigin) require.NoError(err) chID := ch.ID() @@ -217,7 +217,7 @@ func TestChannelTxConfirmed(t *testing.T) { CompressorConfig: compressor.Config{ CompressionAlgo: derive.Zlib, }, - }, &rollup.Config{}) + }, &rollup.Config{}, nil) m.Clear(eth.BlockID{}) // Let's add a valid pending transaction to the channel manager @@ -268,7 +268,7 @@ func TestChannelTxFailed(t *testing.T) { log := testlog.Logger(t, log.LevelCrit) m := NewChannelManager(log, metrics.NoopMetrics, ChannelConfig{CompressorConfig: compressor.Config{ CompressionAlgo: derive.Zlib, - }}, &rollup.Config{}) + }}, &rollup.Config{}, nil) m.Clear(eth.BlockID{}) // Let's add a valid pending transaction to the channel diff --git a/op-batcher/batcher/driver.go b/op-batcher/batcher/driver.go index 0df382ac1e..bb79fd0424 100644 --- a/op-batcher/batcher/driver.go +++ b/op-batcher/batcher/driver.go @@ -57,16 +57,17 @@ type RollupClient interface { // DriverSetup is the collection of input/output interfaces and configuration that the driver operates on. type DriverSetup struct { - Log log.Logger - Metr metrics.Metricer - RollupConfig *rollup.Config - Config BatcherConfig - Txmgr txmgr.TxManager - L1Client L1Client - EndpointProvider dial.L2EndpointProvider - ChannelConfig ChannelConfig - PlasmaDA *plasma.DAClient - AutoSwitchDA bool + Log log.Logger + Metr metrics.Metricer + RollupConfig *rollup.Config + Config BatcherConfig + Txmgr txmgr.TxManager + L1Client L1Client + EndpointProvider dial.L2EndpointProvider + ChannelConfig ChannelConfig + PlasmaDA *plasma.DAClient + AutoSwitchDA bool + ChannelOutFactory ChannelOutFactory } // BatchSubmitter encapsulates a service responsible for submitting L2 tx @@ -98,7 +99,7 @@ type BatchSubmitter struct { func NewBatchSubmitter(setup DriverSetup) *BatchSubmitter { return &BatchSubmitter{ DriverSetup: setup, - state: NewChannelManager(setup.Log, setup.Metr, setup.ChannelConfig, setup.RollupConfig), + state: NewChannelManager(setup.Log, setup.Metr, setup.ChannelConfig, setup.RollupConfig, setup.ChannelOutFactory), } } diff --git a/op-batcher/batcher/service.go b/op-batcher/batcher/service.go index 7c7b0aad49..8efdf6af8d 100644 --- a/op-batcher/batcher/service.go +++ b/op-batcher/batcher/service.go @@ -78,18 +78,20 @@ type BatcherService struct { NotSubmittingOnStart bool } +type DriverSetupOption func(setup *DriverSetup) + // BatcherServiceFromCLIConfig creates a new BatcherService from a CLIConfig. // The service components are fully started, except for the driver, // which will not be submitting batches (if it was configured to) until the Start part of the lifecycle. -func BatcherServiceFromCLIConfig(ctx context.Context, version string, cfg *CLIConfig, log log.Logger) (*BatcherService, error) { +func BatcherServiceFromCLIConfig(ctx context.Context, version string, cfg *CLIConfig, log log.Logger, opts ...DriverSetupOption) (*BatcherService, error) { var bs BatcherService - if err := bs.initFromCLIConfig(ctx, version, cfg, log); err != nil { + if err := bs.initFromCLIConfig(ctx, version, cfg, log, opts...); err != nil { return nil, errors.Join(err, bs.Stop(ctx)) // try to clean up our failed initialization attempt } return &bs, nil } -func (bs *BatcherService) initFromCLIConfig(ctx context.Context, version string, cfg *CLIConfig, log log.Logger) error { +func (bs *BatcherService) initFromCLIConfig(ctx context.Context, version string, cfg *CLIConfig, log log.Logger, opts ...DriverSetupOption) error { bs.Version = version bs.Log = log bs.NotSubmittingOnStart = cfg.Stopped @@ -124,7 +126,7 @@ func (bs *BatcherService) initFromCLIConfig(ctx context.Context, version string, if err := bs.initPlasmaDA(cfg); err != nil { return fmt.Errorf("failed to init plasma DA: %w", err) } - bs.initDriver(cfg) + bs.initDriver(cfg, opts...) if err := bs.initRPCServer(cfg); err != nil { return fmt.Errorf("failed to start RPC server: %w", err) } @@ -297,8 +299,8 @@ func (bs *BatcherService) initMetricsServer(cfg *CLIConfig) error { return nil } -func (bs *BatcherService) initDriver(cfg *CLIConfig) { - bs.driver = NewBatchSubmitter(DriverSetup{ +func (bs *BatcherService) initDriver(cfg *CLIConfig, opts ...DriverSetupOption) { + ds := DriverSetup{ Log: bs.Log, Metr: bs.Metrics, RollupConfig: bs.RollupConfig, @@ -309,7 +311,11 @@ func (bs *BatcherService) initDriver(cfg *CLIConfig) { ChannelConfig: bs.ChannelConfig, PlasmaDA: bs.PlasmaDA, AutoSwitchDA: cfg.DataAvailabilityType == flags.AutoType, - }) + } + for _, opt := range opts { + opt(&ds) + } + bs.driver = NewBatchSubmitter(ds) } func (bs *BatcherService) initRPCServer(cfg *CLIConfig) error { From 9c9dabcd4645093e9bb225c258add9764c1a91b7 Mon Sep 17 00:00:00 2001 From: will-2012 <117156346+will-2012@users.noreply.github.com> Date: Tue, 20 May 2025 14:41:21 +0800 Subject: [PATCH 2/3] chore: adapt stateless deps --- go.mod | 5 ++--- go.sum | 4 ++-- op-batcher/batcher/driver.go | 2 +- op-chain-ops/cmd/check-derivation/main.go | 6 +++--- .../game/keccak/fetcher/fetcher_test.go | 2 +- op-e2e/actions/l2_batcher.go | 4 ++-- op-e2e/actions/l2_batcher_test.go | 2 +- op-e2e/actions/span_batch_test.go | 4 ++-- op-e2e/actions/sync_test.go | 18 +++++++++--------- op-e2e/brotli_batcher_test.go | 2 +- op-e2e/eip4844_test.go | 2 +- op-node/cmd/genesis/cmd.go | 2 +- op-node/rollup/derive/channel_out_test.go | 11 +++++------ op-node/rollup/derive/test/random.go | 2 +- op-program/client/l2/oracle.go | 2 +- op-wheel/engine/engine.go | 2 +- 16 files changed, 34 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 7421371798..3ef366e94e 100644 --- a/go.mod +++ b/go.mod @@ -277,12 +277,11 @@ require ( rsc.io/tmplfunc v0.0.3 // indirect ) -replace github.com/ethereum/go-ethereum v1.13.15 => github.com/bnb-chain/op-geth v1.101315.2-0.0.20250418091555-2b39d61b7cbf +// https://github.com/bnb-chain/op-geth/tree/tee-base-stateless-poc +replace github.com/ethereum/go-ethereum v1.13.15 => github.com/bnb-chain/op-geth v1.101315.2-0.0.20250520053659-1fde7613d115 replace github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0 -//replace github.com/ethereum/go-ethereum v1.13.9 => ../op-geth - // replace github.com/ethereum-optimism/superchain-registry/superchain => ../superchain-registry/superchain // This release keeps breaking Go builds. Stop that. diff --git a/go.sum b/go.sum index cdea5c24d5..5a448fecd2 100644 --- a/go.sum +++ b/go.sum @@ -184,8 +184,8 @@ github.com/bnb-chain/fastssz v0.1.2 h1:vTcXw5SwCtRYnl/BEclujiml7GXiVOZ74tub4GHpv github.com/bnb-chain/fastssz v0.1.2/go.mod h1:KcabV+OEw2QwgyY8Fc88ZG79CKYkFdu0kKWyfA3dI6o= github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr3LCn5/XlcgDWr8= github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk= -github.com/bnb-chain/op-geth v1.101315.2-0.0.20250418091555-2b39d61b7cbf h1:7Ry/NtfhCFelZRVhw5cPwveX8uVFchalL+qhUcn5CMA= -github.com/bnb-chain/op-geth v1.101315.2-0.0.20250418091555-2b39d61b7cbf/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= +github.com/bnb-chain/op-geth v1.101315.2-0.0.20250520053659-1fde7613d115 h1:zIqD55hPe6tiZPrOhR8x40MV8iQNjjouajkmmmf6qZo= +github.com/bnb-chain/op-geth v1.101315.2-0.0.20250520053659-1fde7613d115/go.mod h1:hyHrrcHkUe3lRwfJs+JGrbOHp+pRdheRk+ren4TPhF8= github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= diff --git a/op-batcher/batcher/driver.go b/op-batcher/batcher/driver.go index bb79fd0424..b0fe558ce2 100644 --- a/op-batcher/batcher/driver.go +++ b/op-batcher/batcher/driver.go @@ -682,7 +682,7 @@ func (l *BatchSubmitter) sendTransaction(ctx context.Context, txdata txData, que candidate = l.calldataTxCandidate(data) } - intrinsicGas, err := core.IntrinsicGas(candidate.TxData, nil, nil, true, true, false, false) + intrinsicGas, err := core.IntrinsicGas(candidate.TxData, nil, true, true, false, false) if err != nil { // we log instead of return an error here because txmgr can do its own gas estimation l.Log.Error("Failed to calculate intrinsic gas", "err", err) diff --git a/op-chain-ops/cmd/check-derivation/main.go b/op-chain-ops/cmd/check-derivation/main.go index b867ea23a4..b91d23dd98 100644 --- a/op-chain-ops/cmd/check-derivation/main.go +++ b/op-chain-ops/cmd/check-derivation/main.go @@ -225,7 +225,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client var txData types.TxData switch txType { case types.LegacyTxType: - gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) + gasLimit, err := core.IntrinsicGas(data, nil, false, true, false, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } @@ -242,7 +242,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client Address: randomAddress, StorageKeys: []common.Hash{common.HexToHash("0x1234")}, }} - gasLimit, err := core.IntrinsicGas(data, accessList, nil, false, true, false, false) + gasLimit, err := core.IntrinsicGas(data, accessList, false, true, false, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } @@ -257,7 +257,7 @@ func getRandomSignedTransaction(ctx context.Context, ethClient *ethclient.Client Data: data, } case types.DynamicFeeTxType: - gasLimit, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) + gasLimit, err := core.IntrinsicGas(data, nil, false, true, false, false) if err != nil { return nil, fmt.Errorf("failed to get intrinsicGas: %w", err) } diff --git a/op-challenger/game/keccak/fetcher/fetcher_test.go b/op-challenger/game/keccak/fetcher/fetcher_test.go index cedff735e9..e19dba6342 100644 --- a/op-challenger/game/keccak/fetcher/fetcher_test.go +++ b/op-challenger/game/keccak/fetcher/fetcher_test.go @@ -437,7 +437,7 @@ func (s *stubL1Source) BlockByNumber(_ context.Context, number *big.Int) (*types if !ok { return nil, errors.New("not found") } - return (&types.Block{}).WithBody(txs, nil), nil + return (&types.Block{}).WithBody(types.Body{Transactions: txs, Uncles: nil}), nil } func (s *stubL1Source) TransactionReceipt(_ context.Context, txHash common.Hash) (*types.Receipt, error) { diff --git a/op-e2e/actions/l2_batcher.go b/op-e2e/actions/l2_batcher.go index 1a955f851c..5cda243824 100644 --- a/op-e2e/actions/l2_batcher.go +++ b/op-e2e/actions/l2_batcher.go @@ -277,7 +277,7 @@ func (s *L2Batcher) ActL2BatchSubmit(t Testing, txOpts ...func(tx *types.Dynamic opt(rawTx) } - gas, err := core.IntrinsicGas(rawTx.Data, nil, nil, false, true, false, false) + gas, err := core.IntrinsicGas(rawTx.Data, nil, false, true, false, false) require.NoError(t, err, "need to compute intrinsic gas") rawTx.Gas = gas txData = rawTx @@ -468,7 +468,7 @@ func (s *L2Batcher) ActL2BatchSubmitGarbage(t Testing, kind GarbageKind) { GasFeeCap: gasFeeCap, Data: outputFrame, } - gas, err := core.IntrinsicGas(rawTx.Data, nil, nil, false, true, false, false) + gas, err := core.IntrinsicGas(rawTx.Data, nil, false, true, false, false) require.NoError(t, err, "need to compute intrinsic gas") rawTx.Gas = gas diff --git a/op-e2e/actions/l2_batcher_test.go b/op-e2e/actions/l2_batcher_test.go index 27f567b326..3a137ce992 100644 --- a/op-e2e/actions/l2_batcher_test.go +++ b/op-e2e/actions/l2_batcher_test.go @@ -496,7 +496,7 @@ func BigL2Txs(gt *testing.T, deltaTimeOffset *hexutil.Uint64) { data := make([]byte, 120_000) // very large L2 txs, as large as the tx-pool will accept _, err := rng.Read(data[:]) // fill with random bytes, to make compression ineffective require.NoError(t, err) - gas, err := core.IntrinsicGas(data, nil, nil, false, true, true, false) + gas, err := core.IntrinsicGas(data, nil, false, true, true, false) require.NoError(t, err) if gas > engine.engineApi.RemainingBlockGas() { break diff --git a/op-e2e/actions/span_batch_test.go b/op-e2e/actions/span_batch_test.go index b3bc2d0d14..f9ad45cace 100644 --- a/op-e2e/actions/span_batch_test.go +++ b/op-e2e/actions/span_batch_test.go @@ -524,7 +524,7 @@ func TestSpanBatchLowThroughputChain(gt *testing.T) { data := make([]byte, rand.Intn(100)) _, err := crand.Read(data[:]) // fill with random bytes require.NoError(t, err) - gas, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) + gas, err := core.IntrinsicGas(data, nil, false, true, false, false) require.NoError(t, err) baseFee := seqEngine.l2Chain.CurrentBlock().BaseFee nonce, err := cl.PendingNonceAt(t.Ctx(), addrs[userIdx]) @@ -663,7 +663,7 @@ func TestBatchEquivalence(gt *testing.T) { data := make([]byte, rand.Intn(100)) _, err := crand.Read(data[:]) // fill with random bytes require.NoError(t, err) - gas, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) + gas, err := core.IntrinsicGas(data, nil, false, true, false, false) require.NoError(t, err) baseFee := seqEngine.l2Chain.CurrentBlock().BaseFee nonce, err := seqEngCl.PendingNonceAt(t.Ctx(), addrs[userIdx]) diff --git a/op-e2e/actions/sync_test.go b/op-e2e/actions/sync_test.go index b856413f35..a06f12f0cd 100644 --- a/op-e2e/actions/sync_test.go +++ b/op-e2e/actions/sync_test.go @@ -235,12 +235,12 @@ func TestBackupUnsafe(gt *testing.T) { To: &dp.Addresses.Bob, Value: e2eutils.Ether(2), }) - block = block.WithBody([]*types.Transaction{block.Transactions()[0], validTx}, []*types.Header{}) + block = block.WithBody(types.Body{Transactions: []*types.Transaction{block.Transactions()[0], validTx}, Uncles: []*types.Header{}}) } if i == 3 { // Make block B3 as an invalid block invalidTx := testutils.RandomTx(rng, big.NewInt(100), signer) - block = block.WithBody([]*types.Transaction{block.Transactions()[0], invalidTx}, []*types.Header{}) + block = block.WithBody(types.Body{Transactions: []*types.Transaction{block.Transactions()[0], invalidTx}, Uncles: []*types.Header{}}) } // Add A1, B2, B3, B4, B5 into the channel err = channelOut.AddBlock(sd.RollupCfg, block) @@ -398,12 +398,12 @@ func TestBackupUnsafeReorgForkChoiceInputError(gt *testing.T) { To: &dp.Addresses.Bob, Value: e2eutils.Ether(2), }) - block = block.WithBody([]*types.Transaction{block.Transactions()[0], validTx}, []*types.Header{}) + block = block.WithBody(types.Body{Transactions: []*types.Transaction{block.Transactions()[0], validTx}, Uncles: []*types.Header{}}) } if i == 3 { // Make block B3 as an invalid block invalidTx := testutils.RandomTx(rng, big.NewInt(100), signer) - block = block.WithBody([]*types.Transaction{block.Transactions()[0], invalidTx}, []*types.Header{}) + block = block.WithBody(types.Body{Transactions: []*types.Transaction{block.Transactions()[0], invalidTx}, Uncles: []*types.Header{}}) } // Add A1, B2, B3, B4, B5 into the channel err = channelOut.AddBlock(sd.RollupCfg, block) @@ -537,12 +537,12 @@ func TestBackupUnsafeReorgForkChoiceNotInputError(gt *testing.T) { To: &dp.Addresses.Bob, Value: e2eutils.Ether(2), }) - block = block.WithBody([]*types.Transaction{block.Transactions()[0], validTx}, []*types.Header{}) + block = block.WithBody(types.Body{Transactions: []*types.Transaction{block.Transactions()[0], validTx}, Uncles: []*types.Header{}}) } if i == 3 { // Make block B3 as an invalid block invalidTx := testutils.RandomTx(rng, big.NewInt(100), signer) - block = block.WithBody([]*types.Transaction{block.Transactions()[0], invalidTx}, []*types.Header{}) + block = block.WithBody(types.Body{Transactions: []*types.Transaction{block.Transactions()[0], invalidTx}, Uncles: []*types.Header{}}) } // Add A1, B2, B3, B4, B5 into the channel err = channelOut.AddBlock(sd.RollupCfg, block) @@ -861,7 +861,7 @@ func TestInvalidPayloadInSpanBatch(gt *testing.T) { if i == 8 { // Make block A8 as an invalid block invalidTx := testutils.RandomTx(rng, big.NewInt(100), signer) - block = block.WithBody([]*types.Transaction{block.Transactions()[0], invalidTx}, []*types.Header{}) + block = block.WithBody(types.Body{Transactions: []*types.Transaction{block.Transactions()[0], invalidTx}, Uncles: []*types.Header{}}) } // Add A1 ~ A12 into the channel err = channelOut.AddBlock(sd.RollupCfg, block) @@ -896,7 +896,7 @@ func TestInvalidPayloadInSpanBatch(gt *testing.T) { aliceNonce, err := seqEng.EthClient().PendingNonceAt(t.Ctx(), dp.Addresses.Alice) require.NoError(t, err) data := make([]byte, rand.Intn(100)) - gas, err := core.IntrinsicGas(data, nil, nil, false, true, false, false) + gas, err := core.IntrinsicGas(data, nil, false, true, false, false) require.NoError(t, err) baseFee := seqEng.l2Chain.CurrentBlock().BaseFee tx := types.MustSignNewTx(dp.Secrets.Alice, signer, &types.DynamicFeeTx{ @@ -910,7 +910,7 @@ func TestInvalidPayloadInSpanBatch(gt *testing.T) { Data: data, }) // Create valid new block B1 at the same height as A1 - block = block.WithBody([]*types.Transaction{block.Transactions()[0], tx}, []*types.Header{}) + block = block.WithBody(types.Body{Transactions: []*types.Transaction{block.Transactions()[0], tx}, Uncles: []*types.Header{}}) } // Add B1, A2 ~ A12 into the channel err = channelOut.AddBlock(sd.RollupCfg, block) diff --git a/op-e2e/brotli_batcher_test.go b/op-e2e/brotli_batcher_test.go index c000a6f42e..58af85ed27 100644 --- a/op-e2e/brotli_batcher_test.go +++ b/op-e2e/brotli_batcher_test.go @@ -85,7 +85,7 @@ func TestBrotliBatcherFjord(t *testing.T) { opts.Value = big.NewInt(1_000_000_000) opts.Nonce = 1 // Already have deposit opts.ToAddr = &common.Address{0xff, 0xff} - opts.Gas, err = core.IntrinsicGas(opts.Data, nil, nil, false, true, false, false) + opts.Gas, err = core.IntrinsicGas(opts.Data, nil, false, true, false, false) require.NoError(t, err) opts.VerifyOnClients(l2Verif) }) diff --git a/op-e2e/eip4844_test.go b/op-e2e/eip4844_test.go index 37b243ffbf..eca0703d09 100644 --- a/op-e2e/eip4844_test.go +++ b/op-e2e/eip4844_test.go @@ -102,7 +102,7 @@ func testSystem4844E2E(t *testing.T, multiBlob bool) { opts.ToAddr = &common.Address{0xff, 0xff} // put some random data in the tx to make it fill up 6 blobs (multi-blob case) opts.Data = testutils.RandomData(rand.New(rand.NewSource(420)), 400) - opts.Gas, err = core.IntrinsicGas(opts.Data, nil, nil, false, true, false, false) + opts.Gas, err = core.IntrinsicGas(opts.Data, nil, false, true, false, false) require.NoError(t, err) opts.VerifyOnClients(l2Verif) }) diff --git a/op-node/cmd/genesis/cmd.go b/op-node/cmd/genesis/cmd.go index 6d3d687444..04738fb663 100644 --- a/op-node/cmd/genesis/cmd.go +++ b/op-node/cmd/genesis/cmd.go @@ -290,5 +290,5 @@ func readBlockJSON(path string) (*types.Block, error) { for i, tx := range body.Transactions { txs[i] = tx.tx } - return types.NewBlockWithHeader(&header).WithBody(txs, nil).WithWithdrawals(body.Withdrawals), nil + return types.NewBlockWithHeader(&header).WithBody(types.Body{Transactions: txs, Uncles: nil /* uncles */}).WithWithdrawals(body.Withdrawals), nil } diff --git a/op-node/rollup/derive/channel_out_test.go b/op-node/rollup/derive/channel_out_test.go index 1395e328f2..485d89bb39 100644 --- a/op-node/rollup/derive/channel_out_test.go +++ b/op-node/rollup/derive/channel_out_test.go @@ -62,12 +62,11 @@ func TestChannelOutAddBlock(t *testing.T) { t.Run(tcase.Name, func(t *testing.T) { cout := tcase.ChannelOut(t) header := &types.Header{Number: big.NewInt(1), Difficulty: big.NewInt(100)} - block := types.NewBlockWithHeader(header).WithBody( - []*types.Transaction{ - types.NewTx(&types.DynamicFeeTx{}), - }, - nil, - ) + block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: []*types.Transaction{ + types.NewTx(&types.DynamicFeeTx{}), + }, + Uncles: nil, + }) err := cout.AddBlock(&rollupCfg, block) require.Error(t, err) require.Equal(t, ErrNotDepositTx, err) diff --git a/op-node/rollup/derive/test/random.go b/op-node/rollup/derive/test/random.go index 57ad0d8d95..c4d4d1fe9e 100644 --- a/op-node/rollup/derive/test/random.go +++ b/op-node/rollup/derive/test/random.go @@ -45,5 +45,5 @@ func RandomL2BlockWithChainIdAndTime(rng *rand.Rand, txCount int, chainId *big.I for i := 0; i < txCount; i++ { txs = append(txs, testutils.RandomTx(rng, big.NewInt(int64(rng.Uint32())), signer)) } - return block.WithBody(txs, nil) + return block.WithBody(types.Body{Transactions: txs, Uncles: nil}) } diff --git a/op-program/client/l2/oracle.go b/op-program/client/l2/oracle.go index 6aa049e159..cd06cd822b 100644 --- a/op-program/client/l2/oracle.go +++ b/op-program/client/l2/oracle.go @@ -66,7 +66,7 @@ func (p *PreimageOracle) BlockByHash(blockHash common.Hash) *types.Block { header := p.headerByBlockHash(blockHash) txs := p.LoadTransactions(blockHash, header.TxHash) - return types.NewBlockWithHeader(header).WithBody(txs, nil) + return types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs, Uncles: nil}) } func (p *PreimageOracle) LoadTransactions(blockHash common.Hash, txHash common.Hash) []*types.Transaction { diff --git a/op-wheel/engine/engine.go b/op-wheel/engine/engine.go index f76fc753ac..efb357120d 100644 --- a/op-wheel/engine/engine.go +++ b/op-wheel/engine/engine.go @@ -44,7 +44,7 @@ func getBlock(ctx context.Context, client client.RPC, method string, tag string) if err != nil { return nil, err } - return types.NewBlockWithHeader(&bl.Header).WithBody(bl.Transactions, nil), nil + return types.NewBlockWithHeader(&bl.Header).WithBody(types.Body{Transactions: bl.Transactions, Uncles: nil}), nil } func getHeader(ctx context.Context, client client.RPC, method string, tag string) (*types.Header, error) { From 116cdea15e13607184b0bef41efacce8042f33f3 Mon Sep 17 00:00:00 2001 From: will-2012 <117156346+will-2012@users.noreply.github.com> Date: Fri, 23 May 2025 16:45:26 +0800 Subject: [PATCH 3/3] chore: adapt stateless call PreparePayloadAttributes (#300) --- op-node/rollup/derive/attributes.go | 29 +++++++++++++---------- op-node/rollup/derive/attributes_queue.go | 5 ++-- op-node/rollup/derive/attributes_test.go | 16 ++++++------- op-node/rollup/driver/sequencer.go | 2 +- op-node/rollup/driver/sequencer_test.go | 2 +- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/op-node/rollup/derive/attributes.go b/op-node/rollup/derive/attributes.go index 833d685cfa..fa8a41a31f 100644 --- a/op-node/rollup/derive/attributes.go +++ b/op-node/rollup/derive/attributes.go @@ -55,7 +55,7 @@ func NewFetchingAttributesBuilder(rollupCfg *rollup.Config, l1 L1ReceiptsFetcher // by setting NoTxPool=false as sequencer, or by appending batch transactions as verifier. // The severity of the error is returned; a crit=false error means there was a temporary issue, like a failed RPC or time-out. // A crit=true error means the input arguments are inconsistent or invalid. -func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Context, l2Parent eth.L2BlockRef, epoch eth.BlockID) (attrs *eth.PayloadAttributes, err error) { +func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Context, l2Parent eth.L2BlockRef, epoch eth.BlockID, l1BaseFeeFromStateless *big.Int) (attrs *eth.PayloadAttributes, err error) { var l1Info eth.BlockInfo var depositTxs []hexutil.Bytes var seqNumber uint64 @@ -108,19 +108,24 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex // Calculate bsc block base fee var l1BaseFee *big.Int - if ba.rollupCfg.IsSnow(ba.rollupCfg.NextSecondBlockTime(l2Parent.MillisecondTimestamp())) { - l1BaseFee, err = SnowL1GasPrice(ctx, ba, epoch) - if err != nil { - return nil, err - } - } else if ba.rollupCfg.IsFermat(big.NewInt(int64(l2Parent.Number + 1))) { - l1BaseFee = bsc.BaseFeeByNetworks(ba.rollupCfg.L2ChainID) + if l1BaseFeeFromStateless != nil { + // op-enclave is using the l1 base fee from stateless + l1BaseFee = l1BaseFeeFromStateless } else { - _, transactions, err := ba.l1.InfoAndTxsByHash(ctx, epoch.Hash) - if err != nil { - return nil, NewTemporaryError(fmt.Errorf("failed to fetch L1 block info and txs: %w", err)) + if ba.rollupCfg.IsSnow(ba.rollupCfg.NextSecondBlockTime(l2Parent.MillisecondTimestamp())) { + l1BaseFee, err = SnowL1GasPrice(ctx, ba, epoch) + if err != nil { + return nil, err + } + } else if ba.rollupCfg.IsFermat(big.NewInt(int64(l2Parent.Number + 1))) { + l1BaseFee = bsc.BaseFeeByNetworks(ba.rollupCfg.L2ChainID) + } else { + _, transactions, err := ba.l1.InfoAndTxsByHash(ctx, epoch.Hash) + if err != nil { + return nil, NewTemporaryError(fmt.Errorf("failed to fetch L1 block info and txs: %w", err)) + } + l1BaseFee = bsc.BaseFeeByTransactions(transactions) } - l1BaseFee = bsc.BaseFeeByTransactions(transactions) } l1Info = bsc.NewBlockInfoBSCWrapper(l1Info, l1BaseFee) diff --git a/op-node/rollup/derive/attributes_queue.go b/op-node/rollup/derive/attributes_queue.go index 3e5218a7f7..1e77e17ec5 100644 --- a/op-node/rollup/derive/attributes_queue.go +++ b/op-node/rollup/derive/attributes_queue.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "math/big" "time" "github.com/ethereum/go-ethereum/log" @@ -24,7 +25,7 @@ import ( // This stage does not need to retain any references to L1 blocks. type AttributesBuilder interface { - PreparePayloadAttributes(ctx context.Context, l2Parent eth.L2BlockRef, epoch eth.BlockID) (attrs *eth.PayloadAttributes, err error) + PreparePayloadAttributes(ctx context.Context, l2Parent eth.L2BlockRef, epoch eth.BlockID, l1BaseFee *big.Int) (attrs *eth.PayloadAttributes, err error) CachePayloadByHash(payload *eth.ExecutionPayloadEnvelope) bool } @@ -93,7 +94,7 @@ func (aq *AttributesQueue) createNextAttributes(ctx context.Context, batch *Sing } fetchCtx, cancel := context.WithTimeout(ctx, 20*time.Second) defer cancel() - attrs, err := aq.builder.PreparePayloadAttributes(fetchCtx, l2SafeHead, batch.Epoch()) + attrs, err := aq.builder.PreparePayloadAttributes(fetchCtx, l2SafeHead, batch.Epoch(), nil) if err != nil { return nil, err } diff --git a/op-node/rollup/derive/attributes_test.go b/op-node/rollup/derive/attributes_test.go index b0197b4b3d..e93b9c8ecb 100644 --- a/op-node/rollup/derive/attributes_test.go +++ b/op-node/rollup/derive/attributes_test.go @@ -50,7 +50,7 @@ func TestPreparePayloadAttributes(t *testing.T) { epoch := l1Info.ID() l1Fetcher.ExpectFetchReceipts(epoch.Hash, l1Info, nil, nil) attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher) - _, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch) + _, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch, nil) require.NotNil(t, err, "inconsistent L1 origin error expected") require.ErrorIs(t, err, ErrReset, "inconsistent L1 origin transition must be handled like a critical error with reorg") }) @@ -66,7 +66,7 @@ func TestPreparePayloadAttributes(t *testing.T) { l1Info.InfoNum = l2Parent.L1Origin.Number epoch := l1Info.ID() attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher) - _, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch) + _, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch, nil) require.NotNil(t, err, "inconsistent L1 origin error expected") require.ErrorIs(t, err, ErrReset, "inconsistent L1 origin transition must be handled like a critical error with reorg") }) @@ -83,7 +83,7 @@ func TestPreparePayloadAttributes(t *testing.T) { mockRPCErr := errors.New("mock rpc error") l1Fetcher.ExpectFetchReceipts(epoch.Hash, nil, nil, mockRPCErr) attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher) - _, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch) + _, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch, nil) require.ErrorIs(t, err, mockRPCErr, "mock rpc error expected") require.ErrorIs(t, err, ErrTemporary, "rpc errors should not be critical, it is not necessary to reorg") }) @@ -99,7 +99,7 @@ func TestPreparePayloadAttributes(t *testing.T) { mockRPCErr := errors.New("mock rpc error") l1Fetcher.ExpectInfoByHash(epoch.Hash, nil, mockRPCErr) attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher) - _, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch) + _, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch, nil) require.ErrorIs(t, err, mockRPCErr, "mock rpc error expected") require.ErrorIs(t, err, ErrTemporary, "rpc errors should not be critical, it is not necessary to reorg") }) @@ -119,7 +119,7 @@ func TestPreparePayloadAttributes(t *testing.T) { require.NoError(t, err) l1Fetcher.ExpectFetchReceipts(epoch.Hash, l1Info, nil, nil) attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher) - attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch) + attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch, nil) require.NoError(t, err) require.NotNil(t, attrs) require.Equal(t, l2Parent.Time+cfg.BlockTime, uint64(attrs.Timestamp)) @@ -159,7 +159,7 @@ func TestPreparePayloadAttributes(t *testing.T) { l1Fetcher.ExpectFetchReceipts(epoch.Hash, l1Info, receipts, nil) attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher) - attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch) + attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch, nil) require.NoError(t, err) require.NotNil(t, attrs) require.Equal(t, l2Parent.Time+cfg.BlockTime, uint64(attrs.Timestamp)) @@ -187,7 +187,7 @@ func TestPreparePayloadAttributes(t *testing.T) { l1Fetcher.ExpectInfoByHash(epoch.Hash, l1Info, nil) attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher) - attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch) + attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch, nil) require.NoError(t, err) require.NotNil(t, attrs) require.Equal(t, l2Parent.Time+cfg.BlockTime, uint64(attrs.Timestamp)) @@ -242,7 +242,7 @@ func TestPreparePayloadAttributes(t *testing.T) { require.NoError(t, err) l1Fetcher.ExpectFetchReceipts(epoch.Hash, l1Info, nil, nil) attrBuilder := NewFetchingAttributesBuilder(cfg, l1Fetcher, l1CfgFetcher) - attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch) + attrs, err := attrBuilder.PreparePayloadAttributes(context.Background(), l2Parent, epoch, nil) require.NoError(t, err) require.Equal(t, l1InfoTx, []byte(attrs.Transactions[0])) }) diff --git a/op-node/rollup/driver/sequencer.go b/op-node/rollup/driver/sequencer.go index 76bd91192a..cc67d60a66 100644 --- a/op-node/rollup/driver/sequencer.go +++ b/op-node/rollup/driver/sequencer.go @@ -89,7 +89,7 @@ func (d *Sequencer) StartBuildingBlock(ctx context.Context) error { defer cancel() start = time.Now() - attrs, err := d.attrBuilder.PreparePayloadAttributes(fetchCtx, l2Head, l1Origin.ID()) + attrs, err := d.attrBuilder.PreparePayloadAttributes(fetchCtx, l2Head, l1Origin.ID(), nil) if err != nil { return err } diff --git a/op-node/rollup/driver/sequencer_test.go b/op-node/rollup/driver/sequencer_test.go index 786a52c871..fe4a4fe86a 100644 --- a/op-node/rollup/driver/sequencer_test.go +++ b/op-node/rollup/driver/sequencer_test.go @@ -131,7 +131,7 @@ var _ derive.EngineControl = (*FakeEngineControl)(nil) type testAttrBuilderFn func(ctx context.Context, l2Parent eth.L2BlockRef, epoch eth.BlockID) (attrs *eth.PayloadAttributes, err error) -func (fn testAttrBuilderFn) PreparePayloadAttributes(ctx context.Context, l2Parent eth.L2BlockRef, epoch eth.BlockID) (attrs *eth.PayloadAttributes, err error) { +func (fn testAttrBuilderFn) PreparePayloadAttributes(ctx context.Context, l2Parent eth.L2BlockRef, epoch eth.BlockID, l1BaseFeeFromStateless *big.Int) (attrs *eth.PayloadAttributes, err error) { return fn(ctx, l2Parent, epoch) }