kona_protocol/batch/
element.rs

1//! Span Batch Element
2
3use crate::SingleBatch;
4use alloc::vec::Vec;
5use alloy_primitives::Bytes;
6
7/// MAX_SPAN_BATCH_ELEMENTS is the maximum number of blocks, transactions in total,
8/// or transaction per block allowed in a span batch.
9pub const MAX_SPAN_BATCH_ELEMENTS: u64 = 10_000_000;
10
11/// A single batch element is similar to the [`SingleBatch`] type
12/// but does not contain the parent hash and epoch hash since spans
13/// do not contain this data for every block in the span.
14#[derive(Debug, Default, Clone, PartialEq, Eq)]
15pub struct SpanBatchElement {
16    /// The epoch number of the L1 block
17    pub epoch_num: u64,
18    /// The timestamp of the L2 block
19    pub timestamp: u64,
20    /// The transactions in the L2 block
21    pub transactions: Vec<Bytes>,
22}
23
24impl From<SingleBatch> for SpanBatchElement {
25    fn from(batch: SingleBatch) -> Self {
26        Self {
27            epoch_num: batch.epoch_num,
28            timestamp: batch.timestamp,
29            transactions: batch.transactions,
30        }
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37    use proptest::{collection::vec, prelude::any, proptest};
38
39    proptest! {
40        #[test]
41        fn test_span_batch_element_from_single_batch(epoch_num in 0u64..u64::MAX, timestamp in 0u64..u64::MAX, transactions in vec(any::<Bytes>(), 0..100)) {
42            let single_batch = SingleBatch {
43                epoch_num,
44                timestamp,
45                transactions: transactions.clone(),
46                ..Default::default()
47            };
48
49            let span_batch_element: SpanBatchElement = single_batch.into();
50
51            assert_eq!(span_batch_element.epoch_num, epoch_num);
52            assert_eq!(span_batch_element.timestamp, timestamp);
53            assert_eq!(span_batch_element.transactions, transactions);
54        }
55    }
56}