Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
pr feedback: use epoch schedule sysvar instead of hardcoding length
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar committed Nov 27, 2024
1 parent 5210f9c commit 09235da
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions slashing/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use {
},
solana_program::{
account_info::{next_account_info, AccountInfo},
clock::{Slot, DEFAULT_SLOTS_PER_EPOCH},
clock::Slot,
entrypoint::ProgramResult,
msg,
program_error::ProgramError,
pubkey::Pubkey,
sysvar::{clock::Clock, Sysvar},
sysvar::{clock::Clock, epoch_schedule::EpochSchedule, Sysvar},
},
};

Expand All @@ -30,7 +30,8 @@ where
let Some(elapsed) = clock.slot.checked_sub(slot) else {
return Err(ProgramError::ArithmeticOverflow);
};
if elapsed > DEFAULT_SLOTS_PER_EPOCH {
let epoch_schedule = EpochSchedule::get()?;
if elapsed > epoch_schedule.slots_per_epoch {
return Err(SlashingError::ExceedsStatueOfLimitations.into());
}

Expand Down Expand Up @@ -85,6 +86,7 @@ mod tests {
solana_ledger::shred::Shredder,
solana_sdk::{
clock::{Clock, Slot, DEFAULT_SLOTS_PER_EPOCH},
epoch_schedule::EpochSchedule,
program_error::ProgramError,
signature::Keypair,
signer::Signer,
Expand Down Expand Up @@ -144,6 +146,13 @@ mod tests {
}
solana_program::entrypoint::SUCCESS
}

fn sol_get_epoch_schedule_sysvar(&self, var_addr: *mut u8) -> u64 {
unsafe {
*(var_addr as *mut _ as *mut EpochSchedule) = EpochSchedule::default();
}
solana_program::entrypoint::SUCCESS
}
}

solana_sdk::program_stubs::set_syscall_stubs(Box::new(SyscallStubs {}));
Expand Down

0 comments on commit 09235da

Please sign in to comment.