Skip to content

Commit

Permalink
AccountSharedData.executable() (solana-labs#16835)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Apr 27, 2021
1 parent 4e7e675 commit 998cba7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions programs/bpf_loader/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
{
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -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]);
Expand Down
18 changes: 9 additions & 9 deletions runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
{
Expand All @@ -136,7 +136,7 @@ impl PreAccount {
if !is_writable {
return Err(InstructionError::ReadonlyLamportChange);
}
if pre.executable {
if pre.executable() {
return Err(InstructionError::ExecutableLamportChange);
}
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(());
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/rent_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/keyed_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 998cba7

Please sign in to comment.