2018-06-06 16:36:54 -07:00
|
|
|
//! The `timing` module provides std::time utility functions.
|
2018-05-07 16:49:15 -07:00
|
|
|
use std::time::Duration;
|
2018-05-08 17:59:01 -07:00
|
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
2018-05-07 16:49:15 -07:00
|
|
|
|
2019-02-18 19:28:10 -08:00
|
|
|
pub const NUM_TICKS_PER_SECOND: usize = 10;
|
|
|
|
|
|
|
|
// At 10 ticks/s, 8 ticks per slot implies that leader rotation and voting will happen
|
|
|
|
// every 800 ms. A fast voting cadence ensures faster finality and convergence
|
2019-02-26 10:48:18 -08:00
|
|
|
pub const DEFAULT_TICKS_PER_SLOT: u64 = 80;
|
2019-02-18 19:28:10 -08:00
|
|
|
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 64;
|
|
|
|
|
2019-03-01 12:16:20 -08:00
|
|
|
/// The time window of recent `last_id` values that the bank will track the signatures
|
|
|
|
/// of over. Once the bank discards a `last_id`, it will reject any transactions that use
|
2019-02-18 22:26:22 -08:00
|
|
|
/// that `last_id` in a transaction. Lowering this value reduces memory consumption,
|
|
|
|
/// but requires clients to update its `last_id` more frequently. Raising the value
|
|
|
|
/// lengthens the time a client must wait to be certain a missing transaction will
|
|
|
|
/// not be processed by the network.
|
2019-03-01 12:16:20 -08:00
|
|
|
pub const MAX_HASH_AGE_IN_SECONDS: usize = 120;
|
|
|
|
|
|
|
|
pub const MAX_RECENT_TICK_HASHES: usize = NUM_TICKS_PER_SECOND * MAX_HASH_AGE_IN_SECONDS;
|
2019-02-18 22:26:22 -08:00
|
|
|
|
2018-06-22 10:44:31 -07:00
|
|
|
pub fn duration_as_us(d: &Duration) -> u64 {
|
2018-07-11 13:40:46 -07:00
|
|
|
(d.as_secs() * 1000 * 1000) + (u64::from(d.subsec_nanos()) / 1_000)
|
2018-06-22 10:44:31 -07:00
|
|
|
}
|
|
|
|
|
2018-05-07 16:49:15 -07:00
|
|
|
pub fn duration_as_ms(d: &Duration) -> u64 {
|
2018-07-11 13:40:46 -07:00
|
|
|
(d.as_secs() * 1000) + (u64::from(d.subsec_nanos()) / 1_000_000)
|
2018-05-07 16:49:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn duration_as_s(d: &Duration) -> f32 {
|
2018-07-11 13:40:46 -07:00
|
|
|
d.as_secs() as f32 + (d.subsec_nanos() as f32 / 1_000_000_000.0)
|
2018-05-07 16:49:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn timestamp() -> u64 {
|
2018-05-11 11:38:52 -07:00
|
|
|
let now = SystemTime::now()
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
.expect("create timestamp in timing");
|
2018-07-11 13:40:46 -07:00
|
|
|
duration_as_ms(&now)
|
2018-05-07 16:49:15 -07:00
|
|
|
}
|