Skip to content

Commit

Permalink
lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Mar 6, 2024
1 parent 8d8ffea commit 3d1b392
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use {
prelude::*,
solana_program::{
clock::Clock,
log::sol_log_compute_units,
slot_history::{Check, MAX_ENTRIES},
},
},
Expand Down Expand Up @@ -47,7 +46,7 @@ pub fn handle_copy_cluster_info(ctx: Context<CopyClusterInfo>) -> Result<()> {
let start_slot = epoch_schedule.get_first_slot_in_epoch((epoch - 1).into());
let end_slot = epoch_schedule.get_last_slot_in_epoch((epoch - 1).into());
let (num_blocks, bitvec_inner) =
confirmed_blocks_in_epoch(start_slot, end_slot, slot_history)?;
confirmed_blocks_in_epoch(start_slot, end_slot, *slot_history)?;
// Sets the slot history for the previous epoch, since the total number of blocks in the epoch is now final
cluster_history_account.set_blocks(epoch - 1, num_blocks)?;
// recreates SlotHistory with same heap memory chunk
Expand All @@ -61,7 +60,7 @@ pub fn handle_copy_cluster_info(ctx: Context<CopyClusterInfo>) -> Result<()> {

let start_slot = epoch_schedule.get_first_slot_in_epoch(epoch.into());
let end_slot = epoch_schedule.get_last_slot_in_epoch(epoch.into());
let (num_blocks, _) = confirmed_blocks_in_epoch(start_slot, end_slot, slot_history)?;
let (num_blocks, _) = confirmed_blocks_in_epoch(start_slot, end_slot, *slot_history)?;
cluster_history_account.set_blocks(epoch, num_blocks)?;
cluster_history_account.set_epoch_start_timestamp(epoch, epoch_start_timestamp)?;

Expand All @@ -75,7 +74,7 @@ const BITVEC_BLOCK_SIZE: u64 = 64;
pub fn confirmed_blocks_in_epoch(
start_slot: u64,
end_slot: u64,
slot_history: Box<SlotHistory>,
slot_history: SlotHistory,
) -> Result<(u32, Box<[u64]>)> {
// The SlotHistory BitVec wraps a slice of "Blocks", usizes representing 64 slots each (different than solana blocks).
// Iterating through each slot uses too much compute, but we can count the bits of each u64 altogether efficiently
Expand All @@ -87,7 +86,7 @@ pub fn confirmed_blocks_in_epoch(
let first_full_block_slot = if (start_slot % MAX_ENTRIES) % BITVEC_BLOCK_SIZE == 0 {
start_slot
} else {
start_slot + (64 - (start_slot % MAX_ENTRIES) % BITVEC_BLOCK_SIZE)
start_slot + (BITVEC_BLOCK_SIZE - (start_slot % MAX_ENTRIES) % BITVEC_BLOCK_SIZE)
};

let last_full_block_slot = if (end_slot % MAX_ENTRIES) % BITVEC_BLOCK_SIZE == 0 {
Expand Down
3 changes: 1 addition & 2 deletions tests/tests/test_cluster_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ async fn test_cluster_history_compute_limit() {
.get_sysvar()
.await
.expect("clock");
println!("epoch: {}", clock.epoch);

// Set SlotHistory sysvar
let mut slot_history = SlotHistory::default();
Expand Down Expand Up @@ -184,6 +183,6 @@ fn test_confirmed_blocks_in_epoch_partial_blocks() {
// First partial block: 50 -> 64
// Full block: 64 -> 127
// Last partial block: 128 -> 149
let (num_blocks, _) = confirmed_blocks_in_epoch(50, 149, Box::new(slot_history)).unwrap();
let (num_blocks, _) = confirmed_blocks_in_epoch(50, 149, slot_history).unwrap();
assert_eq!(num_blocks, 100);
}

0 comments on commit 3d1b392

Please sign in to comment.