kona_protocol/batch/validity.rs
1//! Contains the [BatchValidity] and its encodings.
2
3/// Batch Validity
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum BatchValidity {
7 /// The batch is invalid now and in the future, unless we reorg, so it can be discarded.
8 Drop,
9 /// The batch is valid and should be processed
10 Accept,
11 /// We are lacking L1 information until we can proceed batch filtering
12 Undecided,
13 /// The batch may be valid, but cannot be processed yet and should be checked again later
14 Future,
15 /// Introduced in Holocene, a special variant of the `Drop` variant that signals not to flush
16 /// the active batch and channel, in the case of processing an old batch
17 Past,
18}
19
20impl BatchValidity {
21 /// Returns whether the batch is accepted.
22 pub const fn is_accept(&self) -> bool {
23 matches!(self, Self::Accept)
24 }
25
26 /// Returns whether the batch is dropped.
27 pub const fn is_drop(&self) -> bool {
28 matches!(self, Self::Drop)
29 }
30
31 /// Returns whether the batch is outdated.
32 pub const fn is_outdated(&self) -> bool {
33 matches!(self, Self::Past)
34 }
35
36 /// Returns whether the batch is future.
37 pub const fn is_future(&self) -> bool {
38 matches!(self, Self::Future)
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_batch_validity() {
48 assert!(BatchValidity::Accept.is_accept());
49 assert!(BatchValidity::Drop.is_drop());
50 assert!(BatchValidity::Past.is_outdated());
51 assert!(BatchValidity::Future.is_future());
52 }
53}