Refactor: Use SysvarCache in all builtin programs (#22864)

* Replaces from_keyed_account() by SysvarCache in stake instruction.

* Replaces from_keyed_account() by SysvarCache in system instruction processor.

* Removes from_keyed_account().
Moves check_sysvar_keyed_account() into sysvar_cache.rs

* Removes tests which test for incorrectly serialized sysvars.
This commit is contained in:
Alexander Meißner
2022-02-03 13:03:50 +01:00
committed by GitHub
parent 60af1a4cce
commit c16cf9cf8a
4 changed files with 137 additions and 331 deletions

View File

@ -5,11 +5,11 @@ use {
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
instruction::InstructionError,
keyed_account::{check_sysvar_keyed_account, KeyedAccount},
keyed_account::KeyedAccount,
pubkey::Pubkey,
sysvar::{
clock::Clock, epoch_schedule::EpochSchedule, rent::Rent, slot_hashes::SlotHashes,
stake_history::StakeHistory, SysvarId,
stake_history::StakeHistory, Sysvar, SysvarId,
},
},
std::sync::Arc,
@ -181,6 +181,15 @@ impl SysvarCache {
pub mod get_sysvar_with_account_check {
use super::*;
fn check_sysvar_keyed_account<S: Sysvar>(
keyed_account: &KeyedAccount,
) -> Result<(), InstructionError> {
if !S::check_id(keyed_account.unsigned_key()) {
return Err(InstructionError::InvalidArgument);
}
Ok(())
}
pub fn clock(
keyed_account: &KeyedAccount,
invoke_context: &InvokeContext,