Skip to content

Commit

Permalink
delete size limit for rollup process
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethanncnm committed Jul 20, 2023
1 parent 6eabc03 commit 7b93641
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 136 deletions.
67 changes: 2 additions & 65 deletions batch-submitter/drivers/sequencer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,8 @@ func (d *Driver) CraftBatchTx(
log.Info(name+" crafting batch tx", "start", start, "end", end,
"nonce", nonce, "type", d.cfg.BatchType.String())

var (
batchElements []BatchElement
totalTxSize uint64
hasLargeNextTx bool
)
var batchElements []BatchElement

for i := new(big.Int).Set(start); i.Cmp(end) < 0; i.Add(i, bigOne) {
block, err := d.cfg.L2Client.BlockByNumber(ctx, i)
if err != nil {
Expand All @@ -252,30 +249,10 @@ func (d *Driver) CraftBatchTx(
// For each sequencer transaction, update our running total with the
// size of the transaction.
batchElement := BatchElementFromBlock(block)
if batchElement.IsSequencerTx() {
// Abort once the total size estimate is greater than the maximum
// configured size. This is a conservative estimate, as the total
// calldata size will be greater when batch contexts are included.
// Below this set will be further whittled until the raw call data
// size also adheres to this constraint.
txLen := batchElement.Tx.Size()
if totalTxSize+uint64(TxLenSize+txLen) > d.cfg.MaxPlaintextBatchSize {
// 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
}
totalTxSize += uint64(TxLenSize + txLen)
}

batchElements = append(batchElements, batchElement)
}

shouldStartAt := start.Uint64()
var pruneCount int
for {
batchParams, err := GenSequencerBatchParams(
shouldStartAt, d.cfg.BlockOffset, batchElements,
Expand All @@ -298,47 +275,7 @@ func (d *Driver) CraftBatchTx(
"min_tx_size", d.cfg.MinTxSize,
"max_tx_size", d.cfg.MaxTxSize)

// Continue pruning until plaintext calldata size is less than
// configured max.
calldataSize := uint64(len(calldata))
if calldataSize > d.cfg.MaxTxSize {
oldLen := len(batchElements)
newBatchElementsLen := (oldLen * 9) / 10
batchElements = batchElements[:newBatchElementsLen]
log.Info(name+" pruned batch",
"old_num_txs", oldLen,
"new_num_txs", newBatchElementsLen)
pruneCount++
continue
}

// 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 && calldataSize < d.cfg.MinTxSize {
log.Info(name+" batch tx size below minimum",
"num_txs", len(batchElements))
return nil, nil
}

d.metrics.NumElementsPerBatch().Observe(float64(len(batchElements)))
d.metrics.BatchPruneCount.Set(float64(pruneCount))

log.Info(name+" batch constructed",
"num_txs", len(batchElements),
Expand Down
74 changes: 3 additions & 71 deletions batch-submitter/drivers/sequencer/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type AppendSequencerBatchParams struct {
Txs []*CachedTx
}

// Write encodes the AppendSequencerBatchParams using the following format:
// WriteNoTxn encodes the AppendSequencerBatchParams using the following format:
// - should_start_at_element: 5 bytes
// - total_elements_to_append: 3 bytes
// - num_contexts: 3 bytes
Expand All @@ -210,68 +210,6 @@ type AppendSequencerBatchParams struct {
//
// Note that writing to a bytes.Buffer cannot
// error, so errors are ignored here
func (p *AppendSequencerBatchParams) Write(
w *bytes.Buffer,
batchType BatchType,
) error {

_ = writeUint64(w, p.ShouldStartAtElement, 5)
_ = writeUint64(w, p.TotalElementsToAppend, 3)

// There must be contexts if there are transactions
if len(p.Contexts) == 0 && len(p.Txs) != 0 {
return ErrMalformedBatch
}

// There must be transactions if there are contexts
if len(p.Txs) == 0 && len(p.Contexts) != 0 {
return ErrMalformedBatch
}

// copy the contexts as to not malleate the struct
// when it is a typed batch
contexts := make([]BatchContext, 0, len(p.Contexts)+1)
// Add the marker context, if any, for non-legacy encodings.
markerContext := batchType.MarkerContext()
if markerContext != nil {
contexts = append(contexts, *markerContext)
}
contexts = append(contexts, p.Contexts...)

// Write number of contexts followed by each fixed-size BatchContext.
_ = writeUint64(w, uint64(len(contexts)), 3)
for _, context := range contexts {
context.Write(w)
}

switch batchType {
case BatchTypeLegacy:
// Write each length-prefixed tx.
for _, tx := range p.Txs {
_ = writeUint64(w, uint64(tx.Size()), TxLenSize)
_, _ = w.Write(tx.RawTx()) // can't fail for bytes.Buffer
}
case BatchTypeZlib:
zw := zlib.NewWriter(w)
for _, tx := range p.Txs {
if err := writeUint64(zw, uint64(tx.Size()), TxLenSize); err != nil {
return err
}
if _, err := zw.Write(tx.RawTx()); err != nil {
return err
}
}
if err := zw.Close(); err != nil {
return err
}

default:
return fmt.Errorf("Unknown batch type: %s", batchType)
}

return nil
}

func (p *AppendSequencerBatchParams) WriteNoTxn(
w *bytes.Buffer,
batchType BatchType,
Expand Down Expand Up @@ -315,14 +253,8 @@ func (p *AppendSequencerBatchParams) Serialize(
upgradeBlock *big.Int,
) ([]byte, error) {
var buf bytes.Buffer
if l2BlockNumber.Cmp(upgradeBlock) > 0 {
if err := p.WriteNoTxn(&buf, batchType); err != nil {
return nil, err
}
} else {
if err := p.Write(&buf, batchType); err != nil {
return nil, err
}
if err := p.WriteNoTxn(&buf, batchType); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
Expand Down

0 comments on commit 7b93641

Please sign in to comment.