diff --git a/accounts-db/src/tiered_storage.rs b/accounts-db/src/tiered_storage.rs index 0fee6594c26d65..2051733da36e76 100644 --- a/accounts-db/src/tiered_storage.rs +++ b/accounts-db/src/tiered_storage.rs @@ -13,7 +13,10 @@ pub mod readable; mod test_utils; use { - crate::{accounts_file::StoredAccountsInfo, storable_accounts::StorableAccounts}, + crate::{ + account_storage::meta::StoredAccountMeta, accounts_file::StoredAccountsInfo, + storable_accounts::StorableAccounts, + }, error::TieredStorageError, footer::{AccountBlockFormat, AccountMetaFormat}, hot::{HotStorageWriter, HOT_FORMAT}, @@ -377,12 +380,10 @@ mod tests { const MIN_PUBKEY: Pubkey = Pubkey::new_from_array([0x00u8; 32]); const MAX_PUBKEY: Pubkey = Pubkey::new_from_array([0xFFu8; 32]); - let mut min_pubkey_ref = &MAX_PUBKEY; - let mut max_pubkey_ref = &MIN_PUBKEY; + let mut min_pubkey_ref = MAX_PUBKEY; + let mut max_pubkey_ref = MIN_PUBKEY; - while let Some((stored_account_meta, next)) = - reader.get_stored_account_meta(index_offset).unwrap() - { + let mut test = |stored_account_meta: StoredAccountMeta<'_>| { if let Some(account) = expected_accounts_map.get(stored_account_meta.pubkey()) { verify_test_account_with_footer( &stored_account_meta, @@ -390,18 +391,36 @@ mod tests { stored_account_meta.pubkey(), footer, ); - verified_accounts.insert(stored_account_meta.pubkey()); - if *min_pubkey_ref > *stored_account_meta.pubkey() { + verified_accounts.insert(*stored_account_meta.pubkey()); + if min_pubkey_ref > *stored_account_meta.pubkey() { min_pubkey_ref = stored_account_meta.pubkey(); } - if *max_pubkey_ref < *stored_account_meta.pubkey() { - max_pubkey_ref = stored_account_meta.pubkey(); + if max_pubkey_ref < *stored_account_meta.pubkey() { + max_pubkey_ref = *stored_account_meta.pubkey(); } } + }; + reader.scan_accounts(|stored_account_meta| { + test(stored_account_meta); + }); + + assert_eq!(footer.min_account_address, min_pubkey_ref); + assert_eq!(footer.max_account_address, max_pubkey_ref); + assert!(!verified_accounts.is_empty()); + assert_eq!(verified_accounts.len(), expected_accounts_map.len()); + + // try again with get_stored_account_meta + verified_accounts = HashSet::new(); + min_pubkey_ref = MAX_PUBKEY; + max_pubkey_ref = MIN_PUBKEY; + while let Some((stored_account_meta, next)) = + reader.get_stored_account_meta(index_offset).unwrap() + { + test(stored_account_meta); index_offset = next; } - assert_eq!(footer.min_account_address, *min_pubkey_ref); - assert_eq!(footer.max_account_address, *max_pubkey_ref); + assert_eq!(footer.min_account_address, min_pubkey_ref); + assert_eq!(footer.max_account_address, max_pubkey_ref); assert!(!verified_accounts.is_empty()); assert_eq!(verified_accounts.len(), expected_accounts_map.len()) }