tsoracle_core/epoch.rs
1//
2// ░▀█▀░█▀▀░█▀█░█▀▄░█▀█░█▀▀░█░░░█▀▀
3// ░░█░░▀▀█░█░█░█▀▄░█▀█░█░░░█░░░█▀▀
4// ░░▀░░▀▀▀░▀▀▀░▀░▀░▀░▀░▀▀▀░▀▀▀░▀▀▀
5//
6// tsoracle — Distributed Timestamp Oracle
7//
8// Copyright (c) 2026 Prisma Risk
9// Licensed under the Apache License, Version 2.0
10// https://github.com/prisma-risk/tsoracle
11//
12
13//! Leader epoch — opaque monotonic identifier chosen by the consensus driver.
14
15#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17pub struct Epoch(pub u64);
18
19impl Epoch {
20 pub const ZERO: Epoch = Epoch(0);
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26
27 #[test]
28 fn default_is_zero() {
29 assert_eq!(Epoch::default(), Epoch::ZERO);
30 }
31
32 #[test]
33 fn ordering() {
34 assert!(Epoch(1) < Epoch(2));
35 assert!(Epoch::ZERO < Epoch(1));
36 }
37}