Skip to content

Commit 296fb5b

Browse files
using current epoch's schedule
1 parent d6d91b7 commit 296fb5b

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

src/block.rs

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use solana_fee_calculator::FeeRateGovernor;
2121
use solana_genesis_config::GenesisConfig;
2222
use solana_hard_forks::HardForks;
2323
use solana_hash::Hash;
24+
use solana_ledger::leader_schedule_utils;
2425
use solana_inflation::Inflation;
2526
use solana_lattice_hash::lt_hash::LtHash;
2627
use solana_ledger::blockstore_processor::{
@@ -579,6 +580,7 @@ pub fn execute_block(context: BlockContext) -> Option<BlockEffects> {
579580
null_tracer(),
580581
);
581582
}
583+
let l_sched = leader_schedule_utils::leader_schedule(current_epoch, &bank).unwrap();
582584

583585
bank.distribute_partitioned_epoch_rewards();
584586

@@ -689,48 +691,35 @@ pub fn execute_block(context: BlockContext) -> Option<BlockEffects> {
689691
// - leader_schedule_epoch: The epoch for which the leader schedule applies
690692
// - first_slot: The absolute slot number where this epoch begins
691693
// - slots_in_epoch: Total number of slots in this epoch (can vary by epoch)
692-
let first_slot = epoch_schedule_for_effects.get_first_slot_in_epoch(leader_schedule_epoch);
693-
let slots_in_epoch = epoch_schedule_for_effects.get_slots_in_epoch(leader_schedule_epoch);
694+
let first_slot = epoch_schedule_for_effects.get_first_slot_in_epoch(current_epoch);
695+
let slots_in_epoch = epoch_schedule_for_effects.get_slots_in_epoch(current_epoch);
694696

695697
// Attempt to retrieve the leader schedule for this epoch from the cache
696-
let leader_schedule_effects =
697-
if let Some(schedule) = leader_schedule.get_epoch_leader_schedule(leader_schedule_epoch) {
698-
// Schedule found, obtain effects and hash
699-
// Generate a deterministic 128-bit hash of the entire leader schedule
700-
// This hash encodes both WHO the leaders are and WHEN they lead.
701-
// We use a fixed seed for reproducibility across implementations.
702-
let mut schedule_hash = [0u8; 16];
703-
let schedule_pubkeys: Vec<Pubkey> = (0..slots_in_epoch)
704-
.map(|slot_offset| schedule[slot_offset])
705-
.collect();
706-
707-
let unique_cnt = hash_epoch_leaders(
708-
&schedule_pubkeys,
709-
LEADER_SCHEDULE_HASH_SEED,
710-
&mut schedule_hash,
711-
);
712-
713-
// Package all the schedule metadata for output
714-
proto::LeaderScheduleEffects {
715-
leaders_epoch: leader_schedule_epoch, // Which epoch this schedule applies to
716-
leaders_slot0: first_slot, // First absolute slot in this epoch
717-
leaders_slot_cnt: slots_in_epoch as u64, // Total slots in this epoch
718-
leader_pub_cnt: unique_cnt as u64, // Number of unique leader validators
719-
leaders_sched_cnt: slots_in_epoch as u64, // Number of scheduled leader slots (verification field)
720-
leader_schedule_hash: schedule_hash.to_vec(), // 128-bit fingerprint of the schedule
721-
}
722-
} else {
723-
// No schedule found for this epoch, return empty/zero values
724-
// This can happen during bootstrapping or if the epoch is too far in the future
725-
proto::LeaderScheduleEffects {
726-
leaders_epoch: 0,
727-
leaders_slot0: 0,
728-
leaders_slot_cnt: 0,
729-
leader_pub_cnt: 0,
730-
leaders_sched_cnt: 0,
731-
leader_schedule_hash: vec![],
732-
}
733-
};
698+
699+
// Schedule found, obtain effects and hash
700+
// Generate a deterministic 128-bit hash of the entire leader schedule
701+
// This hash encodes both WHO the leaders are and WHEN they lead.
702+
// We use a fixed seed for reproducibility across implementations.
703+
let mut schedule_hash = [0u8; 16];
704+
let schedule_pubkeys: Vec<Pubkey> = (0..slots_in_epoch)
705+
.map(|slot_offset| l_sched[slot_offset])
706+
.collect();
707+
708+
let unique_cnt = hash_epoch_leaders(
709+
&schedule_pubkeys,
710+
LEADER_SCHEDULE_HASH_SEED,
711+
&mut schedule_hash,
712+
);
713+
714+
// Package all the schedule metadata for output
715+
let leader_schedule_effects = proto::LeaderScheduleEffects {
716+
leaders_epoch: current_epoch, // Which epoch this schedule applies to
717+
leaders_slot0: first_slot, // First absolute slot in this epoch
718+
leaders_slot_cnt: slots_in_epoch as u64, // Total slots in this epoch
719+
leader_pub_cnt: unique_cnt as u64, // Number of unique leader validators
720+
leaders_sched_cnt: slots_in_epoch as u64, // Number of scheduled leader slots (verification field)
721+
leader_schedule_hash: schedule_hash.to_vec(), // 128-bit fingerprint of the schedule
722+
};
734723

735724
// Then include in the output
736725
Some(BlockEffects {

0 commit comments

Comments
 (0)