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
54
55
56
57
58
59
60
61
62
63
64
65
//! 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 core::fmt::Display for BatchValidity {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Drop => write!(f, "Drop"),
Self::Accept => write!(f, "Accept"),
Self::Undecided => write!(f, "Undecided"),
Self::Future => write!(f, "Future"),
Self::Past => write!(f, "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());
}
}