Skip to content

Commit

Permalink
feat: enable multi frame txs and frame size setting for calldata txs
Browse files Browse the repository at this point in the history
  • Loading branch information
emilianobonassi authored and tuxcanfly committed Aug 8, 2024
1 parent 1ba5ebf commit dffc561
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
3 changes: 3 additions & 0 deletions op-batcher/batcher/channel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 10 additions & 2 deletions op-batcher/batcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions op-batcher/batcher/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions op-batcher/batcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion op-batcher/batcher/test_batch_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions op-batcher/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -169,6 +181,8 @@ var optionalFlags = []cli.Flag{
MaxPendingTransactionsFlag,
MaxChannelDurationFlag,
MaxL1TxSizeBytesFlag,
MaxFrameSizeFlag,
MultiFrameTxsFlag,
TargetNumFramesFlag,
ApproxComprRatioFlag,
CompressorFlag,
Expand Down
2 changes: 1 addition & 1 deletion op-e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit dffc561

Please sign in to comment.