Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove LoadZeroLamports enum #28204

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 14 additions & 33 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
account_rent_state::{check_rent_state_with_account, RentState},
accounts_db::{
AccountShrinkThreshold, AccountsAddRootTiming, AccountsDb, AccountsDbConfig,
BankHashInfo, LoadHint, LoadZeroLamports, LoadedAccount, ScanStorageResult,
BankHashInfo, LoadHint, LoadedAccount, ScanStorageResult,
ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS, ACCOUNTS_DB_CONFIG_FOR_TESTING,
},
accounts_index::{
Expand Down Expand Up @@ -258,8 +258,6 @@ impl Accounts {
feature_set: &FeatureSet,
account_overrides: Option<&AccountOverrides>,
) -> Result<LoadedTransaction> {
let load_zero_lamports = LoadZeroLamports::None;

// Copy all the accounts
let message = tx.message();
// NOTE: this check will never fail because `tx` is sanitized
Expand Down Expand Up @@ -295,7 +293,7 @@ impl Accounts {
(account_override.clone(), 0)
} else {
self.accounts_db
.load_with_fixed_root(ancestors, key, load_zero_lamports)
.load_with_fixed_root(ancestors, key)
.map(|(mut account, _)| {
if message.is_writable(i) {
let rent_due = rent_collector
Expand Down Expand Up @@ -344,12 +342,9 @@ impl Accounts {
programdata_address,
}) = account.state()
{
if let Some((programdata_account, _)) =
self.accounts_db.load_with_fixed_root(
ancestors,
&programdata_address,
load_zero_lamports,
)
if let Some((programdata_account, _)) = self
.accounts_db
.load_with_fixed_root(ancestors, &programdata_address)
{
account_deps
.push((programdata_address, programdata_account));
Expand Down Expand Up @@ -393,7 +388,6 @@ impl Accounts {
&mut accounts,
instruction.program_id_index as IndexOfAccount,
error_counters,
load_zero_lamports,
)
})
.collect::<Result<Vec<Vec<IndexOfAccount>>>>()?;
Expand Down Expand Up @@ -465,7 +459,6 @@ impl Accounts {
accounts: &mut Vec<TransactionAccount>,
mut program_account_index: IndexOfAccount,
error_counters: &mut TransactionErrorMetrics,
load_zero_lamports: LoadZeroLamports,
) -> Result<Vec<IndexOfAccount>> {
let mut account_indices = Vec::new();
let mut program_id = match accounts.get(program_account_index as usize) {
Expand All @@ -483,11 +476,10 @@ impl Accounts {
}
depth += 1;

program_account_index = match self.accounts_db.load_with_fixed_root(
ancestors,
&program_id,
load_zero_lamports,
) {
program_account_index = match self
.accounts_db
.load_with_fixed_root(ancestors, &program_id)
{
Some((program_account, _)) => {
let account_index = accounts.len() as IndexOfAccount;
accounts.push((program_id, program_account));
Expand All @@ -513,11 +505,10 @@ impl Accounts {
programdata_address,
}) = program.state()
{
let programdata_account_index = match self.accounts_db.load_with_fixed_root(
ancestors,
&programdata_address,
load_zero_lamports,
) {
let programdata_account_index = match self
.accounts_db
.load_with_fixed_root(ancestors, &programdata_address)
{
Some((programdata_account, _)) => {
let account_index = accounts.len() as IndexOfAccount;
accounts.push((programdata_address, programdata_account));
Expand Down Expand Up @@ -615,15 +606,10 @@ impl Accounts {
ancestors: &Ancestors,
address_table_lookup: &MessageAddressTableLookup,
slot_hashes: &SlotHashes,
load_zero_lamports: LoadZeroLamports,
) -> std::result::Result<LoadedAddresses, AddressLookupError> {
let table_account = self
.accounts_db
.load_with_fixed_root(
ancestors,
&address_table_lookup.account_key,
load_zero_lamports,
)
.load_with_fixed_root(ancestors, &address_table_lookup.account_key)
.map(|(account, _rent)| account)
.ok_or(AddressLookupError::LookupTableAccountNotFound)?;

Expand Down Expand Up @@ -2088,7 +2074,6 @@ mod tests {
&ancestors,
&address_table_lookup,
&SlotHashes::default(),
LoadZeroLamports::SomeWithZeroLamportAccount,
),
Err(AddressLookupError::LookupTableAccountNotFound),
);
Expand Down Expand Up @@ -2121,7 +2106,6 @@ mod tests {
&ancestors,
&address_table_lookup,
&SlotHashes::default(),
LoadZeroLamports::SomeWithZeroLamportAccount,
),
Err(AddressLookupError::InvalidAccountOwner),
);
Expand Down Expand Up @@ -2154,7 +2138,6 @@ mod tests {
&ancestors,
&address_table_lookup,
&SlotHashes::default(),
LoadZeroLamports::SomeWithZeroLamportAccount,
),
Err(AddressLookupError::InvalidAccountData),
);
Expand Down Expand Up @@ -2199,7 +2182,6 @@ mod tests {
&ancestors,
&address_table_lookup,
&SlotHashes::default(),
LoadZeroLamports::SomeWithZeroLamportAccount,
),
Ok(LoadedAddresses {
writable: vec![table_addresses[0]],
Expand Down Expand Up @@ -2514,7 +2496,6 @@ mod tests {
&mut vec![(keypair.pubkey(), account)],
0,
&mut error_counters,
LoadZeroLamports::SomeWithZeroLamportAccount,
),
Err(TransactionError::ProgramAccountNotFound)
);
Expand Down
26 changes: 5 additions & 21 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,6 @@ pub enum StoreReclaims {
Ignore,
}

/// specifies how to return zero lamport accounts
/// This will only be useful until a feature activation occurs.
#[derive(Clone, Copy)]
pub enum LoadZeroLamports {
/// return None if loaded account has zero lamports
None,
/// return Some(account with zero lamports) if loaded account has zero lamports
/// Today this is the default. With feature activation, this will no longer be possible.
SomeWithZeroLamportAccount,
}

// the current best way to add filler accounts is gradually.
// In other scenarios, such as monitoring catchup with large # of accounts, it may be useful to be able to
// add filler accounts at the beginning, so that code path remains but won't execute at the moment.
Expand Down Expand Up @@ -4693,19 +4682,14 @@ impl AccountsDb {
self.do_load_with_populate_read_cache(ancestors, pubkey, None, LoadHint::Unspecified, true);
}

/// note this returns None for accounts with zero lamports
pub fn load_with_fixed_root(
&self,
ancestors: &Ancestors,
pubkey: &Pubkey,
load_zero_lamports: LoadZeroLamports,
) -> Option<(AccountSharedData, Slot)> {
self.load(ancestors, pubkey, LoadHint::FixedMaxRoot)
.filter(|(account, _)| {
matches!(
load_zero_lamports,
LoadZeroLamports::SomeWithZeroLamportAccount
) || !account.is_zero_lamport()
})
.filter(|(account, _)| !account.is_zero_lamport())
}

pub fn load_without_fixed_root(
Expand Down Expand Up @@ -13950,21 +13934,21 @@ pub mod tests {

assert_eq!(db.read_only_accounts_cache.cache_len(), 0);
let account = db
.load_with_fixed_root(&Ancestors::default(), &account_key, LoadZeroLamports::None)
.load_with_fixed_root(&Ancestors::default(), &account_key)
.map(|(account, _)| account)
.unwrap();
assert_eq!(account.lamports(), 1);
assert_eq!(db.read_only_accounts_cache.cache_len(), 1);
let account = db
.load_with_fixed_root(&Ancestors::default(), &account_key, LoadZeroLamports::None)
.load_with_fixed_root(&Ancestors::default(), &account_key)
.map(|(account, _)| account)
.unwrap();
assert_eq!(account.lamports(), 1);
assert_eq!(db.read_only_accounts_cache.cache_len(), 1);
db.store_cached((2, &[(&account_key, &zero_lamport_account)][..]), None);
assert_eq!(db.read_only_accounts_cache.cache_len(), 1);
let account = db
.load_with_fixed_root(&Ancestors::default(), &account_key, LoadZeroLamports::None)
.load_with_fixed_root(&Ancestors::default(), &account_key)
.map(|(account, _)| account);
assert!(account.is_none());
assert_eq!(db.read_only_accounts_cache.cache_len(), 1);
Expand Down
4 changes: 0 additions & 4 deletions runtime/src/bank/address_lookup_table.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
super::Bank,
crate::accounts_db::LoadZeroLamports,
solana_address_lookup_table_program::error::AddressLookupError,
solana_sdk::{
message::v0::{LoadedAddresses, MessageAddressTableLookup},
Expand All @@ -17,8 +16,6 @@ impl AddressLoader for &Bank {
return Err(TransactionError::UnsupportedVersion);
}

let load_zero_lamports = LoadZeroLamports::None;

let slot_hashes = self
.sysvar_cache
.read()
Expand All @@ -33,7 +30,6 @@ impl AddressLoader for &Bank {
&self.ancestors,
address_table_lookup,
&slot_hashes,
load_zero_lamports,
)
})
.collect::<Result<_, AddressLookupError>>()?)
Expand Down