agglayer_types/
epoch.rs

1#[derive(
2    Clone,
3    Copy,
4    Debug,
5    Default,
6    Eq,
7    Ord,
8    PartialEq,
9    PartialOrd,
10    derive_more::Display,
11    derive_more::From,
12    serde::Deserialize,
13    serde::Serialize,
14)]
15#[cfg_attr(feature = "testutils", derive(arbitrary::Arbitrary))]
16#[serde(transparent)]
17pub struct EpochNumber(u64);
18
19impl EpochNumber {
20    pub const ZERO: EpochNumber = EpochNumber(0);
21    pub const ONE: EpochNumber = EpochNumber(1);
22
23    pub const fn new(epoch: u64) -> EpochNumber {
24        EpochNumber(epoch)
25    }
26
27    #[must_use = "The value of the next epoch is returned but not used"]
28    pub const fn next(&self) -> EpochNumber {
29        EpochNumber(self.0.checked_add(1).expect("Epoch number overflow"))
30    }
31
32    pub const fn increment(&mut self) {
33        *self = self.next();
34    }
35
36    pub const fn as_u64(&self) -> u64 {
37        self.0
38    }
39}
40
41#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
42#[cfg_attr(feature = "testutils", derive(arbitrary::Arbitrary))]
43pub struct EpochConfiguration {
44    /// The genesis block where the AggLayer starts.
45    pub genesis_block: u64,
46    /// The duration of an epoch in blocks.
47    pub epoch_duration: u64,
48}