add unchecked invokes (#20313)

This commit is contained in:
Jack May
2021-09-29 19:50:38 -07:00
committed by GitHub
parent 5e05f12c48
commit 8188c1dd59

View File

@ -2,18 +2,36 @@ use crate::{
account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction, pubkey::Pubkey, account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction, pubkey::Pubkey,
}; };
/// Invoke a cross-program instruction /// Invoke a cross-program instruction.
/// ///
/// Note that the program id of the instruction being issued must also be included in /// Notes:
/// `account_infos`. /// - RefCell checking can be compute unit expensive, to avoid that expense use
/// `invoke_unchecked` instead, but at your own risk.
/// - The program id of the instruction being issued must also be included in
/// `account_infos`.
pub fn invoke(instruction: &Instruction, account_infos: &[AccountInfo]) -> ProgramResult { pub fn invoke(instruction: &Instruction, account_infos: &[AccountInfo]) -> ProgramResult {
invoke_signed(instruction, account_infos, &[]) invoke_signed(instruction, account_infos, &[])
} }
/// Invoke a cross-program instruction but don't enforce RefCell handling.
///
/// Notes:
/// - The missing checks ensured that the invocation doesn't violate the borrow
/// rules of the `AccountInfo` fields that are wrapped in `RefCell`s. To
/// include the checks call `invoke` instead.
/// - The program id of the instruction being issued must also be included in
/// `account_infos`.
pub fn invoke_unchecked(instruction: &Instruction, account_infos: &[AccountInfo]) -> ProgramResult {
invoke_signed_unchecked(instruction, account_infos, &[])
}
/// Invoke a cross-program instruction with program signatures /// Invoke a cross-program instruction with program signatures
/// ///
/// Note that the program id of the instruction being issued must also be included in /// Notes:
/// `account_infos`. /// - RefCell checking can be compute unit expensive, to avoid that expense use
/// `invoke_signed_unchecked` instead, but at your own risk.
/// - The program id of the instruction being issued must also be included in
/// `account_infos`.
pub fn invoke_signed( pub fn invoke_signed(
instruction: &Instruction, instruction: &Instruction,
account_infos: &[AccountInfo], account_infos: &[AccountInfo],
@ -35,6 +53,23 @@ pub fn invoke_signed(
} }
} }
invoke_signed_unchecked(instruction, account_infos, signers_seeds)
}
/// Invoke a cross-program instruction with program signatures but don't check
/// RefCell handling.
///
/// Note:
/// - The missing checks ensured that the invocation doesn't violate the borrow
/// rules of the `AccountInfo` fields that are wrapped in `RefCell`s. To
/// include the checks call `invoke_signed` instead.
/// - The program id of the instruction being issued must also be included in
/// `account_infos`.
pub fn invoke_signed_unchecked(
instruction: &Instruction,
account_infos: &[AccountInfo],
signers_seeds: &[&[&[u8]]],
) -> ProgramResult {
#[cfg(target_arch = "bpf")] #[cfg(target_arch = "bpf")]
{ {
extern "C" { extern "C" {