Share RO and Executable accounts within invocations (#15799)

This commit is contained in:
Jack May
2021-03-10 23:04:00 -08:00
committed by GitHub
parent ac8ccee6b8
commit 478518308d
8 changed files with 145 additions and 85 deletions

View File

@ -107,6 +107,10 @@ pub mod check_program_owner {
solana_sdk::declare_id!("5XnbR5Es9YXEARRuP6mdvoxiW3hx5atNNeBmwVd8P3QD");
}
pub mod cpi_share_ro_and_exec_accounts {
solana_sdk::declare_id!("6VgVBi3uRVqp56TtEwNou8idgdmhCD1aYqX8FaJ1fnJb");
}
lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
@ -133,7 +137,8 @@ lazy_static! {
(full_inflation::mainnet::certusone::vote::id(), "Community vote allowing Certus One to enable full inflation"),
(warp_timestamp_again::id(), "warp timestamp again, adjust bounding to 25% fast 80% slow #15204"),
(check_init_vote_data::id(), "check initialized Vote data"),
(check_program_owner::id(), "limit programs to operating on accounts owned by itself")
(check_program_owner::id(), "limit programs to operating on accounts owned by itself"),
(cpi_share_ro_and_exec_accounts::id(), "Share RO and Executable accounts during cross-program invocations"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()

View File

@ -6,6 +6,7 @@ use solana_program::{clock::Epoch, instruction::InstructionError, pubkey::Pubkey
use std::{
cell::{Ref, RefCell, RefMut},
iter::FromIterator,
rc::Rc,
};
#[repr(C)]
@ -160,7 +161,7 @@ pub fn create_keyed_is_signer_accounts<'a>(
}
pub fn create_keyed_readonly_accounts(
accounts: &[(Pubkey, RefCell<AccountSharedData>)],
accounts: &[(Pubkey, Rc<RefCell<AccountSharedData>>)],
) -> Vec<KeyedAccount> {
accounts
.iter()

View File

@ -59,7 +59,7 @@ pub trait InvokeContext {
/// Get the bank's active feature set
fn is_feature_active(&self, feature_id: &Pubkey) -> bool;
/// Get an account from a pre-account
fn get_account(&self, pubkey: &Pubkey) -> Option<RefCell<AccountSharedData>>;
fn get_account(&self, pubkey: &Pubkey) -> Option<Rc<RefCell<AccountSharedData>>>;
/// Update timing
fn update_timing(
&mut self,
@ -333,7 +333,7 @@ impl InvokeContext for MockInvokeContext {
fn is_feature_active(&self, _feature_id: &Pubkey) -> bool {
true
}
fn get_account(&self, _pubkey: &Pubkey) -> Option<RefCell<AccountSharedData>> {
fn get_account(&self, _pubkey: &Pubkey) -> Option<Rc<RefCell<AccountSharedData>>> {
None
}
fn update_timing(