From 3380c1404474c4805639a9dad502232f6efd66ca Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang <93241502+yhchiang-sol@users.noreply.github.com> Date: Fri, 26 Jan 2024 09:40:05 -0800 Subject: [PATCH] [TieredStorage] Correct the HotStorage API for account_matches_owners (#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 --- accounts-db/src/tiered_storage/hot.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/accounts-db/src/tiered_storage/hot.rs b/accounts-db/src/tiered_storage/hot.rs index 4ef3dca1de4578..730ace5aa310ed 100644 --- a/accounts-db/src/tiered_storage/hot.rs +++ b/accounts-db/src/tiered_storage/hot.rs @@ -362,7 +362,7 @@ impl HotStorageReader { pub fn account_matches_owners( &self, account_offset: HotAccountOffset, - owners: &[&Pubkey], + owners: &[Pubkey], ) -> Result { let account_meta = self .get_account_meta_from_offset(account_offset) @@ -377,7 +377,7 @@ impl HotStorageReader { owners .iter() - .position(|candidate| &account_owner == candidate) + .position(|candidate| account_owner == candidate) .ok_or(MatchAccountOwnerError::NoMatch) } } @@ -1081,7 +1081,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()) { @@ -1090,16 +1090,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!( @@ -1119,7 +1118,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] ); } }