1use {
4 crate::{clone_zeroed, copy_field},
5 std::mem::MaybeUninit,
6};
7
8pub const DEFAULT_TICKS_PER_SECOND: u64 = 160;
11
12#[cfg(test)]
13static_assertions::const_assert_eq!(MS_PER_TICK, 6);
14pub const MS_PER_TICK: u64 = 1000 / DEFAULT_TICKS_PER_SECOND;
15
16#[cfg(test)]
17static_assertions::const_assert_eq!(SLOT_MS, 400);
18pub const SLOT_MS: u64 = (DEFAULT_TICKS_PER_SLOT * 1000) / DEFAULT_TICKS_PER_SECOND;
19
20pub const DEFAULT_TICKS_PER_SLOT: u64 = 64;
23
24pub const DEFAULT_HASHES_PER_SECOND: u64 = 2_000_000;
26
27#[cfg(test)]
28static_assertions::const_assert_eq!(DEFAULT_HASHES_PER_TICK, 12_500);
29pub const DEFAULT_HASHES_PER_TICK: u64 = DEFAULT_HASHES_PER_SECOND / DEFAULT_TICKS_PER_SECOND;
30
31pub const DEFAULT_DEV_SLOTS_PER_EPOCH: u64 = 8192;
33
34#[cfg(test)]
35static_assertions::const_assert_eq!(SECONDS_PER_DAY, 86_400);
36pub const SECONDS_PER_DAY: u64 = 24 * 60 * 60;
37
38#[cfg(test)]
39static_assertions::const_assert_eq!(TICKS_PER_DAY, 13_824_000);
40pub const TICKS_PER_DAY: u64 = DEFAULT_TICKS_PER_SECOND * SECONDS_PER_DAY;
41
42#[cfg(test)]
43static_assertions::const_assert_eq!(DEFAULT_SLOTS_PER_EPOCH, 432_000);
44pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 2 * TICKS_PER_DAY / DEFAULT_TICKS_PER_SLOT;
46
47pub const NUM_CONSECUTIVE_LEADER_SLOTS: u64 = 4;
49
50#[cfg(test)]
51static_assertions::const_assert_eq!(DEFAULT_MS_PER_SLOT, 400);
52pub const DEFAULT_MS_PER_SLOT: u64 = 1_000 * DEFAULT_TICKS_PER_SLOT / DEFAULT_TICKS_PER_SECOND;
53pub const DEFAULT_S_PER_SLOT: f64 = DEFAULT_TICKS_PER_SLOT as f64 / DEFAULT_TICKS_PER_SECOND as f64;
54
55pub const MAX_HASH_AGE_IN_SECONDS: usize = 120;
62
63#[cfg(test)]
64static_assertions::const_assert_eq!(MAX_RECENT_BLOCKHASHES, 300);
65pub const MAX_RECENT_BLOCKHASHES: usize =
67 MAX_HASH_AGE_IN_SECONDS * DEFAULT_TICKS_PER_SECOND as usize / DEFAULT_TICKS_PER_SLOT as usize;
68
69#[cfg(test)]
70static_assertions::const_assert_eq!(MAX_PROCESSING_AGE, 150);
71pub const MAX_PROCESSING_AGE: usize = MAX_RECENT_BLOCKHASHES / 2;
73
74pub const MAX_TRANSACTION_FORWARDING_DELAY_GPU: usize = 2;
77
78pub const MAX_TRANSACTION_FORWARDING_DELAY: usize = 6;
80
81pub type Slot = u64;
84
85pub type BankId = u64;
88
89pub type Epoch = u64;
92
93pub const GENESIS_EPOCH: Epoch = 0;
94pub const INITIAL_RENT_EPOCH: Epoch = 0;
96
97pub type SlotIndex = u64;
99
100pub type SlotCount = u64;
102
103pub type UnixTimestamp = i64;
106
107#[repr(C)]
113#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Eq)]
114pub struct Clock {
115 pub slot: Slot,
117 pub epoch_start_timestamp: UnixTimestamp,
119 pub epoch: Epoch,
121 pub leader_schedule_epoch: Epoch,
124 pub unix_timestamp: UnixTimestamp,
128}
129
130impl Clone for Clock {
131 fn clone(&self) -> Self {
132 clone_zeroed(|cloned: &mut MaybeUninit<Self>| {
133 let ptr = cloned.as_mut_ptr();
134 unsafe {
135 copy_field!(ptr, self, slot);
136 copy_field!(ptr, self, epoch_start_timestamp);
137 copy_field!(ptr, self, epoch);
138 copy_field!(ptr, self, leader_schedule_epoch);
139 copy_field!(ptr, self, unix_timestamp);
140 }
141 })
142 }
143}
144
145#[cfg(test)]
146mod tests {
147 use super::*;
148
149 #[test]
150 fn test_clone() {
151 let clock = Clock {
152 slot: 1,
153 epoch_start_timestamp: 2,
154 epoch: 3,
155 leader_schedule_epoch: 4,
156 unix_timestamp: 5,
157 };
158 let cloned_clock = clock.clone();
159 assert_eq!(cloned_clock, clock);
160 }
161}