From dffc5618de6a952e3d3caf3200d024e5d64ab226 Mon Sep 17 00:00:00 2001 From: Emiliano Bonassi Date: Fri, 10 May 2024 10:04:04 +0200 Subject: [PATCH] feat: enable multi frame txs and frame size setting for calldata txs --- op-batcher/batcher/channel_config.go | 3 +++ op-batcher/batcher/config.go | 12 ++++++++++-- op-batcher/batcher/driver.go | 4 ++-- op-batcher/batcher/service.go | 11 +++++++++++ op-batcher/batcher/test_batch_submitter.go | 2 +- op-batcher/flags/flags.go | 14 ++++++++++++++ op-e2e/setup.go | 2 +- 7 files changed, 42 insertions(+), 6 deletions(-) diff --git a/op-batcher/batcher/channel_config.go b/op-batcher/batcher/channel_config.go index a130dff2ba8e..92aa450c7cac 100644 --- a/op-batcher/batcher/channel_config.go +++ b/op-batcher/batcher/channel_config.go @@ -30,6 +30,9 @@ type ChannelConfig struct { // The maximum byte-size a frame can have. MaxFrameSize uint64 + // MultiFrameTxs controls whether to put all frames of a channel inside a single tx. + MultiFrameTxs bool + // Target number of frames to create per channel. // For blob transactions, this controls the number of blobs to target adding // to each blob tx. diff --git a/op-batcher/batcher/config.go b/op-batcher/batcher/config.go index 43f841cd8271..dc684183e2a1 100644 --- a/op-batcher/batcher/config.go +++ b/op-batcher/batcher/config.go @@ -57,6 +57,12 @@ type CLIConfig struct { // If using blobs, this setting is ignored and the max blob size is used. MaxL1TxSize uint64 + // MaxFrameSize is the maximum size of a frame in a batch tx. + MaxFrameSize uint64 + + // MultiFrameTxs controls whether to put all frames of a channel inside a single tx. + MultiFrameTxs bool + // The target number of frames to create per channel. Controls number of blobs // per blob tx, if using Blob DA. TargetNumFrames int @@ -102,8 +108,8 @@ type CLIConfig struct { MetricsConfig opmetrics.CLIConfig PprofConfig oppprof.CLIConfig RPC oprpc.CLIConfig - PlasmaDA plasma.CLIConfig - DaConfig celestia.CLIConfig + PlasmaDA plasma.CLIConfig + DaConfig celestia.CLIConfig } func (c *CLIConfig) Check() error { @@ -178,6 +184,8 @@ func NewConfig(ctx *cli.Context) *CLIConfig { MaxPendingTransactions: ctx.Uint64(flags.MaxPendingTransactionsFlag.Name), MaxChannelDuration: ctx.Uint64(flags.MaxChannelDurationFlag.Name), MaxL1TxSize: ctx.Uint64(flags.MaxL1TxSizeBytesFlag.Name), + MaxFrameSize: ctx.Uint64(flags.MaxFrameSizeFlag.Name), + MultiFrameTxs: ctx.Bool(flags.MultiFrameTxsFlag.Name), TargetNumFrames: ctx.Int(flags.TargetNumFramesFlag.Name), ApproxComprRatio: ctx.Float64(flags.ApproxComprRatioFlag.Name), Compressor: ctx.String(flags.CompressorFlag.Name), diff --git a/op-batcher/batcher/driver.go b/op-batcher/batcher/driver.go index 3fa8f346ea0c..2a16c7460676 100644 --- a/op-batcher/batcher/driver.go +++ b/op-batcher/batcher/driver.go @@ -543,7 +543,7 @@ func (l *BatchSubmitter) cancelBlockingTx(queue *txmgr.Queue[txRef], receiptsCh var candidate *txmgr.TxCandidate var err error if isBlockedBlob { - candidate = l.calldataTxCandidate([]byte{}) + candidate, _ = l.calldataTxCandidate([]byte{}) } else if candidate, err = l.blobTxCandidate(emptyTxData); err != nil { panic(err) // this error should not happen } @@ -568,7 +568,7 @@ func (l *BatchSubmitter) sendTransaction(ctx context.Context, txdata txData, que } } else { // sanity check - if nf := len(txdata.frames); nf != 1 { + if nf := len(txdata.frames); nf > l.ChannelConfig.ChannelConfig().TargetNumFrames { l.Log.Crit("Unexpected number of frames in calldata tx", "num_frames", nf) } data := txdata.CallData() diff --git a/op-batcher/batcher/service.go b/op-batcher/batcher/service.go index cd64c8f8c2bc..c3323b642738 100644 --- a/op-batcher/batcher/service.go +++ b/op-batcher/batcher/service.go @@ -201,11 +201,22 @@ func (bs *BatcherService) initChannelConfig(cfg *CLIConfig) error { ChannelTimeout: channelTimeout, MaxChannelDuration: cfg.MaxChannelDuration, MaxFrameSize: cfg.MaxL1TxSize - 1, // account for version byte prefix; reset for blobs + MultiFrameTxs: cfg.MultiFrameTxs, TargetNumFrames: cfg.TargetNumFrames, SubSafetyMargin: cfg.SubSafetyMargin, BatchType: cfg.BatchType, } + // override max frame size if set + if cfg.MaxFrameSize > 0 { + cc.MaxFrameSize = cfg.MaxFrameSize + } + + // enable multi-frame txs if set + if cfg.MultiFrameTxs { + cc.MultiFrameTxs = true + } + switch cfg.DataAvailabilityType { case flags.BlobsType, flags.AutoType: if !cfg.TestUseMaxTxSizeForBlobs { diff --git a/op-batcher/batcher/test_batch_submitter.go b/op-batcher/batcher/test_batch_submitter.go index 8814400f06ca..b0d03f279383 100644 --- a/op-batcher/batcher/test_batch_submitter.go +++ b/op-batcher/batcher/test_batch_submitter.go @@ -29,7 +29,7 @@ func (l *TestBatchSubmitter) JamTxPool(ctx context.Context) error { var err error cc := l.state.cfgProvider.ChannelConfig() if cc.UseBlobs { - candidate = l.calldataTxCandidate([]byte{}) + candidate, _ = l.calldataTxCandidate([]byte{}) } else if candidate, err = l.blobTxCandidate(emptyTxData); err != nil { return err } diff --git a/op-batcher/flags/flags.go b/op-batcher/flags/flags.go index 67390a0f2007..43b39db2f634 100644 --- a/op-batcher/flags/flags.go +++ b/op-batcher/flags/flags.go @@ -76,6 +76,18 @@ var ( Value: 120_000, // will be overwritten to max for blob da-type EnvVars: prefixEnvVars("MAX_L1_TX_SIZE_BYTES"), } + MaxFrameSizeFlag = &cli.Uint64Flag{ + Name: "max-frame-size-bytes", + Usage: "The maximum size of a frame. 0 to use default value (120k-1)", + Value: 0, + EnvVars: prefixEnvVars("MAX_FRAME_SIZE_BYTES"), + } + MultiFrameTxsFlag = &cli.BoolFlag{ + Name: "multi-frame-txs", + Usage: "Whether to put all frames of a channel inside a single tx. Ignored for blobs, where true will be used.", + Value: false, + EnvVars: prefixEnvVars("MULTI_FRAME_TXS"), + } TargetNumFramesFlag = &cli.IntFlag{ Name: "target-num-frames", Usage: "The target number of frames to create per channel. Controls number of blobs per blob tx, if using Blob DA.", @@ -169,6 +181,8 @@ var optionalFlags = []cli.Flag{ MaxPendingTransactionsFlag, MaxChannelDurationFlag, MaxL1TxSizeBytesFlag, + MaxFrameSizeFlag, + MultiFrameTxsFlag, TargetNumFramesFlag, ApproxComprRatioFlag, CompressorFlag, diff --git a/op-e2e/setup.go b/op-e2e/setup.go index 0883ff521177..9bfb102b56ad 100644 --- a/op-e2e/setup.go +++ b/op-e2e/setup.go @@ -927,7 +927,7 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste BatchType: batchType, DataAvailabilityType: sys.Cfg.DataAvailabilityType, CompressionAlgo: compressionAlgo, - DaConfig: celestia.CLIConfig{DaRpc: "localhost:26650"}, + DaConfig: celestia.CLIConfig{Rpc: "localhost:26650"}, } // Batch Submitter batcher, err := bss.BatcherServiceFromCLIConfig(context.Background(), "0.0.1", batcherCLIConfig, sys.Cfg.Loggers["batcher"])