Skip to content

Commit

Permalink
deprecate usage of static lists
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Jan 25, 2024
1 parent 7b7cf25 commit 8685df2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
5 changes: 3 additions & 2 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,8 @@ fn main() {
if let Some((pubkey, account, slot)) = some_account_tuple
.filter(|(_, account, _)| Accounts::is_loadable(account.lamports()))
{
if !include_sysvars && solana_sdk::sysvar::is_sysvar_id(pubkey) {
if !include_sysvars && solana_sdk::sysvar::check_id(account.owner())
{
return;
}

Expand Down Expand Up @@ -2613,7 +2614,7 @@ fn main() {
for (pubkey, warped_account) in all_accounts {
// Don't output sysvars; it's always updated but not related to
// inflation.
if solana_sdk::sysvar::is_sysvar_id(&pubkey) {
if solana_sdk::sysvar::check_id(warped_account.owner()) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4397,7 +4397,7 @@ fn test_bank_get_program_accounts() {
assert!(
genesis_accounts
.iter()
.any(|(pubkey, _, _)| solana_sdk::sysvar::is_sysvar_id(pubkey)),
.any(|(_, account, _)| solana_sdk::sysvar::check_id(account.owner())),
"no sysvars found"
);

Expand Down
10 changes: 6 additions & 4 deletions runtime/src/snapshot_minimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use {
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::Slot,
pubkey::Pubkey,
sdk_ids,
reserved_account_keys::ReservedAccountKeys,
},
std::{
collections::HashSet,
Expand Down Expand Up @@ -127,9 +127,11 @@ impl<'a> SnapshotMinimizer<'a> {

/// Used to get sdk accounts in `minimize`
fn get_sdk_accounts(&self) {
sdk_ids::SDK_IDS.iter().for_each(|pubkey| {
self.minimized_account_set.insert(*pubkey);
});
ReservedAccountKeys::active_and_inactive()
.iter()
.for_each(|pubkey| {
self.minimized_account_set.insert(*pubkey);
})
}

/// Used to get rent collection accounts in `minimize`
Expand Down
6 changes: 6 additions & 0 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ lazy_static! {
};
}

#[deprecated(
since = "1.18.0",
note = "please use solana_sdk::reserved_account_keys::ReservedAccountKeys instead"
)]
#[allow(deprecated)]
pub fn is_builtin_key_or_sysvar(key: &Pubkey) -> bool {
if MAYBE_BUILTIN_KEY_OR_SYSVAR[key.0[0] as usize] {
return sysvar::is_sysvar_id(key) || BUILTIN_PROGRAMS_KEYS.contains(key);
Expand Down Expand Up @@ -568,6 +573,7 @@ impl Message {
/// instructions in this message. Since the dynamic set of reserved accounts
/// isn't used here to demote write locks, this shouldn't be used in the
/// runtime.
#[allow(deprecated)]
pub fn is_maybe_writable(&self, i: usize) -> bool {
(self.is_writable_index(i))
&& !is_builtin_key_or_sysvar(&self.account_keys[i])
Expand Down
4 changes: 3 additions & 1 deletion sdk/program/src/message/versions/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
//! [`v0`]: crate::message::v0
//! [future message format]: https://docs.solanalabs.com/proposals/versioned-transactions

#[allow(deprecated)]
use crate::message::legacy::is_builtin_key_or_sysvar;
use crate::{
address_lookup_table_account::AddressLookupTableAccount,
bpf_loader_upgradeable,
hash::Hash,
instruction::{CompiledInstruction, Instruction},
message::{
compiled_keys::{CompileError, CompiledKeys},
legacy::is_builtin_key_or_sysvar,
AccountKeys, MessageHeader, MESSAGE_VERSION_PREFIX,
},
pubkey::Pubkey,
Expand Down Expand Up @@ -338,6 +339,7 @@ impl Message {
/// writable. Before loading addresses and without the reserved account keys
/// set, we can't demote write locks properly so this should not be used by
/// the runtime.
#[allow(deprecated)]
pub fn is_maybe_writable(&self, key_index: usize) -> bool {
self.is_writable_index(key_index)
&& !{
Expand Down
4 changes: 4 additions & 0 deletions sdk/program/src/sysvar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ lazy_static! {
}

/// Returns `true` of the given `Pubkey` is a sysvar account.
#[deprecated(
since = "1.18.0",
note = "please check the account's owner or use solana_sdk::reserved_account_keys::ReservedAccountKeys instead"
)]
pub fn is_sysvar_id(id: &Pubkey) -> bool {
ALL_IDS.iter().any(|key| key == id)
}
Expand Down
17 changes: 9 additions & 8 deletions storage-bigtable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use {
deserialize_utils::default_on_eof,
message::v0::LoadedAddresses,
pubkey::Pubkey,
reserved_account_keys::ReservedAccountKeys,
signature::Signature,
sysvar::is_sysvar_id,
timing::AtomicInterval,
transaction::{TransactionError, VersionedTransaction},
},
Expand Down Expand Up @@ -938,6 +938,7 @@ impl LedgerStorage {
entries,
} = confirmed_block;

let reserved_account_keys = ReservedAccountKeys::active_and_inactive();
let mut tx_cells = Vec::with_capacity(confirmed_block.transactions.len());
for (index, transaction_with_meta) in confirmed_block.transactions.iter().enumerate() {
let VersionedTransactionWithStatusMeta { meta, transaction } = transaction_with_meta;
Expand All @@ -947,7 +948,7 @@ impl LedgerStorage {
let memo = extract_and_fmt_memos(transaction_with_meta);

for address in transaction_with_meta.account_keys().iter() {
if !is_sysvar_id(address) {
if !reserved_account_keys.contains(address) {
by_addr
.entry(address)
.or_default()
Expand Down Expand Up @@ -1083,9 +1084,9 @@ impl LedgerStorage {
let err = None;

for address in transaction.message.account_keys.iter() {
if !is_sysvar_id(address) {
addresses.insert(address);
}
// Some of these addresses might be reserved keys but it's
// ok if we attempt to delete a row that doesn't exist
addresses.insert(address);
}

expected_tx_infos.insert(
Expand All @@ -1100,9 +1101,9 @@ impl LedgerStorage {
let err = meta.status.clone().err();

for address in tx_with_meta.account_keys().iter() {
if !is_sysvar_id(address) {
addresses.insert(address);
}
// Some of these addresses might be reserved keys but it's
// ok if we attempt to delete a row that doesn't exist
addresses.insert(address);
}

expected_tx_infos.insert(
Expand Down

0 comments on commit 8685df2

Please sign in to comment.