42
42
get_ancient_append_vec_capacity, is_ancient, AccountsToStore, StorageSelector,
43
43
},
44
44
append_vec::{
45
- aligned_stored_size, AccountMeta, AppendVec ,
46
- StorableAccountsWithHashesAndWriteVersions, StoredAccountMeta, StoredMetaWriteVersion,
47
- APPEND_VEC_MMAPPED_FILES_OPEN, STORE_META_OVERHEAD,
45
+ aligned_stored_size, AppendVec, StorableAccountsWithHashesAndWriteVersions ,
46
+ StoredAccountMeta, StoredMetaWriteVersion, APPEND_VEC_MMAPPED_FILES_OPEN ,
47
+ STORE_META_OVERHEAD,
48
48
},
49
49
cache_hash_data::{CacheHashData, CacheHashDataFile},
50
50
contains::Contains,
@@ -810,24 +810,21 @@ impl<'a> LoadedAccountAccessor<'a> {
810
810
}
811
811
}
812
812
813
- fn get_account_meta (&self) -> Option<AccountMeta > {
813
+ fn account_matches_owners (&self, owners: &[&Pubkey] ) -> Option<bool > {
814
814
match self {
815
- LoadedAccountAccessor::Cached(cached_account) => {
816
- cached_account.as_ref().map(|cached_account| AccountMeta {
817
- lamports: cached_account.account.lamports(),
818
- rent_epoch: cached_account.account.rent_epoch(),
819
- owner: *cached_account.account.owner(),
820
- executable: cached_account.account.executable(),
821
- })
822
- }
815
+ LoadedAccountAccessor::Cached(cached_account) => cached_account
816
+ .as_ref()
817
+ .map(|cached_account| owners.contains(&cached_account.account.owner())),
823
818
LoadedAccountAccessor::Stored(maybe_storage_entry) => {
824
819
// storage entry may not be present if slot was cleaned up in
825
820
// between reading the accounts index and calling this function to
826
821
// get account meta from the storage entry here
827
822
maybe_storage_entry
828
823
.as_ref()
829
824
.and_then(|(storage_entry, offset)| {
830
- storage_entry.accounts.get_account_meta(*offset)
825
+ storage_entry
826
+ .accounts
827
+ .account_matches_owners(*offset, owners)
831
828
})
832
829
}
833
830
}
@@ -4936,31 +4933,31 @@ impl AccountsDb {
4936
4933
self.do_load(ancestors, pubkey, None, load_hint, LoadZeroLamports::None)
4937
4934
}
4938
4935
4939
- pub fn get_account_meta(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<AccountMeta> {
4936
+ pub fn account_matches_owners(
4937
+ &self,
4938
+ ancestors: &Ancestors,
4939
+ account: &Pubkey,
4940
+ owners: &[&Pubkey],
4941
+ ) -> Option<bool> {
4940
4942
let (slot, storage_location, _maybe_account_accesor) =
4941
- self.read_index_for_accessor_or_load_slow(ancestors, pubkey , None, false)?;
4943
+ self.read_index_for_accessor_or_load_slow(ancestors, account , None, false)?;
4942
4944
4943
4945
if !storage_location.is_cached() {
4944
- let result = self.read_only_accounts_cache.load(*pubkey , slot);
4946
+ let result = self.read_only_accounts_cache.load(*account , slot);
4945
4947
if let Some(account) = result {
4946
- return Some(AccountMeta {
4947
- lamports: account.lamports(),
4948
- rent_epoch: account.rent_epoch(),
4949
- owner: *account.owner(),
4950
- executable: account.executable(),
4951
- });
4948
+ return Some(owners.contains(&account.owner()));
4952
4949
}
4953
4950
}
4954
4951
4955
4952
let (account_accessor, _slot) = self.retry_to_get_account_accessor(
4956
4953
slot,
4957
4954
storage_location,
4958
4955
ancestors,
4959
- pubkey ,
4956
+ account ,
4960
4957
None,
4961
4958
LoadHint::Unspecified,
4962
4959
)?;
4963
- account_accessor.get_account_meta( )
4960
+ account_accessor.account_matches_owners(owners )
4964
4961
}
4965
4962
4966
4963
pub fn load_account_into_read_cache(&self, ancestors: &Ancestors, pubkey: &Pubkey) {
@@ -14133,43 +14130,54 @@ pub mod tests {
14133
14130
}
14134
14131
14135
14132
#[test]
14136
- fn test_get_account_meta () {
14133
+ fn test_account_matches_owners () {
14137
14134
let db = Arc::new(AccountsDb::new_with_config_for_tests(
14138
14135
Vec::new(),
14139
14136
&ClusterType::Development,
14140
14137
AccountSecondaryIndexes::default(),
14141
14138
AccountShrinkThreshold::default(),
14142
14139
));
14143
14140
14141
+ let owners: Vec<Pubkey> = (0..2).map(|_| Pubkey::new_unique()).collect();
14142
+ let owners_refs: Vec<&Pubkey> = owners.iter().collect();
14143
+
14144
14144
let account1_key = Pubkey::new_unique();
14145
- let owner1_key = Pubkey::new_unique();
14146
- let account1 = AccountSharedData::new(321, 10, &owner1_key);
14145
+ let account1 = AccountSharedData::new(321, 10, &owners[0]);
14147
14146
14148
14147
let account2_key = Pubkey::new_unique();
14149
- let owner2_key = Pubkey::new_unique();
14150
- let account2 = AccountSharedData::new(1, 1, &owner2_key);
14148
+ let account2 = AccountSharedData::new(1, 1, &owners[1]);
14149
+
14150
+ let account3_key = Pubkey::new_unique();
14151
+ let account3 = AccountSharedData::new(1, 1, &Pubkey::new_unique());
14151
14152
14152
14153
db.store_cached((0, &[(&account1_key, &account1)][..]), None);
14153
14154
db.store_cached((1, &[(&account2_key, &account2)][..]), None);
14155
+ db.store_cached((2, &[(&account3_key, &account3)][..]), None);
14154
14156
14155
14157
db.add_root(0);
14156
14158
db.add_root(1);
14159
+ db.add_root(2);
14157
14160
14158
14161
// Flush the cache so that the account meta will be read from the storage
14159
14162
db.flush_accounts_cache(true, None);
14160
14163
db.clean_accounts_for_tests();
14161
14164
14162
- let account_meta = db
14163
- .get_account_meta(&Ancestors::default(), &account1_key)
14164
- .unwrap();
14165
- assert_eq!(account_meta.lamports, 321);
14166
- assert_eq!(account_meta.owner, owner1_key);
14167
-
14168
- let account_meta = db
14169
- .get_account_meta(&Ancestors::default(), &account2_key)
14170
- .unwrap();
14171
- assert_eq!(account_meta.lamports, 1);
14172
- assert_eq!(account_meta.owner, owner2_key);
14165
+ assert_eq!(
14166
+ db.account_matches_owners(&Ancestors::default(), &account1_key, &owners_refs),
14167
+ Some(true)
14168
+ );
14169
+ assert_eq!(
14170
+ db.account_matches_owners(&Ancestors::default(), &account2_key, &owners_refs),
14171
+ Some(true)
14172
+ );
14173
+ assert_eq!(
14174
+ db.account_matches_owners(&Ancestors::default(), &account3_key, &owners_refs),
14175
+ Some(false)
14176
+ );
14177
+ assert_eq!(
14178
+ db.account_matches_owners(&Ancestors::default(), &Pubkey::new_unique(), &owners_refs),
14179
+ None
14180
+ );
14173
14181
14174
14182
// Flush the cache and load account1 (so that it's in the cache)
14175
14183
db.flush_accounts_cache(true, None);
@@ -14184,17 +14192,22 @@ pub mod tests {
14184
14192
)
14185
14193
.unwrap();
14186
14194
14187
- let account_meta = db
14188
- .get_account_meta(&Ancestors::default(), &account1_key)
14189
- .unwrap();
14190
- assert_eq!(account_meta.lamports, 321);
14191
- assert_eq!(account_meta.owner, owner1_key);
14192
-
14193
- let account_meta = db
14194
- .get_account_meta(&Ancestors::default(), &account2_key)
14195
- .unwrap();
14196
- assert_eq!(account_meta.lamports, 1);
14197
- assert_eq!(account_meta.owner, owner2_key);
14195
+ assert_eq!(
14196
+ db.account_matches_owners(&Ancestors::default(), &account1_key, &owners_refs),
14197
+ Some(true)
14198
+ );
14199
+ assert_eq!(
14200
+ db.account_matches_owners(&Ancestors::default(), &account2_key, &owners_refs),
14201
+ Some(true)
14202
+ );
14203
+ assert_eq!(
14204
+ db.account_matches_owners(&Ancestors::default(), &account3_key, &owners_refs),
14205
+ Some(false)
14206
+ );
14207
+ assert_eq!(
14208
+ db.account_matches_owners(&Ancestors::default(), &Pubkey::new_unique(), &owners_refs),
14209
+ None
14210
+ );
14198
14211
}
14199
14212
14200
14213
/// a test that will accept either answer
0 commit comments