add unchecked invokes (#20313) (#20337)

(cherry picked from commit 8188c1dd59)

Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
mergify[bot]
2021-09-30 17:05:51 +00:00
committed by GitHub
parent 734b380cdb
commit 1c15cc6e9a

View File

@ -1,17 +1,35 @@
use crate::{account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction}; use crate::{account_info::AccountInfo, entrypoint::ProgramResult, instruction::Instruction};
/// 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],
@ -33,6 +51,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")]
{ {
let result = unsafe { let result = unsafe {