Commit 526eac8d authored by Conner Fromknecht's avatar Conner Fromknecht Committed by GitHub

feat: bss less strict min-tx-size (#2423)

* feat: improve pruning logging

* feat: split out else if into own conditional

This is equivalent since the if branch continues.

* feat: only contrain minimum tx size on first pass

* feat: ignore minimum tx contraint when observing large elements

* Create chilled-penguins-kneel.md
Co-authored-by: default avatarMark Tyneway <mark.tyneway@gmail.com>
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent f2bcdd5a
---
"@eth-optimism/batch-submitter-service": patch
---
feat: bss less strict min-tx-size
...@@ -167,8 +167,9 @@ func (d *Driver) CraftBatchTx( ...@@ -167,8 +167,9 @@ func (d *Driver) CraftBatchTx(
"nonce", nonce, "type", d.cfg.BatchType.String()) "nonce", nonce, "type", d.cfg.BatchType.String())
var ( var (
batchElements []BatchElement batchElements []BatchElement
totalTxSize uint64 totalTxSize uint64
hasLargeNextTx bool
) )
for i := new(big.Int).Set(start); i.Cmp(end) < 0; i.Add(i, bigOne) { for i := new(big.Int).Set(start); i.Cmp(end) < 0; i.Add(i, bigOne) {
block, err := d.cfg.L2Client.BlockByNumber(ctx, i) block, err := d.cfg.L2Client.BlockByNumber(ctx, i)
...@@ -187,6 +188,12 @@ func (d *Driver) CraftBatchTx( ...@@ -187,6 +188,12 @@ func (d *Driver) CraftBatchTx(
// size also adheres to this constraint. // size also adheres to this constraint.
txLen := batchElement.Tx.Size() txLen := batchElement.Tx.Size()
if totalTxSize+uint64(TxLenSize+txLen) > d.cfg.MaxTxSize { if totalTxSize+uint64(TxLenSize+txLen) > d.cfg.MaxTxSize {
// Adding this transaction causes the batch to be too large, but
// we also record if the batch size without the transaction
// fails to meet our minimum size constraint. This is used below
// to determine whether or not to ignore the minimum size check,
// since in this case it can't be avoided.
hasLargeNextTx = totalTxSize < d.cfg.MinTxSize
break break
} }
totalTxSize += uint64(TxLenSize + txLen) totalTxSize += uint64(TxLenSize + txLen)
...@@ -214,6 +221,11 @@ func (d *Driver) CraftBatchTx( ...@@ -214,6 +221,11 @@ func (d *Driver) CraftBatchTx(
appendSequencerBatchID := d.ctcABI.Methods[appendSequencerBatchMethodName].ID appendSequencerBatchID := d.ctcABI.Methods[appendSequencerBatchMethodName].ID
plaintextCalldata := append(appendSequencerBatchID, plaintextBatchArguments...) plaintextCalldata := append(appendSequencerBatchID, plaintextBatchArguments...)
log.Info(name+" testing batch size",
"plaintext_size", len(plaintextCalldata),
"min_tx_size", d.cfg.MinTxSize,
"max_tx_size", d.cfg.MaxTxSize)
// Continue pruning until plaintext calldata size is less than // Continue pruning until plaintext calldata size is less than
// configured max. // configured max.
plaintextCalldataSize := uint64(len(plaintextCalldata)) plaintextCalldataSize := uint64(len(plaintextCalldata))
...@@ -222,16 +234,33 @@ func (d *Driver) CraftBatchTx( ...@@ -222,16 +234,33 @@ func (d *Driver) CraftBatchTx(
newBatchElementsLen := (oldLen * 9) / 10 newBatchElementsLen := (oldLen * 9) / 10
batchElements = batchElements[:newBatchElementsLen] batchElements = batchElements[:newBatchElementsLen]
log.Info(name+" pruned batch", log.Info(name+" pruned batch",
"plaintext_size", plaintextCalldataSize,
"max_tx_size", d.cfg.MaxTxSize,
"old_num_txs", oldLen, "old_num_txs", oldLen,
"new_num_txs", newBatchElementsLen) "new_num_txs", newBatchElementsLen)
pruneCount++ pruneCount++
continue continue
} else if plaintextCalldataSize < d.cfg.MinTxSize { }
// There are two specific cases in which we choose to ignore the minimum
// L1 tx size. These cases are permitted since they arise from
// situations where the difference between the configured MinTxSize and
// MaxTxSize is less than the maximum L2 tx size permitted by the
// mempool.
//
// This configuration is useful when trying to ensure the profitability
// is sufficient, and we permit batches to be submitted with less than
// our desired configuration only if it is not possible to construct a
// batch within the given parameters.
//
// The two cases are:
// 1. When the next elenent is larger than the difference between the
// min and the max, causing the batch to be too small without the
// element, and too large with it.
// 2. When pruning a batch that exceeds the mac size below, and then
// becomes too small as a result. This is avoided by only applying
// the min size check when the pruneCount is zero.
ignoreMinTxSize := pruneCount > 0 || hasLargeNextTx
if !ignoreMinTxSize && plaintextCalldataSize < d.cfg.MinTxSize {
log.Info(name+" batch tx size below minimum", log.Info(name+" batch tx size below minimum",
"plaintext_size", plaintextCalldataSize,
"min_tx_size", d.cfg.MinTxSize,
"num_txs", len(batchElements)) "num_txs", len(batchElements))
return nil, nil return nil, nil
} }
...@@ -249,7 +278,10 @@ func (d *Driver) CraftBatchTx( ...@@ -249,7 +278,10 @@ func (d *Driver) CraftBatchTx(
calldata = append(appendSequencerBatchID, batchArguments...) calldata = append(appendSequencerBatchID, batchArguments...)
} }
log.Info(name+" batch constructed", "num_txs", len(batchElements), "length", len(calldata)) log.Info(name+" batch constructed",
"num_txs", len(batchElements),
"final_size", len(calldata),
"batch_type", d.cfg.BatchType)
opts, err := bind.NewKeyedTransactorWithChainID( opts, err := bind.NewKeyedTransactorWithChainID(
d.cfg.PrivKey, d.cfg.ChainID, d.cfg.PrivKey, d.cfg.ChainID,
......
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