Batches
A Batch contains a list of transactions to be included in a specific
L2 block. Since the Delta hardfork, there are two Batch types or
variants: SingleBatch
and SpanBatch
.
Where Batches fit in the OP Stack
The Batch is the highest-level data type in the OP Stack derivation process that comes prior to building payload attributes. A Batch is constructed by taking the raw data from a Channel, decompressing it, and decoding the Batch from this decompressed data.
Alternatively, when looking at the Batch type from a batching
perspective, and not from the derivation perspective, the Batch
type contains a list of L2 transactions and is compressed into the
Channel
type. In turn, the Channel
is split
into frames which are posted to the data availability layer through batcher
transactions.
Contents of a Batch
A Batch
is either a SingleBatch
or a
SpanBatch
, each with their own contents. Below,
these types are broken down in their respective sections.
SingleBatch
Type
The SingleBatch
type contains the following.
- A
BlockHash
parent hash that represents the parent L2 block. - A
u64
epoch number that identifies the epoch for this batch. - A
BlockHash
epoch hash. - The timestamp for the batch as a
u64
. - A list of EIP-2718 encoded transactions (represented as
Bytes
).
In order to validate the SingleBatch
once decoded,
the SingleBatch::check_batch
method should be used,
providing the rollup config, l1 blocks, l2 safe head, and inclusion block.
SpanBatch
Type
The SpanBatch
type (available since the Delta hardfork)
comprises the data needed to build a "span" of multiple L2 blocks. It contains
the following data.
- The parent check (the first 20 bytes of the block's parent hash).
- The l1 origin check (the first 20 bytes of the last block's l1 origin hash).
- The genesis timestamp.
- The chain id.
- A list of
SpanBatchElement
s. These are similar to theSingleBatch
type but don't contain the parent hash and epoch hash for this L2 block. - Origin bits.
- Block transaction counts.
- Span batch transactions which contain information for transactions in a span batch.
Similar to the SingleBatch
type discussed above, the SpanBatch
type
must be validated once decoded. For this, the SpanBatch::check_batch
method is available.
After the Holocene hardfork was introduced, span batch validation is greatly
simplified to be forwards-invalidating instead of backwards-invalidating, so a new
SpanBatch::check_batch_prefix
method provides a way to validate
each batch as it is loaded, in an iterative fashion.
Batch Encoding
The first byte of the decompressed channel data is the
BatchType
, which identifies whether the batch is a
SingleBatch
or a SpanBatch
.
From there, the respective type is decoded, and derived
in the case of the SpanBatch
.
The Batch
encoding format for the SingleBatch
is
broken down in the specs.
The Batch
Type
The Batch
type itself only provides two useful methods.
timestamp
returns the timestamp of theBatch
deocde
, constructs a newBatch
from the provided raw, decompressed batch data and rollup config.
Within each Batch
variant, the individual types contain
more functionality.