diff --git a/accounts-db/src/tiered_storage/index.rs b/accounts-db/src/tiered_storage/index.rs index ad66f3c745..8c1f4bc79e 100644 --- a/accounts-db/src/tiered_storage/index.rs +++ b/accounts-db/src/tiered_storage/index.rs @@ -17,6 +17,15 @@ pub struct AccountIndexWriterEntry<'a> { pub intra_block_offset: u64, } +/// The offset to an account stored inside its accounts block. +/// This struct is used to access the meta and data of an account by looking through +/// its accounts block. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct AccountOffset { + /// The offset to the accounts block that contains the account meta/data. + pub block: usize, +} + /// The index format of a tiered accounts file. #[repr(u16)] #[derive( @@ -76,21 +85,22 @@ impl IndexBlockFormat { Ok(address) } - /// Returns the offset to the account block that contains the account - /// associated with the specified index to the index block. - pub fn get_account_block_offset( + /// Returns the offset to the account given the specified index. + pub fn get_account_offset( &self, map: &Mmap, footer: &TieredStorageFooter, index: usize, - ) -> TieredStorageResult { + ) -> TieredStorageResult { match self { Self::AddressAndOffset => { let offset = footer.index_block_offset as usize + std::mem::size_of::() * footer.account_entry_count as usize + index * std::mem::size_of::(); let (account_block_offset, _) = get_type(map, offset)?; - Ok(*account_block_offset) + Ok(AccountOffset { + block: *account_block_offset, + }) } } } @@ -146,10 +156,8 @@ mod tests { .unwrap(); let map = unsafe { MmapOptions::new().map(&file).unwrap() }; for (i, index_entry) in index_entries.iter().enumerate() { - assert_eq!( - index_entry.block_offset, - indexer.get_account_block_offset(&map, &footer, i).unwrap() - ); + let account_offset = indexer.get_account_offset(&map, &footer, i).unwrap(); + assert_eq!(index_entry.block_offset, account_offset.block as u64); let address = indexer.get_account_address(&map, &footer, i).unwrap(); assert_eq!(index_entry.address, address); }