42
42
get_ancient_append_vec_capacity, is_ancient, AccountsToStore, StorageSelector,
43
43
},
44
44
append_vec::{
45
- aligned_stored_size, AppendVec, StorableAccountsWithHashesAndWriteVersions ,
46
- StoredAccountMeta, StoredMetaWriteVersion, APPEND_VEC_MMAPPED_FILES_OPEN ,
47
- STORE_META_OVERHEAD,
45
+ aligned_stored_size, AppendVec, MatchAccountOwnerError ,
46
+ StorableAccountsWithHashesAndWriteVersions, StoredAccountMeta, StoredMetaWriteVersion ,
47
+ APPEND_VEC_MMAPPED_FILES_OPEN, STORE_META_OVERHEAD,
48
48
},
49
49
cache_hash_data::{CacheHashData, CacheHashDataFile},
50
50
contains::Contains,
@@ -816,22 +816,28 @@ impl<'a> LoadedAccountAccessor<'a> {
816
816
}
817
817
}
818
818
819
- fn account_matches_owners(&self, owners: &[&Pubkey]) -> Option<bool > {
819
+ fn account_matches_owners(&self, owners: &[&Pubkey]) -> Result<(), MatchAccountOwnerError > {
820
820
match self {
821
821
LoadedAccountAccessor::Cached(cached_account) => cached_account
822
822
.as_ref()
823
- .map(|cached_account| owners.contains(&cached_account.account.owner())),
823
+ .and_then(|cached_account| {
824
+ owners
825
+ .contains(&cached_account.account.owner())
826
+ .then_some(())
827
+ })
828
+ .ok_or(MatchAccountOwnerError::NoMatch),
824
829
LoadedAccountAccessor::Stored(maybe_storage_entry) => {
825
830
// storage entry may not be present if slot was cleaned up in
826
831
// between reading the accounts index and calling this function to
827
832
// get account meta from the storage entry here
828
833
maybe_storage_entry
829
834
.as_ref()
830
- .and_then (|(storage_entry, offset)| {
835
+ .map (|(storage_entry, offset)| {
831
836
storage_entry
832
837
.accounts
833
838
.account_matches_owners(*offset, owners)
834
839
})
840
+ .unwrap_or(Err(MatchAccountOwnerError::UnableToLoad))
835
841
}
836
842
}
837
843
}
@@ -4943,25 +4949,31 @@ impl AccountsDb {
4943
4949
ancestors: &Ancestors,
4944
4950
account: &Pubkey,
4945
4951
owners: &[&Pubkey],
4946
- ) -> Option<bool> {
4947
- let (slot, storage_location, _maybe_account_accesor) =
4948
- self.read_index_for_accessor_or_load_slow(ancestors, account, None, false)?;
4952
+ ) -> Result<(), MatchAccountOwnerError> {
4953
+ let (slot, storage_location, _maybe_account_accesor) = self
4954
+ .read_index_for_accessor_or_load_slow(ancestors, account, None, false)
4955
+ .ok_or(MatchAccountOwnerError::UnableToLoad)?;
4949
4956
4950
4957
if !storage_location.is_cached() {
4951
4958
let result = self.read_only_accounts_cache.load(*account, slot);
4952
4959
if let Some(account) = result {
4953
- return Some(owners.contains(&account.owner()));
4960
+ return owners
4961
+ .contains(&account.owner())
4962
+ .then_some(())
4963
+ .ok_or(MatchAccountOwnerError::NoMatch);
4954
4964
}
4955
4965
}
4956
4966
4957
- let (account_accessor, _slot) = self.retry_to_get_account_accessor(
4958
- slot,
4959
- storage_location,
4960
- ancestors,
4961
- account,
4962
- None,
4963
- LoadHint::Unspecified,
4964
- )?;
4967
+ let (account_accessor, _slot) = self
4968
+ .retry_to_get_account_accessor(
4969
+ slot,
4970
+ storage_location,
4971
+ ancestors,
4972
+ account,
4973
+ None,
4974
+ LoadHint::Unspecified,
4975
+ )
4976
+ .ok_or(MatchAccountOwnerError::UnableToLoad)?;
4965
4977
account_accessor.account_matches_owners(owners)
4966
4978
}
4967
4979
@@ -14150,19 +14162,19 @@ pub mod tests {
14150
14162
14151
14163
assert_eq!(
14152
14164
db.account_matches_owners(&Ancestors::default(), &account1_key, &owners_refs),
14153
- Some(true )
14165
+ Ok(() )
14154
14166
);
14155
14167
assert_eq!(
14156
14168
db.account_matches_owners(&Ancestors::default(), &account2_key, &owners_refs),
14157
- Some(true )
14169
+ Ok(() )
14158
14170
);
14159
14171
assert_eq!(
14160
14172
db.account_matches_owners(&Ancestors::default(), &account3_key, &owners_refs),
14161
- Some(false )
14173
+ Err(MatchAccountOwnerError::NoMatch )
14162
14174
);
14163
14175
assert_eq!(
14164
14176
db.account_matches_owners(&Ancestors::default(), &Pubkey::new_unique(), &owners_refs),
14165
- None
14177
+ Err(MatchAccountOwnerError::UnableToLoad)
14166
14178
);
14167
14179
14168
14180
// Flush the cache and load account1 (so that it's in the cache)
@@ -14180,19 +14192,19 @@ pub mod tests {
14180
14192
14181
14193
assert_eq!(
14182
14194
db.account_matches_owners(&Ancestors::default(), &account1_key, &owners_refs),
14183
- Some(true )
14195
+ Ok(() )
14184
14196
);
14185
14197
assert_eq!(
14186
14198
db.account_matches_owners(&Ancestors::default(), &account2_key, &owners_refs),
14187
- Some(true )
14199
+ Ok(() )
14188
14200
);
14189
14201
assert_eq!(
14190
14202
db.account_matches_owners(&Ancestors::default(), &account3_key, &owners_refs),
14191
- Some(false )
14203
+ Err(MatchAccountOwnerError::NoMatch )
14192
14204
);
14193
14205
assert_eq!(
14194
14206
db.account_matches_owners(&Ancestors::default(), &Pubkey::new_unique(), &owners_refs),
14195
- None
14207
+ Err(MatchAccountOwnerError::UnableToLoad)
14196
14208
);
14197
14209
}
14198
14210
0 commit comments