Skip to content

Commit

Permalink
Make helper associated fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Sep 28, 2021
1 parent 30bce9d commit d5c4d4d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
9 changes: 1 addition & 8 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ impl Accounts {
let rent_for_sysvars = feature_set.is_active(&feature_set::rent_for_sysvars::id());
let demote_program_write_locks =
feature_set.is_active(&feature_set::demote_program_write_locks::id());
let is_upgradeable_loader_present = is_upgradeable_loader_present(message);

for (i, key) in message.account_keys_iter().enumerate() {
let account = if !message.is_non_loader_key(i) {
Expand Down Expand Up @@ -280,7 +279,7 @@ impl Accounts {
if bpf_loader_upgradeable::check_id(account.owner()) {
if demote_program_write_locks
&& message.is_writable(i, demote_program_write_locks)
&& !is_upgradeable_loader_present
&& !message.is_upgradeable_loader_present()
{
error_counters.invalid_writable_account += 1;
return Err(TransactionError::InvalidWritableAccount);
Expand Down Expand Up @@ -1133,12 +1132,6 @@ pub fn prepare_if_nonce_account(
false
}

fn is_upgradeable_loader_present(message: &SanitizedMessage) -> bool {
message
.account_keys_iter()
.any(|&key| key == bpf_loader_upgradeable::id())
}

pub fn create_test_accounts(
accounts: &Accounts,
pubkeys: &mut Vec<Pubkey>,
Expand Down
7 changes: 7 additions & 0 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,13 @@ impl Message {
}
false
}

/// Returns true if any account is the bpf upgradeable loader
pub fn is_upgradeable_loader_present(&self) -> bool {
self.account_keys
.iter()
.any(|&key| key == bpf_loader_upgradeable::id())
}
}

#[cfg(test)]
Expand Down
7 changes: 7 additions & 0 deletions sdk/program/src/message/mapped.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
crate::{
bpf_loader_upgradeable,
message::{legacy::BUILTIN_PROGRAMS_KEYS, v0},
pubkey::Pubkey,
sysvar,
Expand Down Expand Up @@ -116,6 +117,12 @@ impl MappedMessage {
false
}
}

/// Returns true if any account is the bpf upgradeable loader
pub fn is_upgradeable_loader_present(&self) -> bool {
self.account_keys_iter()
.any(|&key| key == bpf_loader_upgradeable::id())
}
}

#[cfg(test)]
Expand Down
8 changes: 8 additions & 0 deletions sdk/program/src/message/sanitized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ impl SanitizedMessage {
.saturating_add(num_secp256k1_signatures),
)
}

/// Inspect all message keys for the bpf upgradeable loader
pub fn is_upgradeable_loader_present(&self) -> bool {
match self {
Self::Legacy(message) => message.is_upgradeable_loader_present(),
Self::V0(message) => message.is_upgradeable_loader_present(),
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit d5c4d4d

Please sign in to comment.