From 142b86580e628c6d4f4bdaa908dede7424ffdd56 Mon Sep 17 00:00:00 2001 From: Carl Lin Date: Wed, 30 Jul 2025 02:01:58 -0400 Subject: [PATCH] add util --- ledger/src/leader_schedule_utils.rs | 9 +++++++++ votor/src/skip_timer.rs | 11 +++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ledger/src/leader_schedule_utils.rs b/ledger/src/leader_schedule_utils.rs index a24592eed8..ce86bebcf0 100644 --- a/ledger/src/leader_schedule_utils.rs +++ b/ledger/src/leader_schedule_utils.rs @@ -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 { diff --git a/votor/src/skip_timer.rs b/votor/src/skip_timer.rs index 537d620de9..b051fb048b 100644 --- a/votor/src/skip_timer.rs +++ b/votor/src/skip_timer.rs @@ -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::{ @@ -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();