AccountSharedData.executable() (#16835)

This commit is contained in:
Jeff Washington (jwash) 2021-04-27 09:12:17 -05:00 committed by GitHub
parent 4e7e675c07
commit 998cba74b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 18 deletions

View File

@ -2103,7 +2103,7 @@ fn main() {
println!("{}:", pubkey);
println!(" - balance: {} SOL", lamports_to_sol(account.lamports));
println!(" - owner: '{}'", account.owner());
println!(" - executable: {}", account.executable);
println!(" - executable: {}", account.executable());
println!(" - slot: {}", slot);
println!(" - rent_epoch: {}", account.rent_epoch);
if !exclude_account_data {

View File

@ -1733,7 +1733,7 @@ where
})?;
if i == program_account_index
|| account.borrow().executable
|| account.borrow().executable()
|| (invoke_context.is_feature_active(&cpi_share_ro_and_exec_accounts::id())
&& !caller_write_privileges[i])
{
@ -1990,7 +1990,7 @@ fn call<'a>(
for (i, (account, account_ref)) in accounts.iter().zip(account_refs).enumerate() {
let account = account.borrow();
if let Some(account_ref) = account_ref {
if message.is_writable(i, demote_sysvar_write_locks) && !account.executable {
if message.is_writable(i, demote_sysvar_write_locks) && !account.executable() {
*account_ref.lamports = account.lamports;
*account_ref.owner = *account.owner();
if account_ref.data.len() != account.data().len() {

View File

@ -228,7 +228,8 @@ impl Accounts {
})
.unwrap_or_default();
if account.executable && bpf_loader_upgradeable::check_id(account.owner()) {
if account.executable() && bpf_loader_upgradeable::check_id(account.owner())
{
// The upgradeable loader requires the derived ProgramData account
if let Ok(UpgradeableLoaderState::Program {
programdata_address,
@ -352,7 +353,7 @@ impl Accounts {
return Err(TransactionError::ProgramAccountNotFound);
}
};
if !program.executable {
if !program.executable() {
error_counters.invalid_program_for_execution += 1;
return Err(TransactionError::InvalidProgramForExecution);
}

View File

@ -289,7 +289,7 @@ impl<'a> LoadedAccount<'a> {
LoadedAccount::Stored(stored_account_meta) => {
stored_account_meta.account_meta.executable
}
LoadedAccount::Cached((_, cached_account)) => cached_account.account.executable,
LoadedAccount::Cached((_, cached_account)) => cached_account.account.executable(),
}
}
@ -3256,7 +3256,7 @@ impl AccountsDb {
hasher.hash(&account.data());
hasher.hash(&account.owner().as_ref());
if account.executable {
if account.executable() {
hasher.hash(&[1u8; 1]);
} else {
hasher.hash(&[0u8; 1]);

View File

@ -116,7 +116,7 @@ impl PreAccount {
let owner_changed = pre.owner() != post.owner();
if owner_changed
&& (!is_writable // line coverage used to get branch coverage
|| pre.executable
|| pre.executable()
|| program_id != pre.owner()
|| !Self::is_zeroed(&post.data()))
{
@ -136,7 +136,7 @@ impl PreAccount {
if !is_writable {
return Err(InstructionError::ReadonlyLamportChange);
}
if pre.executable {
if pre.executable() {
return Err(InstructionError::ExecutableLamportChange);
}
}
@ -156,10 +156,10 @@ impl PreAccount {
// and if the account is not executable
if !(program_id == pre.owner()
&& is_writable // line coverage used to get branch coverage
&& !pre.executable)
&& !pre.executable())
&& pre.data() != post.data()
{
if pre.executable {
if pre.executable() {
return Err(InstructionError::ExecutableDataModified);
} else if is_writable {
return Err(InstructionError::ExternalAccountDataModified);
@ -169,13 +169,13 @@ impl PreAccount {
}
// executable is one-way (false->true) and only the account owner may set it.
let executable_changed = pre.executable != post.executable;
let executable_changed = pre.executable() != post.executable();
if executable_changed {
if !rent.is_exempt(post.lamports, post.data().len()) {
return Err(InstructionError::ExecutableAccountNotRentExempt);
}
if !is_writable // line coverage used to get branch coverage
|| pre.executable
|| pre.executable()
|| program_id != pre.owner()
{
return Err(InstructionError::ExecutableModified);
@ -832,7 +832,7 @@ impl MessageProcessor {
ic_msg!(invoke_context, "Unknown program {}", callee_program_id);
InstructionError::MissingAccount
})?;
if !program_account.borrow().executable {
if !program_account.borrow().executable() {
ic_msg!(
invoke_context,
"Account {} is not executable",
@ -902,7 +902,7 @@ impl MessageProcessor {
let dst_keyed_account = &keyed_accounts[dst_keyed_account_index];
let src_keyed_account = account.borrow();
if message.is_writable(src_keyed_account_index, demote_sysvar_write_locks)
&& !src_keyed_account.executable
&& !src_keyed_account.executable()
{
if dst_keyed_account.data_len()? != src_keyed_account.data().len()
&& dst_keyed_account.data_len()? != 0
@ -1108,7 +1108,7 @@ impl MessageProcessor {
)?;
pre_sum += u128::from(pre_account.lamports());
post_sum += u128::from(account.lamports);
if is_writable && !account.executable {
if is_writable && !account.executable() {
pre_account.update(&account);
}
return Ok(());

View File

@ -61,7 +61,7 @@ impl RentCollector {
address: &Pubkey,
account: &mut AccountSharedData,
) -> u64 {
if account.executable
if account.executable()
|| account.rent_epoch > self.epoch
|| sysvar::check_id(account.owner())
|| *address == incinerator::id()

View File

@ -52,7 +52,7 @@ impl<'a> KeyedAccount<'a> {
}
pub fn executable(&self) -> Result<bool, InstructionError> {
Ok(self.try_borrow()?.executable)
Ok(self.try_borrow()?.executable())
}
pub fn rent_epoch(&self) -> Result<Epoch, InstructionError> {