pub const DEFAULT_TICKS_PER_SECOND: u64 = 160;
pub const MS_PER_TICK: u64 = 1000 / DEFAULT_TICKS_PER_SECOND;
pub const DEFAULT_TICKS_PER_SLOT: u64 = 64;
pub const DEFAULT_HASHES_PER_SECOND: u64 = 2_000_000;
pub const DEFAULT_DEV_SLOTS_PER_EPOCH: u64 = 8192;
pub const SECONDS_PER_DAY: u64 = 24 * 60 * 60;
pub const TICKS_PER_DAY: u64 = DEFAULT_TICKS_PER_SECOND * SECONDS_PER_DAY;
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 2 * TICKS_PER_DAY / DEFAULT_TICKS_PER_SLOT;
pub const DEFAULT_SLOTS_PER_SEGMENT: u64 = 1024;
pub const DEFAULT_SLOTS_PER_TURN: u64 = 32 * 4;
pub const NUM_CONSECUTIVE_LEADER_SLOTS: u64 = 4;
pub const DEFAULT_MS_PER_SLOT: u64 = 1_000 * DEFAULT_TICKS_PER_SLOT / DEFAULT_TICKS_PER_SECOND;
pub const MAX_HASH_AGE_IN_SECONDS: usize = 120;
pub const MAX_RECENT_BLOCKHASHES: usize =
MAX_HASH_AGE_IN_SECONDS * DEFAULT_TICKS_PER_SECOND as usize / DEFAULT_TICKS_PER_SLOT as usize;
pub const MAX_PROCESSING_AGE: usize = MAX_RECENT_BLOCKHASHES / 2;
pub const MAX_TRANSACTION_FORWARDING_DELAY_GPU: usize = 2;
pub const MAX_TRANSACTION_FORWARDING_DELAY: usize = 6;
pub fn get_segment_from_slot(rooted_slot: Slot, slots_per_segment: u64) -> Segment {
(rooted_slot + (slots_per_segment - 1)) / slots_per_segment
}
pub fn get_complete_segment_from_slot(
rooted_slot: Slot,
slots_per_segment: u64,
) -> Option<Segment> {
let completed_segment = rooted_slot / slots_per_segment;
if rooted_slot < slots_per_segment {
None
} else {
Some(completed_segment)
}
}
pub type Slot = u64;
pub type Segment = u64;
pub type Epoch = u64;
pub type UnixTimestamp = i64;
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
pub struct Clock {
pub slot: Slot,
pub segment: Segment,
pub epoch: Epoch,
pub leader_schedule_epoch: Epoch,
pub unix_timestamp: UnixTimestamp,
}
#[cfg(test)]
mod tests {
use super::*;
fn get_segments(slot: Slot, slots_per_segment: u64) -> (Segment, Segment) {
(
get_segment_from_slot(slot, slots_per_segment),
get_complete_segment_from_slot(slot, slots_per_segment).unwrap(),
)
}
#[test]
fn test_complete_segment_impossible() {
assert_eq!(get_complete_segment_from_slot(5, 10), None);
}
#[test]
fn test_segment_conversion() {
let (current, complete) = get_segments(2048, 1024);
assert_eq!(current, complete);
let (current, complete) = get_segments(2049, 1024);
assert!(complete < current);
}
}