Skip to content

Commit

Permalink
reconstruct slot hashes for long warps (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe authored and buffalojoec committed Dec 4, 2024
1 parent 7902bdb commit 222a67a
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions harness/src/sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ impl Sysvars {

/// Warp the test environment to a slot by updating sysvars.
pub fn warp_to_slot(&mut self, slot: Slot) {
let slot_delta = slot.saturating_sub(self.clock.slot);

// First update `Clock`.
let epoch = self.epoch_schedule.get_epoch(slot);
let leader_schedule_epoch = self.epoch_schedule.get_leader_schedule_epoch(slot);
Expand All @@ -146,17 +148,28 @@ impl Sysvars {
};

// Then update `SlotHashes`.
let i = if let Some(most_recent_slot_hash) = self.slot_hashes.first() {
most_recent_slot_hash.0
if slot_delta > slot_hashes::MAX_ENTRIES as u64 {
let final_hash_slot = slot - slot_hashes::MAX_ENTRIES as u64;

let slot_hash_entries = (final_hash_slot..slot)
.rev()
.map(|slot| (slot, Hash::default()))
.collect::<Vec<_>>();

self.slot_hashes = SlotHashes::new(&slot_hash_entries);
} else {
// By default, this zero is never used, but a user can overwrite
// `SlotHashes`.
0
};
// Don't include the target slot, since it will become the "current"
// slot.
for slot in i..slot {
self.slot_hashes.add(slot, Hash::default());
let i = if let Some(most_recent_slot_hash) = self.slot_hashes.first() {
most_recent_slot_hash.0
} else {
// By default, this zero is never used, but a user can overwrite
// `SlotHashes`.
0
};
// Don't include the target slot, since it will become the "current"
// slot.
for slot in i..slot {
self.slot_hashes.add(slot, Hash::default());
}
}
}
}
Expand Down

0 comments on commit 222a67a

Please sign in to comment.