1#![no_std]
24#![cfg_attr(docsrs, feature(doc_cfg))]
25
26#[cfg(feature = "sysvar")]
27pub mod sysvar;
28
29#[cfg(feature = "serde")]
30use serde_derive::{Deserialize, Serialize};
31use solana_sdk_macro::CloneZeroed;
32
33pub const DEFAULT_TICKS_PER_SLOT: u64 = 64;
35
36pub const DEFAULT_NS_PER_SLOT_400_MS: u64 = 400_000_000;
37pub const DEFAULT_NS_PER_SLOT_350_MS: u64 = 350_000_000;
38pub const DEFAULT_NS_PER_SLOT_300_MS: u64 = 300_000_000;
39pub const DEFAULT_NS_PER_SLOT_250_MS: u64 = 250_000_000;
40pub const DEFAULT_NS_PER_SLOT_200_MS: u64 = 200_000_000;
41
42pub const DEFAULT_NS_PER_SLOT: u64 = DEFAULT_NS_PER_SLOT_300_MS;
44
45pub const DEFAULT_NS_PER_TICK_400_MS: u64 = DEFAULT_NS_PER_SLOT_400_MS / DEFAULT_TICKS_PER_SLOT;
46pub const DEFAULT_NS_PER_TICK_350_MS: u64 = DEFAULT_NS_PER_SLOT_350_MS / DEFAULT_TICKS_PER_SLOT;
47pub const DEFAULT_NS_PER_TICK_300_MS: u64 = DEFAULT_NS_PER_SLOT_300_MS / DEFAULT_TICKS_PER_SLOT;
48pub const DEFAULT_NS_PER_TICK_250_MS: u64 = DEFAULT_NS_PER_SLOT_250_MS / DEFAULT_TICKS_PER_SLOT;
49pub const DEFAULT_NS_PER_TICK_200_MS: u64 = DEFAULT_NS_PER_SLOT_200_MS / DEFAULT_TICKS_PER_SLOT;
50
51pub const DEFAULT_NS_PER_TICK: u64 = DEFAULT_NS_PER_TICK_300_MS;
53
54pub const DEFAULT_TICKS_PER_SECOND_400_MS: u64 = 1_000_000_000 / DEFAULT_NS_PER_TICK_400_MS;
59pub const DEFAULT_TICKS_PER_SECOND_350_MS: u64 = 1_000_000_000 / DEFAULT_NS_PER_TICK_350_MS;
60pub const DEFAULT_TICKS_PER_SECOND_300_MS: u64 = 1_000_000_000 / DEFAULT_NS_PER_TICK_300_MS;
61pub const DEFAULT_TICKS_PER_SECOND_250_MS: u64 = 1_000_000_000 / DEFAULT_NS_PER_TICK_250_MS;
62pub const DEFAULT_TICKS_PER_SECOND_200_MS: u64 = 1_000_000_000 / DEFAULT_NS_PER_TICK_200_MS;
63
64pub const DEFAULT_TICKS_PER_SECOND: u64 = DEFAULT_TICKS_PER_SECOND_300_MS;
69
70#[cfg(test)]
71static_assertions::const_assert_eq!(MS_PER_TICK, 4);
72
73pub const MS_PER_TICK_400_MS: u64 = DEFAULT_NS_PER_TICK_400_MS / 1_000_000;
74pub const MS_PER_TICK_350_MS: u64 = DEFAULT_NS_PER_TICK_350_MS / 1_000_000;
75pub const MS_PER_TICK_300_MS: u64 = DEFAULT_NS_PER_TICK_300_MS / 1_000_000;
76pub const MS_PER_TICK_250_MS: u64 = DEFAULT_NS_PER_TICK_250_MS / 1_000_000;
77pub const MS_PER_TICK_200_MS: u64 = DEFAULT_NS_PER_TICK_200_MS / 1_000_000;
78
79pub const MS_PER_TICK: u64 = MS_PER_TICK_300_MS;
83
84pub const DEFAULT_HASHES_PER_SECOND: u64 = 10_000_000;
85
86#[cfg(test)]
87static_assertions::const_assert_eq!(DEFAULT_HASHES_PER_TICK, 46_875);
88pub const DEFAULT_HASHES_PER_TICK_400_MS: u64 = 62_500;
89pub const DEFAULT_HASHES_PER_TICK_350_MS: u64 = 54_687;
90pub const DEFAULT_HASHES_PER_TICK_300_MS: u64 = 46_875;
91pub const DEFAULT_HASHES_PER_TICK_250_MS: u64 = 39_062;
92pub const DEFAULT_HASHES_PER_TICK_200_MS: u64 = 31_250;
93pub const DEFAULT_HASHES_PER_TICK: u64 = DEFAULT_HASHES_PER_TICK_300_MS;
94
95pub const DEFAULT_DEV_SLOTS_PER_EPOCH: u64 = 8192;
97
98#[cfg(test)]
99static_assertions::const_assert_eq!(SECONDS_PER_DAY, 86_400);
100pub const SECONDS_PER_DAY: u64 = 24 * 60 * 60;
101
102#[cfg(test)]
103static_assertions::const_assert_eq!(TICKS_PER_DAY, 18_432_000);
104pub const TICKS_PER_DAY_400_MS: u64 = SECONDS_PER_DAY * 1_000_000_000 / DEFAULT_NS_PER_TICK_400_MS;
105pub const TICKS_PER_DAY_350_MS: u64 = SECONDS_PER_DAY * 1_000_000_000 / DEFAULT_NS_PER_TICK_350_MS;
106pub const TICKS_PER_DAY_300_MS: u64 = SECONDS_PER_DAY * 1_000_000_000 / DEFAULT_NS_PER_TICK_300_MS;
107pub const TICKS_PER_DAY_250_MS: u64 = SECONDS_PER_DAY * 1_000_000_000 / DEFAULT_NS_PER_TICK_250_MS;
108pub const TICKS_PER_DAY_200_MS: u64 = SECONDS_PER_DAY * 1_000_000_000 / DEFAULT_NS_PER_TICK_200_MS;
109pub const TICKS_PER_DAY: u64 = TICKS_PER_DAY_300_MS;
110
111pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 432_000;
115
116#[cfg(test)]
117static_assertions::const_assert_eq!(DEFAULT_MS_PER_SLOT, 300);
118pub const DEFAULT_MS_PER_SLOT_400_MS: u64 = DEFAULT_NS_PER_SLOT_400_MS / 1_000_000;
119pub const DEFAULT_MS_PER_SLOT_350_MS: u64 = DEFAULT_NS_PER_SLOT_350_MS / 1_000_000;
120pub const DEFAULT_MS_PER_SLOT_300_MS: u64 = DEFAULT_NS_PER_SLOT_300_MS / 1_000_000;
121pub const DEFAULT_MS_PER_SLOT_250_MS: u64 = DEFAULT_NS_PER_SLOT_250_MS / 1_000_000;
122pub const DEFAULT_MS_PER_SLOT_200_MS: u64 = DEFAULT_NS_PER_SLOT_200_MS / 1_000_000;
123
124pub const DEFAULT_MS_PER_SLOT: u64 = DEFAULT_MS_PER_SLOT_300_MS;
126
127pub const DEFAULT_S_PER_SLOT_400_MS: f64 = DEFAULT_MS_PER_SLOT_400_MS as f64 / 1_000.0;
128pub const DEFAULT_S_PER_SLOT_350_MS: f64 = DEFAULT_MS_PER_SLOT_350_MS as f64 / 1_000.0;
129pub const DEFAULT_S_PER_SLOT_300_MS: f64 = DEFAULT_MS_PER_SLOT_300_MS as f64 / 1_000.0;
130pub const DEFAULT_S_PER_SLOT_250_MS: f64 = DEFAULT_MS_PER_SLOT_250_MS as f64 / 1_000.0;
131pub const DEFAULT_S_PER_SLOT_200_MS: f64 = DEFAULT_MS_PER_SLOT_200_MS as f64 / 1_000.0;
132pub const DEFAULT_S_PER_SLOT: f64 = DEFAULT_S_PER_SLOT_300_MS;
133
134pub const MAX_HASH_AGE_IN_SECONDS_400_MS: usize = 120;
143pub const MAX_HASH_AGE_IN_SECONDS_350_MS: usize = 105;
144pub const MAX_HASH_AGE_IN_SECONDS_300_MS: usize = 90;
145pub const MAX_HASH_AGE_IN_SECONDS_250_MS: usize = 75;
146pub const MAX_HASH_AGE_IN_SECONDS_200_MS: usize = 60;
147pub const MAX_HASH_AGE_IN_SECONDS: usize = MAX_HASH_AGE_IN_SECONDS_300_MS;
148
149pub const MAX_RECENT_BLOCKHASHES: usize = 300;
151
152#[cfg(test)]
153static_assertions::const_assert_eq!(MAX_PROCESSING_AGE, 150);
154pub const MAX_PROCESSING_AGE: usize = MAX_RECENT_BLOCKHASHES / 2;
156
157pub const MAX_TRANSACTION_FORWARDING_DELAY_GPU: usize = 2;
160
161pub const MAX_TRANSACTION_FORWARDING_DELAY: usize = 6;
163
164pub const FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET: u64 = 2;
166pub const HOLD_TRANSACTIONS_SLOT_OFFSET: u64 = 20;
167
168pub type Slot = u64;
172
173pub type BankId = u64;
178
179pub type Epoch = u64;
183
184pub const GENESIS_EPOCH: Epoch = 0;
185pub const INITIAL_RENT_EPOCH: Epoch = 0;
187
188pub type SlotIndex = u64;
190
191pub type SlotCount = u64;
193
194pub type UnixTimestamp = i64;
198
199#[repr(C)]
203#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
204#[cfg_attr(feature = "wincode", derive(wincode::SchemaWrite, wincode::SchemaRead))]
205#[derive(Debug, CloneZeroed, Default, PartialEq, Eq)]
206pub struct Clock {
207 pub slot: Slot,
209 pub epoch_start_timestamp: UnixTimestamp,
211 pub epoch: Epoch,
213 pub leader_schedule_epoch: Epoch,
216 pub unix_timestamp: UnixTimestamp,
226}
227
228pub const SIZE: usize = size_of::<Clock>();
230const _: () = assert!(SIZE == 40);
231
232#[cfg(test)]
233mod tests {
234 use super::*;
235
236 #[test]
237 fn test_size_of() {
238 assert_eq!(
239 wincode::serialized_size(&Clock::default()).unwrap() as usize,
240 SIZE,
241 );
242 }
243
244 #[test]
245 fn test_clone() {
246 let clock = Clock {
247 slot: 1,
248 epoch_start_timestamp: 2,
249 epoch: 3,
250 leader_schedule_epoch: 4,
251 unix_timestamp: 5,
252 };
253 let cloned_clock = clock.clone();
254 assert_eq!(cloned_clock, clock);
255 }
256}