From 3586ffa9dba71339d1403678bbc54a64e9093185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 20 Dec 2021 22:19:29 +0100 Subject: [PATCH] Partial revert "Updates documentation around what needs to be passed in CPI. (#21633)" 6f3f6eddb2de5ef3581264f8d6693361bdabd2f6 --- .../programming-model/calling-between-programs.md | 8 ++++++-- sdk/program/src/program.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/src/developing/programming-model/calling-between-programs.md b/docs/src/developing/programming-model/calling-between-programs.md index 200377e27e3585..96a41764b48ae4 100644 --- a/docs/src/developing/programming-model/calling-between-programs.md +++ b/docs/src/developing/programming-model/calling-between-programs.md @@ -54,8 +54,12 @@ mod acme { `invoke()` is built into Solana's runtime and is responsible for routing the given instruction to the `token` program via the instruction's `program_id` -field. The caller has to pass all the accounts required by the instruction -being invoked, except for the executable account (with the key `program_id`). +field. + +Note that `invoke` requires the caller to pass all the accounts required by the +instruction being invoked. This means that both the executable account (the +ones that matches the instruction's program id) and the accounts passed to the +instruction processor. Before invoking `pay()`, the runtime must ensure that `acme` didn't modify any accounts owned by `token`. It does this by applying the runtime's policy to the diff --git a/sdk/program/src/program.rs b/sdk/program/src/program.rs index f07099a0f5245b..45873e2d64a748 100644 --- a/sdk/program/src/program.rs +++ b/sdk/program/src/program.rs @@ -7,6 +7,8 @@ use crate::{ /// Notes: /// - 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 { invoke_signed(instruction, account_infos, &[]) } @@ -17,6 +19,8 @@ pub fn invoke(instruction: &Instruction, account_infos: &[AccountInfo]) -> Progr /// - 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, &[]) } @@ -26,6 +30,8 @@ pub fn invoke_unchecked(instruction: &Instruction, account_infos: &[AccountInfo] /// Notes: /// - 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( instruction: &Instruction, account_infos: &[AccountInfo], @@ -57,6 +63,8 @@ pub fn invoke_signed( /// - 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],