Commit 75040ca5 authored by Conner Fromknecht's avatar Conner Fromknecht

feat: add MIN_L1_TX_SIZE configuration

parent 42d02bcc
---
'@eth-optimism/batch-submitter-service': patch
---
Adds MIN_L1_TX_SIZE configuration
...@@ -27,6 +27,10 @@ func Main(gitVersion string) func(ctx *cli.Context) error { ...@@ -27,6 +27,10 @@ func Main(gitVersion string) func(ctx *cli.Context) error {
return err return err
} }
log.Info("Config parsed",
"min_tx_size", cfg.MinL1TxSize,
"max_tx_size", cfg.MaxL1TxSize)
// The call to defer is done here so that any errors logged from // The call to defer is done here so that any errors logged from
// this point on are posted to Sentry before exiting. // this point on are posted to Sentry before exiting.
if cfg.SentryEnable { if cfg.SentryEnable {
...@@ -121,6 +125,7 @@ func Main(gitVersion string) func(ctx *cli.Context) error { ...@@ -121,6 +125,7 @@ func Main(gitVersion string) func(ctx *cli.Context) error {
L1Client: l1Client, L1Client: l1Client,
L2Client: l2Client, L2Client: l2Client,
BlockOffset: cfg.BlockOffset, BlockOffset: cfg.BlockOffset,
MinTxSize: cfg.MinL1TxSize,
MaxTxSize: cfg.MaxL1TxSize, MaxTxSize: cfg.MaxL1TxSize,
CTCAddr: ctcAddress, CTCAddr: ctcAddress,
ChainID: chainID, ChainID: chainID,
......
...@@ -197,6 +197,7 @@ func NewConfig(ctx *cli.Context) (Config, error) { ...@@ -197,6 +197,7 @@ func NewConfig(ctx *cli.Context) (Config, error) {
L2EthRpc: ctx.GlobalString(flags.L2EthRpcFlag.Name), L2EthRpc: ctx.GlobalString(flags.L2EthRpcFlag.Name),
CTCAddress: ctx.GlobalString(flags.CTCAddressFlag.Name), CTCAddress: ctx.GlobalString(flags.CTCAddressFlag.Name),
SCCAddress: ctx.GlobalString(flags.SCCAddressFlag.Name), SCCAddress: ctx.GlobalString(flags.SCCAddressFlag.Name),
MinL1TxSize: ctx.GlobalUint64(flags.MinL1TxSizeFlag.Name),
MaxL1TxSize: ctx.GlobalUint64(flags.MaxL1TxSizeFlag.Name), MaxL1TxSize: ctx.GlobalUint64(flags.MaxL1TxSizeFlag.Name),
MaxBatchSubmissionTime: ctx.GlobalDuration(flags.MaxBatchSubmissionTimeFlag.Name), MaxBatchSubmissionTime: ctx.GlobalDuration(flags.MaxBatchSubmissionTimeFlag.Name),
PollInterval: ctx.GlobalDuration(flags.PollIntervalFlag.Name), PollInterval: ctx.GlobalDuration(flags.PollIntervalFlag.Name),
......
...@@ -32,6 +32,7 @@ type Config struct { ...@@ -32,6 +32,7 @@ type Config struct {
L1Client *ethclient.Client L1Client *ethclient.Client
L2Client *l2ethclient.Client L2Client *l2ethclient.Client
BlockOffset uint64 BlockOffset uint64
MinTxSize uint64
MaxTxSize uint64 MaxTxSize uint64
CTCAddr common.Address CTCAddr common.Address
ChainID *big.Int ChainID *big.Int
...@@ -150,7 +151,8 @@ func (d *Driver) GetBatchBlockRange( ...@@ -150,7 +151,8 @@ func (d *Driver) GetBatchBlockRange(
// CraftBatchTx transforms the L2 blocks between start and end into a batch // CraftBatchTx transforms the L2 blocks between start and end into a batch
// transaction using the given nonce. A dummy gas price is used in the resulting // transaction using the given nonce. A dummy gas price is used in the resulting
// transaction to use for size estimation. // transaction to use for size estimation. A nil transaction is returned if the
// transaction does not meet the minimum size requirements.
// //
// NOTE: This method SHOULD NOT publish the resulting transaction. // NOTE: This method SHOULD NOT publish the resulting transaction.
func (d *Driver) CraftBatchTx( func (d *Driver) CraftBatchTx(
...@@ -211,13 +213,18 @@ func (d *Driver) CraftBatchTx( ...@@ -211,13 +213,18 @@ func (d *Driver) CraftBatchTx(
batchCallData := append(appendSequencerBatchID, batchArguments...) batchCallData := append(appendSequencerBatchID, batchArguments...)
// Continue pruning until calldata size is less than configured max. // Continue pruning until calldata size is less than configured max.
if uint64(len(batchCallData)) > d.cfg.MaxTxSize { calldataSize := uint64(len(batchCallData))
if calldataSize > d.cfg.MaxTxSize {
oldLen := len(batchElements) oldLen := len(batchElements)
newBatchElementsLen := (oldLen * 9) / 10 newBatchElementsLen := (oldLen * 9) / 10
batchElements = batchElements[:newBatchElementsLen] batchElements = batchElements[:newBatchElementsLen]
log.Info(name+" pruned batch", "old_num_txs", oldLen, "new_num_txs", newBatchElementsLen) log.Info(name+" pruned batch", "old_num_txs", oldLen, "new_num_txs", newBatchElementsLen)
pruneCount++ pruneCount++
continue continue
} else if calldataSize < d.cfg.MinTxSize {
log.Info(name+" batch tx size below minimum",
"size", calldataSize, "min_tx_size", d.cfg.MinTxSize)
return nil, nil
} }
d.metrics.NumElementsPerBatch().Observe(float64(len(batchElements))) d.metrics.NumElementsPerBatch().Observe(float64(len(batchElements)))
......
...@@ -52,6 +52,13 @@ var ( ...@@ -52,6 +52,13 @@ var (
Required: true, Required: true,
EnvVar: "SCC_ADDRESS", EnvVar: "SCC_ADDRESS",
} }
MinL1TxSizeFlag = cli.Uint64Flag{
Name: "min-l1-tx-size",
Usage: "Minimum size in bytes of any L1 transaction that gets " +
"generated by the batch submitter",
Required: true,
EnvVar: prefixEnvVar("MIN_L1_TX_SIZE"),
}
MaxL1TxSizeFlag = cli.Uint64Flag{ MaxL1TxSizeFlag = cli.Uint64Flag{
Name: "max-l1-tx-size", Name: "max-l1-tx-size",
Usage: "Maximum size in bytes of any L1 transaction that gets " + Usage: "Maximum size in bytes of any L1 transaction that gets " +
...@@ -231,6 +238,7 @@ var requiredFlags = []cli.Flag{ ...@@ -231,6 +238,7 @@ var requiredFlags = []cli.Flag{
L2EthRpcFlag, L2EthRpcFlag,
CTCAddressFlag, CTCAddressFlag,
SCCAddressFlag, SCCAddressFlag,
MinL1TxSizeFlag,
MaxL1TxSizeFlag, MaxL1TxSizeFlag,
MaxBatchSubmissionTimeFlag, MaxBatchSubmissionTimeFlag,
PollIntervalFlag, PollIntervalFlag,
......
...@@ -46,7 +46,9 @@ type Driver interface { ...@@ -46,7 +46,9 @@ type Driver interface {
// CraftBatchTx transforms the L2 blocks between start and end into a batch // CraftBatchTx transforms the L2 blocks between start and end into a batch
// transaction using the given nonce. A dummy gas price is used in the // transaction using the given nonce. A dummy gas price is used in the
// resulting transaction to use for size estimation. // resulting transaction to use for size estimation. The driver may return a
// nil value for transaction if there is no action that needs to be
// performed.
// //
// NOTE: This method SHOULD NOT publish the resulting transaction. // NOTE: This method SHOULD NOT publish the resulting transaction.
CraftBatchTx( CraftBatchTx(
...@@ -184,6 +186,8 @@ func (s *Service) eventLoop() { ...@@ -184,6 +186,8 @@ func (s *Service) eventLoop() {
log.Error(name+" unable to craft batch tx", log.Error(name+" unable to craft batch tx",
"err", err) "err", err)
continue continue
} else if tx == nil {
continue
} }
batchTxBuildTime := time.Since(batchTxBuildStart) / time.Millisecond batchTxBuildTime := time.Since(batchTxBuildStart) / time.Millisecond
s.metrics.BatchTxBuildTimeMs().Set(float64(batchTxBuildTime)) s.metrics.BatchTxBuildTimeMs().Set(float64(batchTxBuildTime))
......
...@@ -4,6 +4,7 @@ ETH_NETWORK_NAME=clique ...@@ -4,6 +4,7 @@ ETH_NETWORK_NAME=clique
LOG_LEVEL=debug LOG_LEVEL=debug
BATCH_SUBMITTER_LOG_LEVEL=debug BATCH_SUBMITTER_LOG_LEVEL=debug
BATCH_SUBMITTER_LOG_TERMINAL=true BATCH_SUBMITTER_LOG_TERMINAL=true
BATCH_SUBMITTER_MIN_L1_TX_SIZE=32
BATCH_SUBMITTER_MAX_L1_TX_SIZE=90000 BATCH_SUBMITTER_MAX_L1_TX_SIZE=90000
BATCH_SUBMITTER_MAX_BATCH_SUBMISSION_TIME=0 BATCH_SUBMITTER_MAX_BATCH_SUBMISSION_TIME=0
BATCH_SUBMITTER_POLL_INTERVAL=500ms BATCH_SUBMITTER_POLL_INTERVAL=500ms
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment