op_alloy_protocol/batch/inclusion.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
//! Module containing the [BatchWithInclusionBlock] struct.
use crate::{Batch, BatchValidationProvider, BatchValidity, BlockInfo, L2BlockInfo};
use op_alloy_genesis::RollupConfig;
/// A batch with its inclusion block.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BatchWithInclusionBlock {
/// The inclusion block
pub inclusion_block: BlockInfo,
/// The batch
pub batch: Batch,
}
impl BatchWithInclusionBlock {
/// Creates a new batch with inclusion block.
pub const fn new(inclusion_block: BlockInfo, batch: Batch) -> Self {
Self { inclusion_block, batch }
}
/// Validates the batch can be applied on top of the specified L2 safe head.
/// The first entry of the l1_blocks should match the origin of the l2_safe_head.
/// One or more consecutive l1_blocks should be provided.
/// In case of only a single L1 block, the decision whether a batch is valid may have to stay
/// undecided.
pub async fn check_batch<BF: BatchValidationProvider>(
&self,
cfg: &RollupConfig,
l1_blocks: &[BlockInfo],
l2_safe_head: L2BlockInfo,
fetcher: &mut BF,
) -> BatchValidity {
match &self.batch {
Batch::Single(single_batch) => {
single_batch.check_batch(cfg, l1_blocks, l2_safe_head, &self.inclusion_block)
}
Batch::Span(span_batch) => {
span_batch
.check_batch(cfg, l1_blocks, l2_safe_head, &self.inclusion_block, fetcher)
.await
}
}
}
}