Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ledger/src/leader_schedule_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ pub fn leader_slot_index(slot: Slot) -> usize {
(slot % NUM_CONSECUTIVE_LEADER_SLOTS) as usize
}

/// Returns the number of slots left after `slot` in the leader window
/// that contains `slot`
#[inline]
pub fn remaining_slots_in_window(slot: Slot) -> u64 {
NUM_CONSECUTIVE_LEADER_SLOTS
.checked_sub(leader_slot_index(slot) as u64)
.unwrap()
}

#[cfg(test)]
mod tests {
use {
Expand Down
11 changes: 5 additions & 6 deletions votor/src/skip_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use {
event::{VotorEvent, VotorEventSender},
skip_timeout, BLOCKTIME,
},
solana_ledger::leader_schedule_utils::{last_of_consecutive_leader_slots, leader_slot_index},
solana_sdk::clock::{Slot, NUM_CONSECUTIVE_LEADER_SLOTS},
solana_ledger::leader_schedule_utils::{
last_of_consecutive_leader_slots, remaining_slots_in_window,
},
solana_sdk::clock::Slot,
std::{
collections::{BinaryHeap, VecDeque},
sync::{
Expand Down Expand Up @@ -86,10 +88,7 @@ impl SkipTimerManager {

// To account for restarting from a snapshot in the middle of a leader window
// or from genesis, we compute the exact length of this leader window:
let leader_window_offset = leader_slot_index(start_slot);
let remaining = NUM_CONSECUTIVE_LEADER_SLOTS
.checked_sub(leader_window_offset as u64)
.unwrap();
let remaining = remaining_slots_in_window(start_slot);
// TODO: should we change the first fire as well?
let next_fire = Instant::now().checked_add(skip_timeout(0)).unwrap();

Expand Down