op_alloy_protocol/batch/
validity.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
45
46
47
48
49
50
51
52
53
//! Contains the [BatchValidity] and its encodings.

/// Batch Validity
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BatchValidity {
    /// The batch is invalid now and in the future, unless we reorg, so it can be discarded.
    Drop,
    /// The batch is valid and should be processed
    Accept,
    /// We are lacking L1 information until we can proceed batch filtering
    Undecided,
    /// The batch may be valid, but cannot be processed yet and should be checked again later
    Future,
    /// Introduced in Holocene, a special variant of the `Drop` variant that signals not to flush
    /// the active batch and channel, in the case of processing an old batch
    Past,
}

impl BatchValidity {
    /// Returns whether the batch is accepted.
    pub const fn is_accept(&self) -> bool {
        matches!(self, Self::Accept)
    }

    /// Returns whether the batch is dropped.
    pub const fn is_drop(&self) -> bool {
        matches!(self, Self::Drop)
    }

    /// Returns whether the batch is outdated.
    pub const fn is_outdated(&self) -> bool {
        matches!(self, Self::Past)
    }

    /// Returns whether the batch is future.
    pub const fn is_future(&self) -> bool {
        matches!(self, Self::Future)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_batch_validity() {
        assert!(BatchValidity::Accept.is_accept());
        assert!(BatchValidity::Drop.is_drop());
        assert!(BatchValidity::Past.is_outdated());
        assert!(BatchValidity::Future.is_future());
    }
}