Skip to content

Commit

Permalink
[TieredStorage] Correct the HotStorage API for account_matches_owners (
Browse files Browse the repository at this point in the history
…solana-labs#34967)

#### Problem
In HotStorageReader, the account_matches_owners takes
&[&Pubkey] as the address candidates.  However, it should
be &[Pubkey] as defined in the accounts_file API.

#### Summary of Changes
Correct HotStorageReader::account_matches_owners() to
take &[Pubkey] instead.

#### Test Plan
Existing unit-tests
  • Loading branch information
yhchiang-sol committed Feb 13, 2024
1 parent 3281678 commit cf51382
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl HotStorageReader {
pub fn account_matches_owners(
&self,
account_offset: HotAccountOffset,
owners: &[&Pubkey],
owners: &[Pubkey],
) -> Result<usize, MatchAccountOwnerError> {
let account_meta = self
.get_account_meta_from_offset(account_offset)
Expand All @@ -369,7 +369,7 @@ impl HotStorageReader {

owners
.iter()
.position(|candidate| &account_owner == candidate)
.position(|candidate| account_owner == candidate)
.ok_or(MatchAccountOwnerError::NoMatch)
}
}
Expand Down Expand Up @@ -1073,7 +1073,7 @@ pub mod tests {
let hot_storage = HotStorageReader::new_from_path(&path).unwrap();

// First, verify whether we can find the expected owners.
let mut owner_candidates: Vec<_> = owner_addresses.iter().collect();
let mut owner_candidates = owner_addresses.clone();
owner_candidates.shuffle(&mut rng);

for (account_offset, account_meta) in account_offsets.iter().zip(hot_account_metas.iter()) {
Expand All @@ -1082,16 +1082,15 @@ pub mod tests {
.unwrap();
assert_eq!(
owner_candidates[index],
&owner_addresses[account_meta.owner_offset().0 as usize]
owner_addresses[account_meta.owner_offset().0 as usize]
);
}

// Second, verify the MatchAccountOwnerError::NoMatch case
const NUM_UNMATCHED_OWNERS: usize = 20;
let unmatched_owners: Vec<_> = std::iter::repeat_with(Pubkey::new_unique)
let unmatched_candidates: Vec<_> = std::iter::repeat_with(Pubkey::new_unique)
.take(NUM_UNMATCHED_OWNERS)
.collect();
let unmatched_candidates: Vec<_> = unmatched_owners.iter().collect();

for account_offset in account_offsets.iter() {
assert_eq!(
Expand All @@ -1111,7 +1110,7 @@ pub mod tests {
.unwrap();
assert_eq!(
owner_candidates[index],
&owner_addresses[account_meta.owner_offset().0 as usize]
owner_addresses[account_meta.owner_offset().0 as usize]
);
}
}
Expand Down

0 comments on commit cf51382

Please sign in to comment.