Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/protocol/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

mod r#type;
pub use r#type::*;

mod validity;
pub use validity::BatchValidity;
53 changes: 53 additions & 0 deletions crates/protocol/src/batch/validity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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());
}
}
2 changes: 1 addition & 1 deletion crates/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
extern crate alloc;

mod batch;
pub use batch::{BatchType, SINGLE_BATCH_TYPE, SPAN_BATCH_TYPE};
pub use batch::{BatchType, BatchValidity, SINGLE_BATCH_TYPE, SPAN_BATCH_TYPE};

mod block;
pub use block::{BlockInfo, FromBlockError, L2BlockInfo};
Expand Down