diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 1da0fb7d8406e7..66770e85675492 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -4,7 +4,7 @@ use { account_rent_state::{check_rent_state_with_account, RentState}, accounts_db::{ AccountShrinkThreshold, AccountsAddRootTiming, AccountsDb, AccountsDbConfig, - BankHashInfo, LoadHint, LoadedAccount, ScanStorageResult, + BankHashInfo, LoadHint, LoadZeroLamports, LoadedAccount, ScanStorageResult, ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS, ACCOUNTS_DB_CONFIG_FOR_TESTING, }, accounts_index::{ @@ -35,7 +35,8 @@ use { bpf_loader_upgradeable::{self, UpgradeableLoaderState}, clock::{BankId, Slot, INITIAL_RENT_EPOCH}, feature_set::{ - self, add_set_compute_unit_price_ix, use_default_units_in_fee_calculation, FeatureSet, + self, add_set_compute_unit_price_ix, return_none_for_zero_lamport_accounts, + use_default_units_in_fee_calculation, FeatureSet, }, fee::FeeStructure, genesis_config::ClusterType, @@ -253,6 +254,13 @@ impl Accounts { feature_set: &FeatureSet, account_overrides: Option<&AccountOverrides>, ) -> Result { + let load_zero_lamports = + if feature_set.is_active(&return_none_for_zero_lamport_accounts::id()) { + LoadZeroLamports::None + } else { + LoadZeroLamports::SomeWithZeroLamportAccount + }; + // Copy all the accounts let message = tx.message(); // NOTE: this check will never fail because `tx` is sanitized @@ -288,7 +296,7 @@ impl Accounts { (account_override.clone(), 0) } else { self.accounts_db - .load_with_fixed_root(ancestors, key) + .load_with_fixed_root(ancestors, key, load_zero_lamports) .map(|(mut account, _)| { if message.is_writable(i) { let rent_due = rent_collector @@ -337,9 +345,12 @@ impl Accounts { programdata_address, }) = account.state() { - if let Some((programdata_account, _)) = self - .accounts_db - .load_with_fixed_root(ancestors, &programdata_address) + if let Some((programdata_account, _)) = + self.accounts_db.load_with_fixed_root( + ancestors, + &programdata_address, + load_zero_lamports, + ) { account_deps .push((programdata_address, programdata_account)); @@ -383,6 +394,7 @@ impl Accounts { &mut accounts, instruction.program_id_index as usize, error_counters, + load_zero_lamports, ) }) .collect::>>>()?; @@ -454,6 +466,7 @@ impl Accounts { accounts: &mut Vec, mut program_account_index: usize, error_counters: &mut TransactionErrorMetrics, + load_zero_lamports: LoadZeroLamports, ) -> Result> { let mut account_indices = Vec::new(); let mut program_id = match accounts.get(program_account_index) { @@ -471,10 +484,11 @@ impl Accounts { } depth += 1; - program_account_index = match self - .accounts_db - .load_with_fixed_root(ancestors, &program_id) - { + program_account_index = match self.accounts_db.load_with_fixed_root( + ancestors, + &program_id, + load_zero_lamports, + ) { Some((program_account, _)) => { let account_index = accounts.len(); accounts.push((program_id, program_account)); @@ -500,10 +514,11 @@ impl Accounts { programdata_address, }) = program.state() { - let programdata_account_index = match self - .accounts_db - .load_with_fixed_root(ancestors, &programdata_address) - { + let programdata_account_index = match self.accounts_db.load_with_fixed_root( + ancestors, + &programdata_address, + load_zero_lamports, + ) { Some((programdata_account, _)) => { let account_index = accounts.len(); accounts.push((programdata_address, programdata_account)); @@ -601,10 +616,15 @@ impl Accounts { ancestors: &Ancestors, address_table_lookup: &MessageAddressTableLookup, slot_hashes: &SlotHashes, + load_zero_lamports: LoadZeroLamports, ) -> std::result::Result { let table_account = self .accounts_db - .load_with_fixed_root(ancestors, &address_table_lookup.account_key) + .load_with_fixed_root( + ancestors, + &address_table_lookup.account_key, + load_zero_lamports, + ) .map(|(account, _rent)| account) .ok_or(AddressLookupError::LookupTableAccountNotFound)?; @@ -2063,6 +2083,7 @@ mod tests { &ancestors, &address_table_lookup, &SlotHashes::default(), + LoadZeroLamports::SomeWithZeroLamportAccount, ), Err(AddressLookupError::LookupTableAccountNotFound), ); @@ -2080,7 +2101,8 @@ mod tests { ); let invalid_table_key = Pubkey::new_unique(); - let invalid_table_account = AccountSharedData::default(); + let mut invalid_table_account = AccountSharedData::default(); + invalid_table_account.set_lamports(1); accounts.store_slow_uncached(0, &invalid_table_key, &invalid_table_account); let address_table_lookup = MessageAddressTableLookup { @@ -2094,6 +2116,7 @@ mod tests { &ancestors, &address_table_lookup, &SlotHashes::default(), + LoadZeroLamports::SomeWithZeroLamportAccount, ), Err(AddressLookupError::InvalidAccountOwner), ); @@ -2126,6 +2149,7 @@ mod tests { &ancestors, &address_table_lookup, &SlotHashes::default(), + LoadZeroLamports::SomeWithZeroLamportAccount, ), Err(AddressLookupError::InvalidAccountData), ); @@ -2170,6 +2194,7 @@ mod tests { &ancestors, &address_table_lookup, &SlotHashes::default(), + LoadZeroLamports::SomeWithZeroLamportAccount, ), Ok(LoadedAddresses { writable: vec![table_addresses[0]], @@ -2466,6 +2491,7 @@ mod tests { &mut vec![(keypair.pubkey(), account)], 0, &mut error_counters, + LoadZeroLamports::SomeWithZeroLamportAccount, ), Err(TransactionError::ProgramAccountNotFound) ); diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 3e148e5e171b03..1a74280a314364 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -142,6 +142,17 @@ 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. @@ -4284,8 +4295,15 @@ impl AccountsDb { &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() + }) } pub fn load_without_fixed_root( @@ -13432,13 +13450,13 @@ pub mod tests { assert_eq!(db.read_only_accounts_cache.cache_len(), 0); let account = db - .load_with_fixed_root(&Ancestors::default(), &account_key) + .load_with_fixed_root(&Ancestors::default(), &account_key, LoadZeroLamports::None) .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) + .load_with_fixed_root(&Ancestors::default(), &account_key, LoadZeroLamports::None) .map(|(account, _)| account) .unwrap(); assert_eq!(account.lamports(), 1); @@ -13446,10 +13464,9 @@ pub mod tests { 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) - .map(|(account, _)| account) - .unwrap(); - assert_eq!(account.lamports(), 0); + .load_with_fixed_root(&Ancestors::default(), &account_key, LoadZeroLamports::None) + .map(|(account, _)| account); + assert!(account.is_none()); assert_eq!(db.read_only_accounts_cache.cache_len(), 1); } diff --git a/runtime/src/bank/address_lookup_table.rs b/runtime/src/bank/address_lookup_table.rs index 3916177afd5668..0a4bc732f45ba6 100644 --- a/runtime/src/bank/address_lookup_table.rs +++ b/runtime/src/bank/address_lookup_table.rs @@ -1,7 +1,9 @@ use { super::Bank, + crate::accounts_db::LoadZeroLamports, solana_address_lookup_table_program::error::AddressLookupError, solana_sdk::{ + feature_set::return_none_for_zero_lamport_accounts, message::v0::{LoadedAddresses, MessageAddressTableLookup}, transaction::{AddressLoader, Result as TransactionResult, TransactionError}, }, @@ -16,6 +18,15 @@ impl AddressLoader for &Bank { return Err(TransactionError::UnsupportedVersion); } + let load_zero_lamports = if self + .feature_set + .is_active(&return_none_for_zero_lamport_accounts::id()) + { + LoadZeroLamports::None + } else { + LoadZeroLamports::SomeWithZeroLamportAccount + }; + let slot_hashes = self .sysvar_cache .read() @@ -30,6 +41,7 @@ impl AddressLoader for &Bank { &self.ancestors, address_table_lookup, &slot_hashes, + load_zero_lamports, ) }) .collect::>()?) diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index d9f054ce7e2040..f30d439c2e79bb 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -504,6 +504,10 @@ pub mod vote_state_update_root_fix { solana_sdk::declare_id!("G74BkWBzmsByZ1kxHy44H3wjwp5hp7JbrGRuDpco22tY"); } +pub mod return_none_for_zero_lamport_accounts { + solana_sdk::declare_id!("7K5HFrS1WAq6ND7RQbShXZXbtAookyTfaDQPTJNuZpze"); +} + lazy_static! { /// Map of feature identifiers to user-visible description pub static ref FEATURE_NAMES: HashMap = [ @@ -624,6 +628,7 @@ lazy_static! { (check_ping_ancestor_requests::id(), "ancestor hash repair socket ping/pong support #26963"), (incremental_snapshot_only_incremental_hash_calculation::id(), "only hash accounts in incremental snapshot during incremental snapshot creation #26799"), (vote_state_update_root_fix::id(), "fix root in vote state updates #27361"), + (return_none_for_zero_lamport_accounts::id(), "return none for zero lamport accounts #27800"), /*************** ADD NEW FEATURES HERE ***************/ ] .iter()